Socket APIs: Ethernet/socket.c File Reference

Wiznet Socket API

socket.c File Reference

SOCKET APIs Implements file. More...

#include "socket.h"

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...
 

Variables

uint8_t sock_pack_info [_WIZCHIP_SOCK_NUM_] = {0,}
 

Detailed Description

SOCKET APIs Implements file.

SOCKET APIs like as Berkeley Socket APIs.

Version
1.0.3
Date
2013/10/21
Revision history
<2015/02/05> Notice The version history is not updated after this point. Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary. >> https://github.com/Wiznet/ioLibrary_Driver <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

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.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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 60 of file socket.c.

Referenced by socket().

#define CHECK_SOCKNUM ( )
Value:
do{ \
}while(0); \
#define _WIZCHIP_SOCK_NUM_
The count of independant socket of WIZCHIP.
Definition: wizchip_conf.h:188
#define SOCKERR_SOCKNUM
Invalid socket number.
Definition: socket.h:97

Definition at line 83 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); \
#define SOCKERR_SOCKMODE
Invalid socket mode for socket operation.
Definition: socket.h:101
#define getSn_MR(sn)
Get Sn_MR register.
Definition: w5100.h:1377

Definition at line 88 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); \
#define SOCKERR_SOCKINIT
Socket is not initialized or SIPR is Zero IP address when Sn_MR_TCP.
Definition: socket.h:99
#define getSn_SR(sn)
Get Sn_SR register.
Definition: w5100.h:1426
#define SOCK_INIT
Initiate state.
Definition: w5100.h:901

Definition at line 93 of file socket.c.

Referenced by connect(), and listen().

#define CHECK_SOCKDATA ( )
Value:
do{ \
if(len == 0) return SOCKERR_DATALEN; \
}while(0); \
#define SOCKERR_DATALEN
Data length is zero or greater than buffer max size.
Definition: socket.h:108

Definition at line 98 of file socket.c.

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

Variable Documentation

uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,}

Definition at line 70 of file socket.c.

Referenced by close(), getsockopt(), recv(), recvfrom(), and socket().

Generated on Wed May 4 2016 16:43:59 for Socket APIs by   doxygen 1.8.9.1