io6Library
WIZnet Dual Stack TCP/IP Ethernet Controller Driver
Macros | Enumerations | Functions
socket.h File Reference

SOCKET APIs Header File. More...

#include "stdint.h"
#include "wizchip_conf.h"

Go to the source code of this file.

Macros

#define SOCKET   uint8_t
 SOCKET type define for legacy driver. More...
 
#define SOCK_OK   1
 Result is OK about socket process. More...
 
#define SOCK_BUSY   0
 Socket is busy on processing the operation. Valid only Non-block IO Mode. More...
 
#define SOCK_FATAL   (-1000)
 Result is fatal error about socket process. More...
 
#define SOCK_ERROR   0
 
#define SOCKERR_SOCKNUM   (SOCK_ERROR - 1)
 Invalid socket number. More...
 
#define SOCKERR_SOCKOPT   (SOCK_ERROR - 2)
 Invalid socket option. More...
 
#define SOCKERR_SOCKINIT   (SOCK_ERROR - 3)
 Socket is not initialized or SIPR is Zero IP address when Sn_MR_TCP. More...
 
#define SOCKERR_SOCKCLOSED   (SOCK_ERROR - 4)
 Socket unexpectedly closed. More...
 
#define SOCKERR_SOCKMODE   (SOCK_ERROR - 5)
 Invalid socket mode for socket operation. More...
 
#define SOCKERR_SOCKFLAG   (SOCK_ERROR - 6)
 Invalid socket flag. More...
 
#define SOCKERR_SOCKSTATUS   (SOCK_ERROR - 7)
 Invalid socket status for socket operation. More...
 
#define SOCKERR_ARG   (SOCK_ERROR - 10)
 Invalid argument. More...
 
#define SOCKERR_PORTZERO   (SOCK_ERROR - 11)
 Port number is zero. More...
 
#define SOCKERR_IPINVALID   (SOCK_ERROR - 12)
 Invalid source or destination IP address. More...
 
#define SOCKERR_TIMEOUT   (SOCK_ERROR - 13)
 Timeout occurred. More...
 
#define SOCKERR_DATALEN   (SOCK_ERROR - 14)
 Invalid data length. More...
 
#define SOCKERR_BUFFER   (SOCK_ERROR - 15)
 Socket buffer is not enough for data communication. More...
 
#define SOCKFATAL_PACKLEN   (SOCK_FATAL - 1)
 Invalid packet length. Fatal Error. More...
 
#define SF_MULTI_ENABLE   (Sn_MR_MULTI)
 In UDP mode such as Sn_MR_UDP4 and Sn_MR_UDP6, Sn_MR_UDP6, Enable multicast mode. When Sn_MR_UDP6, Enable only IPv6 Multicating. More...
 
#define SF_ETHER_OWN   (Sn_MR_MF)
 In MACRAW mode such as Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet. More...
 
#define SF_BROAD_BLOCK   (Sn_MR_BRDB)
 In UDP mode such as Sn_MR_UDP4, Sn_MR_UDP6 and Sn_MR_UDPD, or In MACRAW mode sucha as Sn_MR_MACRAW, Block a broadcast packet. More...
 
#define SF_TCP_FPSH   (Sn_MR_FPSH)
 In TCP mode such as Sn_MR_TCP4, Sn_MR_TCP6 and Sn_MR_TCPD, Use to forced push flag. More...
 
#define SF_TCP_NODELAY   (Sn_MR_ND)
 In TCP mode such as Sn_MR_TCP4, Sn_MR_TCP6 and Sn_MR_TCPD, Use to nodelayed ack. More...
 
#define SF_IGMP_VER2   (Sn_MR_MC)
 In UDP mode such as Sn_MR_UDP4 with SF_MULTI_ENABLE, Select IGMP version 2. More...
 
#define SF_SOLICIT_BLOCK   (Sn_MR_SMB)
 In UDP mode such as Sn_MR_UDP6 and Sn_MR_UDPD, Block a solicited mutlicast packet. More...
 
#define SF_ETHER_MULTI4B   (Sn_MR_MMB4)
 In MACRAW mode such as Sn_MR_MACRAW with SF_MULTI_ENABLE, Block a IPv4 multicast packet. More...
 
#define SF_UNI_BLOCK   (Sn_MR_UNIB)
 In UDP mdoe such as Sn_MR_UDP4, Sn_MR_UDP6 and Sn_MR_UDPD with SF_MULTI_ENABLE, Block a unicast packet. More...
 
#define SF_ETHER_MULIT6B   (Sn_MR_MMB6)
 In MACRAW mode such as Sn_MR_MACRAW with SF_MULTI_ENABLE, Block a IPv6 multicast packet. More...
 
#define SF_FORCE_ARP   (Sn_MR2_FARP)
 Force to APR. More...
 
#define SF_DHA_MANUAL   (Sn_MR2_DHAM)
 The destination hardware address of packet to be transmitted is set by user through _Sn_DHAR_. It is invalid in MACRAW mode such as Sn_MR_MACRAW. More...
 
#define SF_IO_NONBLOCK   (0x01 << 3)
 Socket nonblock io mode. It used parameter in socket(). More...
 
#define PACK_IPv6   (1<<7)
 It indicates the destination IP address of the received packet is IPv6 or IPv4. More...
 
#define PACK_IPV6_ALLNODE   (PACK_IPv6 | (1<<6))
 It indicates the destination IP address of the received packet is allnode multicast(broadcast) address or not. More...
 
#define PACK_IPV6_MULTI   (PACK_IPv6 | (1<<5))
 It indicates the destination IP address of the received packet is multicast address or not. More...
 
#define PACK_IPV6_LLA   (PACK_IPv6 | (1<<4))
 It indicates the destination IP address of the received packet is lla or gua. More...
 
#define PACK_COMPLETED   (1<<3)
 It indicates the read data is last in the received packet. More...
 
#define PACK_REMAINED   (1<<2)
 It indicates to remain data in the received packet. More...
 
#define PACK_FIRST   (1<<1)
 It indicates the read data is first in the received packet. More...
 
#define PACK_NONE   (0x00)
 It indicates no information of a packet. More...
 
#define SRCV6_PREFER_AUTO   (PSR_AUTO)
 Soruce IPv6 address is preferred to auto-selection. Refer to _Sn_PSR_. More...
 
#define SRCV6_PREFER_LLA   (PSR_LLA)
 Soruce IPv6 address is preferred to link local address. Refer to _Sn_PSR_. More...
 
#define SRCV6_PREFER_GUA   (PSR_GUA)
 Soruce IPv6 address is preferred to global unique address. Refer to _Sn_PSR_. More...
 
#define TCPSOCK_MODE   (Sn_ESR_TCPM)
 It indicates the IP version when SOCKETn is opened as TCP6 or TCPD mode.(0 - IPv4 , 1 - IPv6) More...
 
#define TCPSOCK_OP   (Sn_ESR_TCPOP)
 It indicates the operation mode when SOCKETn is connected.(0 - TCP CLIENT , 1 - TCP SERVER) More...
 
#define TCPSOCK_SIP   (Sn_ESR_IP6T)
 It indicates the source ip address type when SOCKET is connected. (0 - Link Local, 1 - Global Unique) More...
 
#define SOCK_IO_BLOCK   0
 Socket Block IO Mode in setsockopt(). More...
 
#define SOCK_IO_NONBLOCK   1
 Socket Non-block IO Mode in setsockopt(). More...
 

Enumerations

enum  sockint_kind {
  SIK_CONNECTED = (1 << 0), SIK_DISCONNECTED = (1 << 1), SIK_RECEIVED = (1 << 2), SIK_TIMEOUT = (1 << 3),
  SIK_SENT = (1 << 4), SIK_ALL = 0x1F
}
 The kind of SOCKET Interrupt. More...
 
enum  ctlsock_type {
  CS_SET_IOMODE, CS_GET_IOMODE, CS_GET_MAXTXBUF, CS_GET_MAXRXBUF,
  CS_CLR_INTERRUPT, CS_GET_INTERRUPT, CS_SET_INTMASK, CS_GET_INTMASK,
  CS_SET_PREFER, CS_GET_PREFER
}
 The type of ctlsocket(). More...
 
enum  sockopt_type {
  SO_FLAG, SO_TTL, SO_TOS, SO_MSS,
  SO_DESTIP, SO_DESTPORT, SO_KEEPALIVESEND, SO_KEEPALIVEAUTO,
  SO_SENDBUF, SO_RECVBUF, SO_STATUS, SO_EXTSTATUS,
  SO_REMAINSIZE, SO_MODE, SO_PACKINFO
}
 The type of socket option in setsockopt() or getsockopt() More...
 

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 TCP CLIENT. More...
 
int8_t connect (uint8_t sn, uint8_t *addr, uint16_t port, uint8_t addrlen)
 Try to connect to a TCP SERVER. More...
 
int8_t disconnect (uint8_t sn)
 Try to disconnect to the connected peer. More...
 
datasize_t send (uint8_t sn, uint8_t *buf, datasize_t len)
 Send data to the connected peer. More...
 
datasize_t recv (uint8_t sn, uint8_t *buf, datasize_t len)
 Receive data from the connected peer. More...
 
datasize_t sendto (uint8_t sn, uint8_t *buf, datasize_t len, uint8_t *addr, uint16_t port, uint8_t addrlen)
 Send datagram to the peer specifed by destination IP address and port number passed as parameter. More...
 
datasize_t recvfrom (uint8_t sn, uint8_t *buf, datasize_t len, uint8_t *addr, uint16_t *port, uint8_t *addrlen)
 Receive datagram from a peer. More...
 
int8_t ctlsocket (uint8_t sn, ctlsock_type cstype, void *arg)
 Control SOCKETn. More...
 
int8_t setsockopt (uint8_t sn, sockopt_type sotype, void *arg)
 Set SOCKETn options. More...
 
int8_t getsockopt (uint8_t sn, sockopt_type sotype, void *arg)
 get SOCKETn options More...
 
int16_t peeksockmsg (uint8_t sn, uint8_t *submsg, uint16_t subsize)
 Peeks a sub-message in SOCKETn RX buffer. More...
 

Detailed Description

SOCKET APIs Header File.

Version
1.0.0
Date
2019/01/01
Revision history
<2019/01/01> 1st Release
Author
MidnightCow

Copyright (c) 2019, WIZnet Co., LTD.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file socket.h.

Macro Definition Documentation

◆ SOCKET

#define SOCKET   uint8_t

SOCKET type define for legacy driver.

Definition at line 80 of file socket.h.

◆ SOCK_OK

#define SOCK_OK   1

Result is OK about socket process.

Definition at line 82 of file socket.h.

◆ SOCK_BUSY

#define SOCK_BUSY   0

Socket is busy on processing the operation. Valid only Non-block IO Mode.

Definition at line 83 of file socket.h.

◆ SOCK_FATAL

#define SOCK_FATAL   (-1000)

Result is fatal error about socket process.

Definition at line 84 of file socket.h.

◆ SOCK_ERROR

#define SOCK_ERROR   0

Definition at line 86 of file socket.h.

◆ SOCKERR_SOCKNUM

#define SOCKERR_SOCKNUM   (SOCK_ERROR - 1)

Invalid socket number.

Definition at line 87 of file socket.h.

◆ SOCKERR_SOCKOPT

#define SOCKERR_SOCKOPT   (SOCK_ERROR - 2)

Invalid socket option.

Definition at line 88 of file socket.h.

◆ SOCKERR_SOCKINIT

#define SOCKERR_SOCKINIT   (SOCK_ERROR - 3)

Socket is not initialized or SIPR is Zero IP address when Sn_MR_TCP.

Definition at line 89 of file socket.h.

◆ SOCKERR_SOCKCLOSED

#define SOCKERR_SOCKCLOSED   (SOCK_ERROR - 4)

Socket unexpectedly closed.

Definition at line 90 of file socket.h.

◆ SOCKERR_SOCKMODE

#define SOCKERR_SOCKMODE   (SOCK_ERROR - 5)

Invalid socket mode for socket operation.

Definition at line 91 of file socket.h.

◆ SOCKERR_SOCKFLAG

#define SOCKERR_SOCKFLAG   (SOCK_ERROR - 6)

Invalid socket flag.

Definition at line 92 of file socket.h.

◆ SOCKERR_SOCKSTATUS

#define SOCKERR_SOCKSTATUS   (SOCK_ERROR - 7)

Invalid socket status for socket operation.

Definition at line 93 of file socket.h.

◆ SOCKERR_ARG

#define SOCKERR_ARG   (SOCK_ERROR - 10)

Invalid argument.

Definition at line 94 of file socket.h.

◆ SOCKERR_PORTZERO

#define SOCKERR_PORTZERO   (SOCK_ERROR - 11)

Port number is zero.

Definition at line 95 of file socket.h.

◆ SOCKERR_IPINVALID

#define SOCKERR_IPINVALID   (SOCK_ERROR - 12)

Invalid source or destination IP address.

Definition at line 96 of file socket.h.

◆ SOCKERR_TIMEOUT

#define SOCKERR_TIMEOUT   (SOCK_ERROR - 13)

Timeout occurred.

Definition at line 97 of file socket.h.

◆ SOCKERR_DATALEN

#define SOCKERR_DATALEN   (SOCK_ERROR - 14)

Invalid data length.

Definition at line 98 of file socket.h.

◆ SOCKERR_BUFFER

#define SOCKERR_BUFFER   (SOCK_ERROR - 15)

Socket buffer is not enough for data communication.

Definition at line 99 of file socket.h.

◆ SOCKFATAL_PACKLEN

#define SOCKFATAL_PACKLEN   (SOCK_FATAL - 1)

Invalid packet length. Fatal Error.

Definition at line 103 of file socket.h.

◆ SF_MULTI_ENABLE

#define SF_MULTI_ENABLE   (Sn_MR_MULTI)

In UDP mode such as Sn_MR_UDP4 and Sn_MR_UDP6, Sn_MR_UDP6, Enable multicast mode. When Sn_MR_UDP6, Enable only IPv6 Multicating.

Definition at line 127 of file socket.h.

◆ SF_ETHER_OWN

#define SF_ETHER_OWN   (Sn_MR_MF)

In MACRAW mode such as Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet.

Definition at line 128 of file socket.h.

◆ SF_BROAD_BLOCK

#define SF_BROAD_BLOCK   (Sn_MR_BRDB)

In UDP mode such as Sn_MR_UDP4, Sn_MR_UDP6 and Sn_MR_UDPD, or In MACRAW mode sucha as Sn_MR_MACRAW, Block a broadcast packet.

Definition at line 133 of file socket.h.

◆ SF_TCP_FPSH

#define SF_TCP_FPSH   (Sn_MR_FPSH)

In TCP mode such as Sn_MR_TCP4, Sn_MR_TCP6 and Sn_MR_TCPD, Use to forced push flag.

Definition at line 134 of file socket.h.

◆ SF_TCP_NODELAY

#define SF_TCP_NODELAY   (Sn_MR_ND)

In TCP mode such as Sn_MR_TCP4, Sn_MR_TCP6 and Sn_MR_TCPD, Use to nodelayed ack.

Definition at line 136 of file socket.h.

◆ SF_IGMP_VER2

#define SF_IGMP_VER2   (Sn_MR_MC)

In UDP mode such as Sn_MR_UDP4 with SF_MULTI_ENABLE, Select IGMP version 2.

Definition at line 137 of file socket.h.

◆ SF_SOLICIT_BLOCK

#define SF_SOLICIT_BLOCK   (Sn_MR_SMB)

In UDP mode such as Sn_MR_UDP6 and Sn_MR_UDPD, Block a solicited mutlicast packet.

Definition at line 138 of file socket.h.

◆ SF_ETHER_MULTI4B

#define SF_ETHER_MULTI4B   (Sn_MR_MMB4)

In MACRAW mode such as Sn_MR_MACRAW with SF_MULTI_ENABLE, Block a IPv4 multicast packet.

Definition at line 139 of file socket.h.

◆ SF_UNI_BLOCK

#define SF_UNI_BLOCK   (Sn_MR_UNIB)

In UDP mdoe such as Sn_MR_UDP4, Sn_MR_UDP6 and Sn_MR_UDPD with SF_MULTI_ENABLE, Block a unicast packet.

Definition at line 141 of file socket.h.

◆ SF_ETHER_MULIT6B

#define SF_ETHER_MULIT6B   (Sn_MR_MMB6)

In MACRAW mode such as Sn_MR_MACRAW with SF_MULTI_ENABLE, Block a IPv6 multicast packet.

Definition at line 142 of file socket.h.

◆ SF_FORCE_ARP

#define SF_FORCE_ARP   (Sn_MR2_FARP)

Force to APR.

In datagram mode such as Sn_MR_IPRAW4, Sn_MR_IPRAW6, Sn_MR_UDP4, Sn_MR_UDP6, and Sn_MR_UDPD, Force to request ARP before a packet is sent to a destination.
In TCP mode such as Sn_MR_TCP4, Sn_MR_TCP6, and Sn_MR_TCPD and TCP SERVER operation mode, Force to request ARP before SYN/ACK packet is sent to a TCP CLIENT.
When SF_DHA_MANUAL is set, the ARP is process but the destination hardware address is fixed by user.

Definition at line 152 of file socket.h.

◆ SF_DHA_MANUAL

#define SF_DHA_MANUAL   (Sn_MR2_DHAM)

The destination hardware address of packet to be transmitted is set by user through _Sn_DHAR_. It is invalid in MACRAW mode such as Sn_MR_MACRAW.

Definition at line 157 of file socket.h.

◆ SF_IO_NONBLOCK

#define SF_IO_NONBLOCK   (0x01 << 3)

Socket nonblock io mode. It used parameter in socket().

Definition at line 159 of file socket.h.

◆ PACK_IPv6

#define PACK_IPv6   (1<<7)

It indicates the destination IP address of the received packet is IPv6 or IPv4.

Definition at line 164 of file socket.h.

◆ PACK_IPV6_ALLNODE

#define PACK_IPV6_ALLNODE   (PACK_IPv6 | (1<<6))

It indicates the destination IP address of the received packet is allnode multicast(broadcast) address or not.

Definition at line 165 of file socket.h.

◆ PACK_IPV6_MULTI

#define PACK_IPV6_MULTI   (PACK_IPv6 | (1<<5))

It indicates the destination IP address of the received packet is multicast address or not.

Definition at line 166 of file socket.h.

◆ PACK_IPV6_LLA

#define PACK_IPV6_LLA   (PACK_IPv6 | (1<<4))

It indicates the destination IP address of the received packet is lla or gua.

Definition at line 167 of file socket.h.

◆ PACK_COMPLETED

#define PACK_COMPLETED   (1<<3)

It indicates the read data is last in the received packet.

Definition at line 168 of file socket.h.

◆ PACK_REMAINED

#define PACK_REMAINED   (1<<2)

It indicates to remain data in the received packet.

Definition at line 169 of file socket.h.

◆ PACK_FIRST

#define PACK_FIRST   (1<<1)

It indicates the read data is first in the received packet.

Definition at line 170 of file socket.h.

◆ PACK_NONE

#define PACK_NONE   (0x00)

It indicates no information of a packet.

Definition at line 171 of file socket.h.

◆ SRCV6_PREFER_AUTO

#define SRCV6_PREFER_AUTO   (PSR_AUTO)

Soruce IPv6 address is preferred to auto-selection. Refer to _Sn_PSR_.

Definition at line 173 of file socket.h.

◆ SRCV6_PREFER_LLA

#define SRCV6_PREFER_LLA   (PSR_LLA)

Soruce IPv6 address is preferred to link local address. Refer to _Sn_PSR_.

Definition at line 174 of file socket.h.

◆ SRCV6_PREFER_GUA

#define SRCV6_PREFER_GUA   (PSR_GUA)

Soruce IPv6 address is preferred to global unique address. Refer to _Sn_PSR_.

Definition at line 175 of file socket.h.

◆ TCPSOCK_MODE

#define TCPSOCK_MODE   (Sn_ESR_TCPM)

It indicates the IP version when SOCKETn is opened as TCP6 or TCPD mode.(0 - IPv4 , 1 - IPv6)

Definition at line 177 of file socket.h.

◆ TCPSOCK_OP

#define TCPSOCK_OP   (Sn_ESR_TCPOP)

It indicates the operation mode when SOCKETn is connected.(0 - TCP CLIENT , 1 - TCP SERVER)

Definition at line 178 of file socket.h.

◆ TCPSOCK_SIP

#define TCPSOCK_SIP   (Sn_ESR_IP6T)

It indicates the source ip address type when SOCKET is connected. (0 - Link Local, 1 - Global Unique)

Definition at line 179 of file socket.h.

◆ SOCK_IO_BLOCK

#define SOCK_IO_BLOCK   0

Socket Block IO Mode in setsockopt().

Definition at line 184 of file socket.h.

◆ SOCK_IO_NONBLOCK

#define SOCK_IO_NONBLOCK   1

Socket Non-block IO Mode in setsockopt().

Definition at line 185 of file socket.h.