|
SWILIB API (X75)
|
Functions for working with BSD-like sockets.
Usage: #include <swilib.h> or #include <swilib/socket.h>
Data Structures | |
| struct | in_addr |
| Internet address (a structure for historical reasons) More... | |
| struct | sockaddr |
| Socket address, generic. More... | |
| struct | sockaddr_in |
| Socket address, internet style. More... | |
| struct | hostent |
| DNS response. More... | |
Macros | |
| #define | INADDR_ANY (uint32_t) 0x00000000 |
| Definitions of bits in internet address integers. | |
| #define | INADDR_BROADCAST (uint32_t) 0xffffffff |
| #define | INET_ADDRSTRLEN 16 |
| Maximum length of the IPv4 address. | |
| #define | MAX_IPv4_STR_LEN 16 |
| Maximum length of the IPv4 address. | |
| #define | MAX_IPv6_STR_LEN 64 |
| Maximum length of the IPv6 address. | |
| #define | IP_ADDR(A, B, C, D) (((unsigned long)A << 24) | ((unsigned long)B << 16) | ((unsigned long) C << 8) | ((unsigned long) D << 0)) |
| Helper for creating IP address. | |
Typedefs | |
| typedef uint16_t | in_port_t |
| Port value. | |
| typedef uint16_t | sa_family_t |
| Address family. | |
| typedef uint32_t | in_addr_t |
| Internet address. | |
| typedef uint32_t | socklen_t |
| Socket address length type definition. | |
| typedef struct sockaddr | SOCK_ADDR |
| ELF's backward compatibility. | |
| typedef struct sockaddr_in | SOCKADDR_IN |
| Windows-style. | |
| typedef struct sockaddr | SOCKADDR |
| Windows-style. | |
| typedef struct hostent | HOSTENT |
| Windows-style. | |
Enumerations | |
| enum | SockProtocolID { IPPROTO_IP = 0 , IPPROTO_TCP = 6 , IPPROTO_UDP = 17 , IPPROTO_MAX = 18 } |
| Internet protocols. More... | |
| enum | SockTypeID { SOCK_DGRAM = 0 , SOCK_STREAM = 1 } |
| Socket types. More... | |
| enum | SockFamilyID { AF_UNSPEC = 0 , AF_INET = 1 , AF_MAX = 2 } |
| Socket family types. More... | |
| enum | SockShutdownTypeID { SHUT_RD = 0 , SHUT_WR = 1 , SHUT_RDWR = 2 } |
| Socket shutdown types. More... | |
Functions | |
| int | async_gethostbyname (const char *name, void *response, int *req_id) |
| Resolve domain name. | |
| uint32_t | str2ip (const char *ip) |
| Convert the string IP address to the numeric format. | |
| in_addr_t | inet_addr (const char *ip) |
| Convert the string IP address to the numeric format. | |
| uint16_t | htons (uint16_t p) |
| Convert host to network order (unsigned short). | |
| uint32_t | htonl (uint32_t p) |
| Convert host to network order (unsigned int). | |
| static uint16_t | ntohs (uint16_t p) |
| Convert network to host order. | |
| static uint32_t | ntohl (uint32_t p) |
| int | socket (int domain, int type, int protocol) |
| int | connect (int socket, const struct sockaddr *address, socklen_t address_len) |
| Connect socket to the address. | |
| int | bind (int socket, const struct sockaddr *address, socklen_t address_len) |
| Bind socket to the address. | |
| int | shutdown (int socket, int how) |
| Shutdown. | |
| int | recv (int socket, void *buf, int len, int flags) |
| Receive data on a socket. | |
| int | send (int socket, const void *buf, int len, int flags) |
| Send a message on a socket. | |
| int | available0 (int socket) |
| Get available bytes for reading in the socket. | |
| int * | socklasterr (void) |
| Pointer to the last socket error. | |
| int | closesocket (int socket) |
| Close socket descriptor. | |
| struct hostent * | gethostbyname (const char *name) |
| Resolve a host name synchronously. | |
| int | getsockname (int sock, SOCK_ADDR *addr, int *len) |
| Read the local address of a socket. | |
| int | getpeername (int sock, SOCK_ADDR *addr, int *len) |
| Read the remote address of a connected socket. | |
| int | setsockopt (int sock, int level, int option, const void *value, int len) |
| Set a socket option. | |
| int | getsockopt (int sock, int level, int option, void *value, int *len) |
| Read a socket option. | |
| int | ioctlsocket (int sock, int cmd, void *arg) |
| Apply a socket control command; read socklasterr for errors. | |
| int | listen (int sock, int backlog) |
| Start listening for incoming TCP connections. | |
| int | ENIP_GetNativeSocket (int sock, ENIP_SOCKET **native) |
| Look up the native ENIP object for a socket descriptor. | |
| struct in_addr |
| struct sockaddr |
| struct sockaddr_in |
| struct hostent |
| #define INADDR_ANY (uint32_t) 0x00000000 |
| #define INET_ADDRSTRLEN 16 |
| #define MAX_IPv4_STR_LEN 16 |
| #define MAX_IPv6_STR_LEN 64 |
| #define IP_ADDR | ( | A, | |
| B, | |||
| C, | |||
| D ) (((unsigned long)A << 24) | ((unsigned long)B << 16) | ((unsigned long) C << 8) | ((unsigned long) D << 0)) |
| typedef uint16_t sa_family_t |
| typedef uint32_t socklen_t |
| typedef struct sockaddr_in SOCKADDR_IN |
| enum SockProtocolID |
| enum SockTypeID |
| enum SockFamilyID |
| enum SockShutdownTypeID |
| int async_gethostbyname | ( | const char * | name, |
| void * | response, | ||
| int * | req_id ) |
Resolve domain name.
| name | domain name to be resolved | |
| [out] | response | pointer to the pointer of hostent |
| [out] | req_id | request ID or NULL |
response is void * for compatibility reasons - some old code still uses int **** for this function. | uint32_t str2ip | ( | const char * | ip | ) |
Convert the string IP address to the numeric format.
| ip | IP address, example: 127.0.0.1 |
Convert the string IP address to the numeric format.
| ip | IP address, example: 127.0.0.1 |
| uint16_t htons | ( | uint16_t | p | ) |
Convert host to network order (unsigned short).
| uint32_t htonl | ( | uint32_t | p | ) |
Convert host to network order (unsigned int).
|
inlinestatic |
| int socket | ( | int | domain, |
| int | type, | ||
| int | protocol ) |
| domain | socket domain, set to AF_INET |
| type | socket type, set to SOCK_STREAM |
| protocol | set to 0 (default protocol) |
Connect socket to the address.
| socket | socket descriptor |
| address | socket address, see sockaddr_in |
| address_len | size of the socket address |
Bind socket to the address.
| socket | socket descriptor |
| address | socket address, see sockaddr_in |
| address_len | size of the socket address |
| int shutdown | ( | int | socket, |
| int | how ) |
Shutdown.
| socket | socket descriptor |
| how | specifies the type of shutdown, see SockShutdownTypeID |
| int recv | ( | int | socket, |
| void * | buf, | ||
| int | len, | ||
| int | flags ) |
Receive data on a socket.
| socket | socket descriptor | |
| [out] | buf | buffer for received data |
| len | maximum size for the receiving | |
| flags | set to 0 |
| int send | ( | int | socket, |
| const void * | buf, | ||
| int | len, | ||
| int | flags ) |
Send a message on a socket.
| socket | socket descriptor |
| buf | buffer for sending |
| len | size of the data in buffer |
| flags | set to 0 |
| int available0 | ( | int | socket | ) |
Get available bytes for reading in the socket.
| socket | socket descriptor |
| int * socklasterr | ( | void | ) |
| int closesocket | ( | int | socket | ) |
Close socket descriptor.
| socket | socket descriptor |
Resolve a host name synchronously.
| name | domain name |
| int getsockname | ( | int | sock, |
| SOCK_ADDR * | addr, | ||
| int * | len ) |
Read the local address of a socket.
| sock | socket descriptor |
| addr | output address |
| len | address-buffer size on entry, returned length on exit |
| int getpeername | ( | int | sock, |
| SOCK_ADDR * | addr, | ||
| int * | len ) |
Read the remote address of a connected socket.
| sock | socket descriptor |
| addr | output address |
| len | address-buffer size on entry, returned length on exit |
| int setsockopt | ( | int | sock, |
| int | level, | ||
| int | option, | ||
| const void * | value, | ||
| int | len ) |
Set a socket option.
| sock | socket descriptor |
| level | option level |
| option | option identifier |
| value | option data |
| len | size of option data in bytes |
| int getsockopt | ( | int | sock, |
| int | level, | ||
| int | option, | ||
| void * | value, | ||
| int * | len ) |
Read a socket option.
| sock | socket descriptor |
| level | option level |
| option | option identifier |
| value | output option data |
| len | buffer size on entry, returned length on exit |
| int ioctlsocket | ( | int | sock, |
| int | cmd, | ||
| void * | arg ) |
Apply a socket control command; read socklasterr for errors.
| sock | socket descriptor |
| cmd | control command |
| arg | command argument storage |
| int listen | ( | int | sock, |
| int | backlog ) |
Start listening for incoming TCP connections.
| sock | bound socket descriptor |
| backlog | must be 3, other values fail |
| int ENIP_GetNativeSocket | ( | int | sock, |
| ENIP_SOCKET ** | native ) |
Look up the native ENIP object for a socket descriptor.
| sock | socket descriptor |
| native | receives the firmware-owned socket object on success |