SWILIB API (ELKA)    
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef __IN_SWILIB__
4#include "base.h"
5#include "gprs.h"
6#endif
7
9
18typedef uint16_t in_port_t;
19typedef uint16_t sa_family_t;
20typedef uint32_t in_addr_t;
21typedef uint32_t socklen_t;
22typedef struct sockaddr SOCK_ADDR;
24typedef struct sockaddr_in SOCKADDR_IN;
25typedef struct sockaddr SOCKADDR;
26typedef struct hostent HOSTENT;
28#ifndef SWILIB_LINUX_SIMULATOR
34#define INADDR_ANY (uint32_t) 0x00000000
35#define INADDR_BROADCAST (uint32_t) 0xffffffff
36
37#define INET_ADDRSTRLEN 16
38#define MAX_IPv4_STR_LEN 16
39#define MAX_IPv6_STR_LEN 64
44#define IP_ADDR(A, B, C, D) (((unsigned long)A << 24) | ((unsigned long)B << 16) | ((unsigned long) C << 8) | ((unsigned long) D << 0))
45#endif
46
56
64
70 AF_INET = 1,
71 AF_MAX = 2,
72};
73
82
89
93#ifdef SWILIB_MODERN
94struct sockaddr {
95 uint16_t sa_family;
96 char sa_data[14];
97};
98#else
99struct sockaddr {
100 union {
101 struct {
102 uint16_t sa_family;
103 char sa_data[14];
104 };
105 struct {
106 uint16_t family;
107 uint16_t port;
108 uint32_t ip;
109 uint32_t unk1;
110 uint32_t unk2;
111 };
112 };
113};
114#endif
115
125
129struct hostent {
130 char *h_name;
131 char **h_aliases;
133 short h_length;
134 char **h_addr_list;
135};
136
152__swi_begin(0x1B6)
153int async_gethostbyname(const char *name, void *response, int *req_id)
154__swi_end(0x1B6, async_gethostbyname, (name, response, req_id));
155
161__swi_begin(0x1B7)
162uint32_t str2ip(const char *ip)
163__swi_end(0x1B7, str2ip, (ip));
164
170__swi_begin(0x1B7)
172__swi_end(0x1B7, inet_addr, (ip));
173
177__swi_begin(0x17A)
178uint16_t htons(uint16_t p)
179__swi_end(0x17A, htons, (p));
180
184__swi_begin(0x17B)
185uint32_t htonl(uint32_t p)
186__swi_end(0x17B, htonl, (p));
187
192static inline uint16_t ntohs(uint16_t p) { return htons(p); }
193static inline uint32_t ntohl(uint32_t p) { return htonl(p); }
194
201__swi_begin(0x173)
202int socket(int domain, int type, int protocol)
203__swi_end(0x173, socket, (domain, type, protocol));
204
212__swi_begin(0x174)
213int connect(int socket, const struct sockaddr *address, socklen_t address_len)
214__swi_end(0x174, connect, (socket, address, address_len));
215
223__swi_begin(0x175)
224int bind(int socket, const struct sockaddr *address, socklen_t address_len)
225__swi_end(0x175, bind, (socket, address, address_len));
226
233__swi_begin(0x177)
234int shutdown(int socket, int how)
235__swi_end(0x177, shutdown, (socket, how));
236
245__swi_begin(0x178)
246int recv(int socket, void *buf, int len, int flags)
247__swi_end(0x178, recv, (socket, buf, len, flags));
248
257__swi_begin(0x179)
258int send(int socket, const void *buf, int len, int flags)
259__swi_end(0x179, send, (socket, buf, len, flags));
260
266__swi_begin(0x18D)
268__swi_end(0x18D, available0, (socket));
269
278__swi_begin(0x817C)
279int *socklasterr(void)
280__swi_end(0x817C, socklasterr, ());
281
287__swi_begin(0x176)
289__swi_end(0x176, closesocket, (socket));
290
296__swi_begin(0x434)
297struct hostent *gethostbyname(const char *name)
298__swi_end(0x434, gethostbyname, (name));
299
307__swi_begin(0x435)
308int getsockname(int sock, SOCK_ADDR *addr, int *len)
309__swi_end(0x435, getsockname, (sock, addr, len));
310
318__swi_begin(0x436)
319int getpeername(int sock, SOCK_ADDR *addr, int *len)
320__swi_end(0x436, getpeername, (sock, addr, len));
321
331__swi_begin(0x437)
332int setsockopt(int sock, int level, int option, const void *value, int len)
333__swi_end(0x437, setsockopt, (sock, level, option, value, len));
334
344__swi_begin(0x438)
345int getsockopt(int sock, int level, int option, void *value, int *len)
346__swi_end(0x438, getsockopt, (sock, level, option, value, len));
347
355__swi_begin(0x439)
356int ioctlsocket(int sock, int cmd, void *arg)
357__swi_end(0x439, ioctlsocket, (sock, cmd, arg));
358
365__swi_begin(0x43A)
366int listen(int sock, int backlog)
367__swi_end(0x43A, listen, (sock, backlog));
368
375__swi_begin(0x443)
376int ENIP_GetNativeSocket(int sock, ENIP_SOCKET **native)
377__swi_end(0x443, ENIP_GetNativeSocket, (sock, native));
378
380
#define __swilib_begin
Definition doxygen.h:29
#define __swi_end(number, func, call)
Definition doxygen.h:33
#define __swi_begin(number)
Definition doxygen.h:32
#define __swilib_end
Definition doxygen.h:30
#define closesocket(s)
Definition e_os.h:154
#define ioctlsocket(a, b, c)
Definition e_os.h:153
struct ENIP_SOCKET ENIP_SOCKET
ENIP socket.
Definition gprs.h:40
char sin_zero[8]
Definition socket.h:123
uint16_t sa_family
address family
Definition socket.h:95
short h_length
Always 4.
Definition socket.h:133
in_addr_t s_addr
Definition socket.h:87
char * h_name
Official name of host.
Definition socket.h:130
short h_addrtype
Always AF_INET.
Definition socket.h:132
struct in_addr sin_addr
IP value, use htonl or inet_addr (old name: ip)
Definition socket.h:122
char ** h_addr_list
List of addresses.
Definition socket.h:134
sa_family_t sin_family
AF_INET (old name: family)
Definition socket.h:120
char ** h_aliases
Alias list.
Definition socket.h:131
in_port_t sin_port
Port value, use htons (old name: port)
Definition socket.h:121
char sa_data[14]
address value
Definition socket.h:96
int shutdown(int socket, int how)
Shutdown.
int * socklasterr(void)
Pointer to the last socket error.
SockTypeID
Socket types.
Definition socket.h:60
int setsockopt(int sock, int level, int option, const void *value, int len)
Set a socket option.
uint16_t sa_family_t
Address family.
Definition socket.h:19
uint16_t htons(uint16_t p)
Convert host to network order (unsigned short).
int send(int socket, const void *buf, int len, int flags)
Send a message on a socket.
static uint16_t ntohs(uint16_t p)
Convert network to host order.
Definition socket.h:192
int available0(int socket)
Get available bytes for reading in the socket.
uint32_t socklen_t
Socket address length type definition.
Definition socket.h:21
int getsockname(int sock, SOCK_ADDR *addr, int *len)
Read the local address of a socket.
in_addr_t inet_addr(const char *ip)
Convert the string IP address to the numeric format.
int bind(int socket, const struct sockaddr *address, socklen_t address_len)
Bind socket to the address.
SockFamilyID
Socket family types.
Definition socket.h:68
int recv(int socket, void *buf, int len, int flags)
Receive data on a socket.
int listen(int sock, int backlog)
Start listening for incoming TCP connections.
int getsockopt(int sock, int level, int option, void *value, int *len)
Read a socket option.
int async_gethostbyname(const char *name, void *response, int *req_id)
Resolve domain name.
uint32_t htonl(uint32_t p)
Convert host to network order (unsigned int).
uint16_t in_port_t
Port value.
Definition socket.h:18
uint32_t in_addr_t
Internet address.
Definition socket.h:20
int ENIP_GetNativeSocket(int sock, ENIP_SOCKET **native)
Look up the native ENIP object for a socket descriptor.
SockShutdownTypeID
Socket shutdown types.
Definition socket.h:77
int getpeername(int sock, SOCK_ADDR *addr, int *len)
Read the remote address of a connected socket.
struct hostent * gethostbyname(const char *name)
Resolve a host name synchronously.
uint32_t str2ip(const char *ip)
Convert the string IP address to the numeric format.
int connect(int socket, const struct sockaddr *address, socklen_t address_len)
Connect socket to the address.
int socket(int domain, int type, int protocol)
static uint32_t ntohl(uint32_t p)
Definition socket.h:193
SockProtocolID
Internet protocols.
Definition socket.h:50
@ SOCK_DGRAM
UDP.
Definition socket.h:61
@ SOCK_STREAM
TCP.
Definition socket.h:62
@ AF_MAX
Total count.
Definition socket.h:71
@ AF_INET
Internet IP Protocol.
Definition socket.h:70
@ AF_UNSPEC
Unspecified.
Definition socket.h:69
@ SHUT_RD
shut down the reading side
Definition socket.h:78
@ SHUT_WR
shut down the writing side
Definition socket.h:79
@ SHUT_RDWR
shut down both sides
Definition socket.h:80
@ IPPROTO_MAX
UDP.
Definition socket.h:54
@ IPPROTO_IP
Dummy for IP.
Definition socket.h:51
@ IPPROTO_TCP
Definition socket.h:52
@ IPPROTO_UDP
TCP.
Definition socket.h:53
DNS response.
Definition socket.h:129
Internet address (a structure for historical reasons)
Definition socket.h:86
Socket address, generic.
Definition socket.h:94
Socket address, internet style.
Definition socket.h:119
#define const
Definition zconf.h:115