Socket APIs
Macros | Functions
socket.c File Reference

SOCKET APIs Implements file. More...

#include "socket.h"
Include dependency graph for socket.c:

Go to the source code of this file.

Macros

#define SOCK_ANY_PORT_NUM   0xC000;
 
#define CHECK_SOCKNUM()
 
#define CHECK_SOCKMODE(mode)
 
#define CHECK_SOCKINIT()
 
#define CHECK_SOCKDATA()
 

Functions

int8_t socket (uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
 Open a socket. More...
 
int8_t close (uint8_t sn)
 Close a socket. More...
 
int8_t listen (uint8_t sn)
 Listen to a connection request from a client. More...
 
int8_t connect (uint8_t sn, uint8_t *addr, uint16_t port)
 Try to connect a server. More...
 
int8_t disconnect (uint8_t sn)
 Try to disconnect a connection socket. More...
 
int32_t send (uint8_t sn, uint8_t *buf, uint16_t len)
 Send data to the connected peer in TCP socket. More...
 
int32_t recv (uint8_t sn, uint8_t *buf, uint16_t len)
 Receive data from the connected peer. More...
 
int32_t sendto (uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
 Sends datagram to the peer with destination IP address and port number passed as parameter. More...
 
int32_t recvfrom (uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
 Receive datagram of UDP or MACRAW. More...
 
int8_t ctlsocket (uint8_t sn, ctlsock_type cstype, void *arg)
 Control socket. More...
 
int8_t setsockopt (uint8_t sn, sockopt_type sotype, void *arg)
 set socket options More...
 
int8_t getsockopt (uint8_t sn, sockopt_type sotype, void *arg)
 get socket options More...
 

Detailed Description

SOCKET APIs Implements file.

SOCKET APIs like as Berkeley Socket APIs.

Version
1.0.3
Date
2013/10/21
Revision history
<2014/05/01> V1.0.3. Refer to M20140501
  1. Implicit type casting -> Explicit type casting.
  2. replace 0x01 with PACK_REMAINED in recvfrom()
  3. Validation a destination ip in connect() & sendto(): It occurs a fatal error on converting unint32 address if uint8* addr parameter is not aligned by 4byte address. Copy 4 byte addr value into temporary uint32 variable and then compares it. <2013/12/20> V1.0.2 Refer to M20131220 Remove Warning. <2013/11/04> V1.0.1 2nd Release. Refer to "20131104". In sendto(), Add to clear timeout interrupt status (Sn_IR_TIMEOUT) <2013/10/21> 1st Release
Author
MidnightCow

Copyright (c) 2013, WIZnet Co., LTD. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright 

notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file socket.c.

Macro Definition Documentation

#define SOCK_ANY_PORT_NUM   0xC000;

Definition at line 54 of file socket.c.

Referenced by socket().

#define CHECK_SOCKNUM ( )
Value:
do{ \
}while(0); \

Definition at line 66 of file socket.c.

Referenced by close(), connect(), ctlsocket(), disconnect(), getsockopt(), listen(), recv(), recvfrom(), send(), sendto(), setsockopt(), and socket().

#define CHECK_SOCKMODE (   mode)
Value:
do{ \
if((getSn_MR(sn) & 0x0F) != mode) return SOCKERR_SOCKMODE; \
}while(0); \

Definition at line 71 of file socket.c.

Referenced by connect(), disconnect(), getsockopt(), listen(), recv(), send(), and setsockopt().

#define CHECK_SOCKINIT ( )
Value:
do{ \
if((getSn_SR(sn) != SOCK_INIT)) return SOCKERR_SOCKINIT; \
}while(0); \

Definition at line 76 of file socket.c.

Referenced by connect(), and listen().

#define CHECK_SOCKDATA ( )
Value:
do{ \
if(len == 0) return SOCKERR_DATALEN; \
}while(0); \

Definition at line 81 of file socket.c.

Referenced by recv(), recvfrom(), send(), and sendto().