bsd_socket.h
Go to the documentation of this file.
1 /**
2  * @file bsd_socket.h
3  * @brief BSD socket API
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _BSD_SOCKET_H
32 #define _BSD_SOCKET_H
33 
34 //BSD socket support
35 #ifndef BSD_SOCKET_SUPPORT
36  #define BSD_SOCKET_SUPPORT ENABLED
37 #elif (BSD_SOCKET_SUPPORT != ENABLED && BSD_SOCKET_SUPPORT != DISABLED)
38  #error BSD_SOCKET_SUPPORT parameter is not valid
39 #endif
40 
41 //Maximum number of file descriptors a fd_set object can hold
42 #ifndef FD_SETSIZE
43  #define FD_SETSIZE 8
44 #elif (FD_SETSIZE < 1)
45  #error FD_SETSIZE parameter is not valid
46 #endif
47 
48 //Set errno variable
49 #ifndef BSD_SOCKET_SET_ERRNO
50  #define BSD_SOCKET_SET_ERRNO(e)
51 #endif
52 
53 //Keil RTX port?
54 #if defined(USE_RTX) && !defined(RTX_CUSTOM_HEADER)
55 
56 //No support for BSD sockets
57 #undef BSD_SOCKET_SUPPORT
58 #define BSD_SOCKET_SUPPORT DISABLED
59 
60 //Windows port?
61 #elif defined(_WIN32) && !defined(_DONT_USE_WINSOCK)
62 
63 //Undefine conflicting definitions
64 #undef htons
65 #undef htonl
66 #undef ntohs
67 #undef ntohl
68 
69 //Dependencies
70 #include <winsock2.h>
71 
72 #elif (BSD_SOCKET_SUPPORT == ENABLED)
73 
74 //Dependencies
75 #include "os_port.h"
76 
77 //Address families
78 #define AF_UNSPEC 0
79 #define AF_INET 2
80 #define AF_INET6 10
81 #define AF_PACKET 17
82 
83 //Protocol families
84 #define PF_UNSPEC AF_UNSPEC
85 #define PF_INET AF_INET
86 #define PF_INET6 AF_INET6
87 #define PF_PACKET AF_PACKET
88 
89 //Socket types
90 #define SOCK_STREAM 1
91 #define SOCK_DGRAM 2
92 #define SOCK_RAW 3
93 
94 //IP protocol identifiers
95 #define IPPROTO_IP 0
96 #define IPPROTO_ICMP 1
97 #define IPPROTO_IGMP 2
98 #define IPPROTO_TCP 6
99 #define IPPROTO_UDP 17
100 #define IPPROTO_IPV6 41
101 #define IPPROTO_ESP 50
102 #define IPPROTO_AH 51
103 #define IPPROTO_ICMPV6 58
104 
105 //Ethernet protocol identifiers
106 #define ETH_P_ALL 0x0000
107 #define ETH_P_IP 0x0800
108 #define ETH_P_ARP 0x0806
109 #define ETH_P_IPV6 0x86DD
110 
111 //Option levels
112 #define SOL_SOCKET 0xFFFF
113 
114 //Common addresses
115 #define INADDR_ANY 0x00000000
116 #define INADDR_LOOPBACK 0x7F000001
117 #define INADDR_BROADCAST 0xFFFFFFFF
118 
119 //Flags used by I/O functions
120 #define MSG_PEEK 0x0002
121 #define MSG_DONTROUTE 0x0004
122 #define MSG_CTRUNC 0x0008
123 #define MSG_DONTWAIT 0x0040
124 #define MSG_WAITALL 0x0100
125 
126 //Flags used by shutdown function
127 #define SD_RECEIVE 0
128 #define SD_SEND 1
129 #define SD_BOTH 2
130 
131 //Flags used by shutdown function (alias)
132 #define SHUT_RD SD_RECEIVE
133 #define SHUT_WR SD_SEND
134 #define SHUT_RDWR SD_BOTH
135 
136 //Socket level options
137 #define SO_REUSEADDR 2
138 #define SO_TYPE 3
139 #define SO_ERROR 4
140 #define SO_DONTROUTE 5
141 #define SO_BROADCAST 6
142 #define SO_SNDBUF 7
143 #define SO_RCVBUF 8
144 #define SO_KEEPALIVE 9
145 #define SO_NO_CHECK 11
146 #define SO_LINGER 13
147 #define SO_SNDTIMEO 20
148 #define SO_RCVTIMEO 21
149 #define SO_BINDTODEVICE 25
150 #define SO_ACCEPTCONN 30
151 
152 //IP level options
153 #define IP_TOS 1
154 #define IP_TTL 2
155 #define IP_ROUTER_ALERT 5
156 #define IP_PKTINFO 8
157 #define IP_RECVTTL 12
158 #define IP_RECVTOS 13
159 #define IP_MULTICAST_IF 32
160 #define IP_MULTICAST_TTL 33
161 #define IP_MULTICAST_LOOP 34
162 #define IP_ADD_MEMBERSHIP 35
163 #define IP_DROP_MEMBERSHIP 36
164 #define IP_UNBLOCK_SOURCE 37
165 #define IP_BLOCK_SOURCE 38
166 #define IP_ADD_SOURCE_MEMBERSHIP 39
167 #define IP_DROP_SOURCE_MEMBERSHIP 40
168 #define MCAST_JOIN_GROUP 42
169 #define MCAST_BLOCK_SOURCE 43
170 #define MCAST_UNBLOCK_SOURCE 44
171 #define MCAST_LEAVE_GROUP 45
172 #define MCAST_JOIN_SOURCE_GROUP 46
173 #define MCAST_LEAVE_SOURCE_GROUP 47
174 #define IP_DONTFRAG 67
175 
176 //IPv6 level options
177 #define IPV6_UNICAST_HOPS 16
178 #define IPV6_MULTICAST_IF 17
179 #define IPV6_MULTICAST_HOPS 18
180 #define IPV6_MULTICAST_LOOP 19
181 #define IPV6_ADD_MEMBERSHIP 20
182 #define IPV6_DROP_MEMBERSHIP 21
183 #define IPV6_V6ONLY 26
184 #define IPV6_PKTINFO 50
185 #define IPV6_RECVHOPLIMIT 51
186 #define IPV6_HOPLIMIT 52
187 #define IPV6_DONTFRAG 62
188 #define IPV6_RECVTCLASS 66
189 #define IPV6_TCLASS 67
190 
191 //TCP level options
192 #define TCP_NODELAY 1
193 #define TCP_MAXSEG 2
194 #define TCP_KEEPIDLE 4
195 #define TCP_KEEPINTVL 5
196 #define TCP_KEEPCNT 6
197 
198 //IP TOS option
199 #define IPTOS_LOWDELAY 0x10
200 #define IPTOS_THROUGHPUT 0x08
201 #define IPTOS_RELIABILITY 0x04
202 
203 //Multicast filter mode
204 #define MCAST_EXCLUDE 0
205 #define MCAST_INCLUDE 1
206 
207 //IOCTL commands
208 #define FIONBIO 126
209 #define FIONREAD 127
210 #define FIONWRITE 121
211 #define FIONSPACE 120
212 
213 //FCNTL commands
214 #define F_GETFL 3
215 #define F_SETFL 4
216 
217 //FCNTL flags
218 #define O_NONBLOCK 0x0004
219 
220 //Flags used by getaddrinfo
221 #define AI_PASSIVE 0x01
222 #define AI_CANONNAME 0x02
223 #define AI_NUMERICHOST 0x04
224 #define AI_NUMERICSERV 0x08
225 #define AI_ALL 0x10
226 #define AI_ADDRCONFIG 0x20
227 #define AI_V4MAPPED 0x40
228 
229 //Flags used by getnameinfo
230 #define NI_NOFQDN 0x01
231 #define NI_NUMERICHOST 0x02
232 #define NI_NAMEREQD 0x04
233 #define NI_NUMERICSERV 0x08
234 #define NI_DGRAM 0x10
235 
236 //Return values
237 #define SOCKET_SUCCESS 0
238 #define SOCKET_ERROR (-1)
239 
240 //Return values used by getaddrinfo and getnameinfo
241 #define EAI_ADDRFAMILY 1
242 #define EAI_AGAIN 2
243 #define EAI_BADFLAGS 3
244 #define EAI_FAIL 4
245 #define EAI_FAMILY 5
246 #define EAI_MEMORY 6
247 #define EAI_NODATA 7
248 #define EAI_NONAME 8
249 #define EAI_SERVICE 9
250 #define EAI_SOCKTYPE 10
251 #define EAI_SYSTEM 11
252 #define EAI_OVERFLOW 12
253 
254 //Error codes
255 #define EINTR 4
256 #define EAGAIN 11
257 #define EWOULDBLOCK 11
258 #define EFAULT 14
259 #define EINVAL 22
260 #define EINPROGRESS 36
261 #define ETIMEDOUT 60
262 #define ENAMETOOLONG 63
263 #define EMSGSIZE 90
264 #define ENOPROTOOPT 92
265 #define EOPNOTSUPP 95
266 #define EADDRNOTAVAIL 99
267 #define ECONNRESET 104
268 #define ENOBUFS 105
269 #define EISCONN 106
270 #define ENOTCONN 107
271 #define ESHUTDOWN 108
272 #define ECONNREFUSED 111
273 
274 //Error codes used by gethostbyname_r
275 #define NETDB_SUCCESS 0
276 #define HOST_NOT_FOUND 1
277 #define TRY_AGAIN 2
278 #define NO_RECOVERY 3
279 #define NO_ADDRESS 4
280 
281 //Return codes
282 #define INADDR_NONE ((in_addr_t) (-1))
283 
284 //Maximum length for string representation of IPv4 address
285 #define INET_ADDRSTRLEN 16
286 
287 //Maximum length for string representation of IPv6 address
288 #define INET6_ADDRSTRLEN 40
289 
290 //Interface name length
291 #define IF_NAMESIZE (NET_MAX_IF_NAME_LEN + 1)
292 
293 //C++ guard
294 #ifdef __cplusplus
295 extern "C" {
296 #endif
297 
298 
299 /**
300  * @brief Length type
301  **/
302 
303 typedef int_t socklen_t;
304 
305 
306 /**
307  * @brief Address family
308  **/
309 
310 typedef uint16_t sa_family_t;
311 
312 
313 /**
314  * @brief Port number
315  **/
316 
317 typedef uint16_t in_port_t;
318 
319 
320 /**
321  * @brief IPv4 address
322  **/
323 
324 typedef uint32_t in_addr_t;
325 
326 
327 /**
328  * @brief Socket address
329  **/
330 
331 typedef struct sockaddr
332 {
334  uint8_t sa_data[14];
336 
337 
338 /**
339  * @brief Socket address storage
340  **/
341 
342 typedef struct sockaddr_storage
343 {
345  uint8_t ss_pad[26];
347 
348 
349 /**
350  * @brief Structure that represents an IPv4 address
351  **/
352 
353 typedef struct in_addr
354 {
357 
358 
359 /**
360  * @brief IPv4 address information
361  **/
362 
363 typedef struct sockaddr_in
364 {
367  struct in_addr sin_addr;
368  uint8_t sin_zero[8];
370 
371 
372 /**
373  * @brief Structure that represents an IPv6 address
374  **/
375 
376 typedef struct in6_addr
377 {
378  uint8_t s6_addr[16];
380 
381 
382 /**
383  * @brief IPv6 address information
384  **/
385 
386 typedef struct sockaddr_in6
387 {
390  uint32_t sin6_flowinfo;
391  struct in6_addr sin6_addr;
392  uint32_t sin6_scope_id;
394 
395 
396 /**
397  * @brief Any-source multicast group information (for IPv4 only)
398  **/
399 
400 typedef struct ip_mreq
401 {
402  struct in_addr imr_multiaddr;
403  struct in_addr imr_interface;
405 
406 
407 /**
408  * @brief Source-specific multicast group information (for IPv4 only)
409  **/
410 
411 typedef struct ip_mreq_source
412 {
413  struct in_addr imr_multiaddr;
414  struct in_addr imr_sourceaddr;
415  struct in_addr imr_interface;
417 
418 
419 /**
420  * @brief Any-source multicast group information (for IPv6 only)
421  **/
422 
423 typedef struct ipv6_mreq
424 {
425  struct in6_addr ipv6mr_multiaddr;
428 
429 
430 /**
431  * @brief Any-source multicast group information (for IPv4/IPv6)
432  **/
433 
434 typedef struct group_req
435 {
436  uint32_t gr_interface;
437  struct sockaddr_storage gr_group;
439 
440 
441 /**
442  * @brief Source-specific multicast group information (for IPv4/IPv6)
443  **/
444 
445 typedef struct group_source_req
446 {
447  uint32_t gsr_interface;
451 
452 
453 /**
454  * @brief Linger structure
455  **/
456 
457 typedef struct linger
458 {
462 
463 
464 /**
465  * @brief Scatter/gather array
466  **/
467 
468 struct iovec
469 {
470  void *iov_base;
471  size_t iov_len;
472 };
473 
474 
475 /**
476  * @brief Message header
477  **/
478 
479 typedef struct msghdr
480 {
481  void *msg_name;
483  struct iovec *msg_iov;
485  void *msg_control;
489 
490 
491 /**
492  * @brief Ancillary data header
493  **/
494 
495 typedef struct cmsghdr
496 {
497  size_t cmsg_len;
501 
502 
503 /**
504  * @brief IPv4 packet information
505  **/
506 
507 typedef struct in_pktinfo
508 {
510  struct in_addr ipi_addr;
512 
513 
514 /**
515  * @brief IPv6 packet information
516  **/
517 
518 typedef struct in6_pktinfo
519 {
521  struct in6_addr ipi6_addr;
523 
524 
525 /**
526  * @brief Set of sockets
527  **/
528 
529 typedef struct fd_set
530 {
534 
535 
536 /**
537  * @brief Information about a given host
538  **/
539 
540 typedef struct hostent
541 {
542  uint16_t h_addrtype;
543  uint16_t h_length;
544  uint8_t h_addr[16];
546 
547 
548 /**
549  * @brief Information about address of a service provider
550  **/
551 
552 typedef struct addrinfo
553 {
559  struct sockaddr *ai_addr;
561  struct addrinfo *ai_next;
563 
564 
565 #ifndef _TIMEVAL_DEFINED
566 
567 /**
568  * @brief Timeout structure
569  **/
570 
571 typedef struct timeval
572 {
573  int32_t tv_sec;
574  int32_t tv_usec;
576 
577 #endif
578 
579 
580 //Forward declaration of functions
581 struct cmsghdr *socketCmsgFirstHdr(struct msghdr *msg);
582 struct cmsghdr *socketCmsgNextHdr(struct msghdr *msg, struct cmsghdr *cmsg);
583 
584 //Macros for manipulating ancillary data object information
585 #define CMSG_DATA(cmsg) ((uint8_t *) (cmsg) + sizeof(CMSGHDR))
586 #define CMSG_ALIGN(len) (((len) + sizeof(int_t) - 1) & ~(sizeof(int_t) - 1))
587 #define CMSG_SPACE(len) (sizeof(CMSGHDR) + CMSG_ALIGN(len))
588 #define CMSG_LEN(len) (sizeof(CMSGHDR) + (len))
589 #define CMSG_FIRSTHDR(msg) socketCmsgFirstHdr(msg)
590 #define CMSG_NXTHDR(msg, cmsg) socketCmsgNextHdr(msg, cmsg)
591 
592 //Forward declaration of functions
593 void socketFdZero(fd_set *fds);
594 void socketFdSet(fd_set *fds, int_t s);
595 void socketFdClr(fd_set *fds, int_t s);
597 
598 //Macros for manipulating and checking descriptor sets
599 #define FD_ZERO(fds) socketFdZero(fds)
600 #define FD_SET(s, fds) socketFdSet(fds, s)
601 #define FD_CLR(s, fds) socketFdClr(fds, s)
602 #define FD_ISSET(s, fds) socketFdIsSet(fds, s)
603 
604 //BSD socket related constants
605 extern const struct in6_addr in6addr_any;
606 extern const struct in6_addr in6addr_loopback;
607 
608 //BSD socket related functions
610 int_t bind(int_t s, const struct sockaddr *addr, socklen_t addrlen);
611 int_t connect(int_t s, const struct sockaddr *addr, socklen_t addrlen);
612 int_t listen(int_t s, int_t backlog);
613 int_t accept(int_t s, struct sockaddr *addr, socklen_t *addrlen);
614 int_t send(int_t s, const void *data, size_t length, int_t flags);
615 
616 int_t sendto(int_t s, const void *data, size_t length, int_t flags,
617  const struct sockaddr *addr, socklen_t addrlen);
618 
619 int_t sendmsg(int_t s, struct msghdr *msg, int_t flags);
620 
621 int_t recv(int_t s, void *data, size_t size, int_t flags);
622 
623 int_t recvfrom(int_t s, void *data, size_t size, int_t flags,
624  struct sockaddr *addr, socklen_t *addrlen);
625 
626 int_t recvmsg(int_t s, struct msghdr *msg, int_t flags);
627 
628 int_t getsockname(int_t s, struct sockaddr *addr, socklen_t *addrlen);
629 int_t getpeername(int_t s, struct sockaddr *addr, socklen_t *addrlen);
630 
631 int_t setsockopt(int_t s, int_t level, int_t optname, const void *optval,
632  socklen_t optlen);
633 
634 int_t getsockopt(int_t s, int_t level, int_t optname, void *optval,
635  socklen_t *optlen);
636 
637 int_t setipv4sourcefilter(int_t s, struct in_addr interface, struct in_addr group,
638  uint32_t fmode, uint_t numsrc, struct in_addr *slist);
639 
640 int_t getipv4sourcefilter(int_t s, struct in_addr interface, struct in_addr group,
641  uint32_t *fmode, uint_t *numsrc, struct in_addr *slist);
642 
643 int_t setsourcefilter(int_t s, uint32_t interface, struct sockaddr *group,
644  socklen_t grouplen, uint32_t fmode, uint_t numsrc,
645  struct sockaddr_storage *slist);
646 
647 int_t getsourcefilter(int_t s, uint32_t interface, struct sockaddr *group,
648  socklen_t grouplen, uint32_t *fmode, uint_t *numsrc,
649  struct sockaddr_storage *slist);
650 
651 int_t ioctlsocket(int_t s, uint32_t cmd, void *arg);
652 int_t fcntl(int_t s, int_t cmd, int_t arg);
653 
654 int_t shutdown(int_t s, int_t how);
656 
657 int_t select(int_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
658  const struct timeval *timeout);
659 
660 int_t gethostname(char_t *name, size_t len);
661 struct hostent *gethostbyname(const char_t *name);
662 
663 struct hostent *gethostbyname_r(const char_t *name, struct hostent *result,
664  char_t *buf, size_t buflen, int_t *h_errnop);
665 
666 int_t getaddrinfo(const char_t *node, const char_t *service,
667  const struct addrinfo *hints, struct addrinfo **res);
668 
669 void freeaddrinfo(struct addrinfo *res);
670 
671 int_t getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
672  char_t *host, size_t hostlen, char_t *serv, size_t servlen, int flags);
673 
674 uint_t if_nametoindex(const char_t *ifname);
675 char_t *if_indextoname(uint_t ifindex, char_t *ifname);
676 
677 in_addr_t inet_addr(const char_t *cp);
678 
679 int_t inet_aton(const char_t *cp, struct in_addr *inp);
680 const char_t *inet_ntoa(struct in_addr in);
681 const char_t *inet_ntoa_r(struct in_addr in, char_t *buf, socklen_t buflen);
682 
683 int_t inet_pton(int_t af, const char_t *src, void *dst);
684 const char_t *inet_ntop(int_t af, const void *src, char_t *dst, socklen_t size);
685 
686 //C++ guard
687 #ifdef __cplusplus
688 }
689 #endif
690 
691 #endif
692 #endif
int_t getsourcefilter(int_t s, uint32_t interface, struct sockaddr *group, socklen_t grouplen, uint32_t *fmode, uint_t *numsrc, struct sockaddr_storage *slist)
Get multicast source filter.
Definition: bsd_socket.c:2673
int_t listen(int_t s, int_t backlog)
Place a socket in the listening state.
Definition: bsd_socket.c:322
struct in_addr imr_sourceaddr
Definition: bsd_socket.h:414
struct ipv6_mreq IPV6_MREQ
Any-source multicast group information (for IPv6 only)
uint32_t gr_interface
Definition: bsd_socket.h:436
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:65
struct sockaddr * ai_addr
Definition: bsd_socket.h:559
int_t getaddrinfo(const char_t *node, const char_t *service, const struct addrinfo *hints, struct addrinfo **res)
Convert host and service names to socket address.
Definition: bsd_socket.c:3389
struct addrinfo * PADDRINFO
int_t socklen_t
Length type.
Definition: bsd_socket.h:303
Ancillary data header.
Definition: bsd_socket.h:496
uint32_t in_addr_t
IPv4 address.
Definition: bsd_socket.h:324
uint8_t sin_zero[8]
Definition: bsd_socket.h:368
struct hostent * gethostbyname_r(const char_t *name, struct hostent *result, char_t *buf, size_t buflen, int_t *h_errnop)
Host name resolution (reentrant version)
Definition: bsd_socket.c:3315
struct in6_addr IN6_ADDR
Structure that represents an IPv6 address.
int_t send(int_t s, const void *data, size_t length, int_t flags)
Send data to a connected socket.
Definition: bsd_socket.c:459
uint8_t protocol
Definition: ipv4.h:326
struct in_addr IN_ADDR
Structure that represents an IPv4 address.
uint32_t sin6_flowinfo
Definition: bsd_socket.h:390
signed int int_t
Definition: compiler_port.h:49
void * iov_base
Definition: bsd_socket.h:470
in_port_t sin6_port
Definition: bsd_socket.h:389
size_t iov_len
Definition: bsd_socket.h:471
Source-specific multicast group information (for IPv4/IPv6)
Definition: bsd_socket.h:446
struct in_addr imr_multiaddr
Definition: bsd_socket.h:413
int_t closesocket(int_t s)
The closesocket function closes an existing socket.
Definition: bsd_socket.c:3027
const char_t * inet_ntoa_r(struct in_addr in, char_t *buf, socklen_t buflen)
Convert a binary IPv4 address to dot-decimal notation (reentrant version)
Definition: bsd_socket.c:3919
struct ip_mreq IP_MREQ
Any-source multicast group information (for IPv4 only)
const struct in6_addr in6addr_any
Definition: bsd_socket.c:49
Set of sockets.
Definition: bsd_socket.h:530
struct in_pktinfo * PIN_PKTINFO
uint8_t data[]
Definition: ethernet.h:222
struct timeval * PTIMEVAL
struct ip_mreq_source * PIP_MREQ_SOURCE
socklen_t msg_namelen
Definition: bsd_socket.h:482
in_port_t sin_port
Definition: bsd_socket.h:366
struct in6_addr sin6_addr
Definition: bsd_socket.h:391
const char_t * inet_ntop(int_t af, const void *src, char_t *dst, socklen_t size)
Convert an IPv4 or IPv6 address from binary to text.
Definition: bsd_socket.c:4019
void * msg_control
Definition: bsd_socket.h:485
struct in_addr imr_interface
Definition: bsd_socket.h:403
uint8_t type
Definition: coap_common.h:176
struct sockaddr_in6 SOCKADDR_IN6
IPv6 address information.
Socket address storage.
Definition: bsd_socket.h:343
struct in_addr imr_interface
Definition: bsd_socket.h:415
struct cmsghdr * socketCmsgFirstHdr(struct msghdr *msg)
Get first ancillary data header.
int_t ioctlsocket(int_t s, uint32_t cmd, void *arg)
Control the I/O mode of a socket.
Definition: bsd_socket.c:2833
char_t name[]
sa_family_t sin6_family
Definition: bsd_socket.h:388
struct group_req GROUP_REQ
Any-source multicast group information (for IPv4/IPv6)
int_t setsourcefilter(int_t s, uint32_t interface, struct sockaddr *group, socklen_t grouplen, uint32_t fmode, uint_t numsrc, struct sockaddr_storage *slist)
Set multicast source filter.
Definition: bsd_socket.c:2508
int_t ai_flags
Definition: bsd_socket.h:554
const uint8_t res[]
IPv4 address information.
Definition: bsd_socket.h:364
Any-source multicast group information (for IPv4 only)
Definition: bsd_socket.h:401
int_t cmsg_level
Definition: bsd_socket.h:498
sa_family_t ss_family
Definition: bsd_socket.h:344
void socketFdClr(fd_set *fds, int_t s)
Remove a descriptor from an existing set.
IPv6 packet information.
Definition: bsd_socket.h:519
void * msg_name
Definition: bsd_socket.h:481
struct sockaddr_storage gsr_source
Definition: bsd_socket.h:449
uint8_t h_addr[16]
Definition: bsd_socket.h:544
void socketFdSet(fd_set *fds, int_t s)
Add a descriptor to an existing set.
Structure that represents an IPv6 address.
Definition: bsd_socket.h:377
int_t getsockname(int_t s, struct sockaddr *addr, socklen_t *addrlen)
Retrieves the local name for a socket.
Definition: bsd_socket.c:1476
struct timeval TIMEVAL
Timeout structure.
uint16_t sa_family_t
Address family.
Definition: bsd_socket.h:310
struct msghdr MSGHDR
Message header.
int32_t tv_sec
Definition: bsd_socket.h:573
int ipi_ifindex
Definition: bsd_socket.h:509
int_t fd_count
Definition: bsd_socket.h:531
struct in_addr * PIN_ADDR
struct cmsghdr * socketCmsgNextHdr(struct msghdr *msg, struct cmsghdr *cmsg)
Get next ancillary data header.
Linger structure.
Definition: bsd_socket.h:458
struct ip_mreq * PIP_MREQ
Socket address.
Definition: bsd_socket.h:332
uint32_t gsr_interface
Definition: bsd_socket.h:447
int_t recvfrom(int_t s, void *data, size_t size, int_t flags, struct sockaddr *addr, socklen_t *addrlen)
Receive a datagram.
Definition: bsd_socket.c:989
int_t ai_protocol
Definition: bsd_socket.h:557
IPv6 address information.
Definition: bsd_socket.h:387
char_t * if_indextoname(uint_t ifindex, char_t *ifname)
Map an interface index into its corresponding name.
Definition: bsd_socket.c:3795
Structure that represents an IPv4 address.
Definition: bsd_socket.h:354
uint16_t h_length
Definition: bsd_socket.h:543
void socketFdZero(fd_set *fds)
Initializes a descriptor set.
struct linger LINGER
Linger structure.
struct in6_pktinfo * PIN6_PKTINFO
struct cmsghdr * PCMSGHDR
struct sockaddr_in SOCKADDR_IN
IPv4 address information.
uint8_t sa_data[14]
Definition: bsd_socket.h:334
sa_family_t sin_family
Definition: bsd_socket.h:365
int ipi6_ifindex
Definition: bsd_socket.h:520
struct in6_addr ipv6mr_multiaddr
Definition: bsd_socket.h:425
struct sockaddr_in * PSOCKADDR_IN
struct hostent HOSTENT
Information about a given host.
int_t msg_iovlen
Definition: bsd_socket.h:484
int_t bind(int_t s, const struct sockaddr *addr, socklen_t addrlen)
Associate a local address with a socket.
Definition: bsd_socket.c:107
in_addr_t inet_addr(const char_t *cp)
Convert a dot-decimal string into binary data in network byte order.
Definition: bsd_socket.c:3833
Message header.
Definition: bsd_socket.h:480
struct hostent * PHOSTENT
int_t select(int_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout)
Determine the status of one or more sockets.
Definition: bsd_socket.c:3069
int_t fd_array[FD_SETSIZE]
Definition: bsd_socket.h:532
uint8_t length
Definition: tcp.h:368
const struct in6_addr in6addr_loopback
Definition: bsd_socket.c:52
struct in_addr imr_multiaddr
Definition: bsd_socket.h:402
int32_t tv_usec
Definition: bsd_socket.h:574
int_t sendmsg(int_t s, struct msghdr *msg, int_t flags)
Send a message.
Definition: bsd_socket.c:661
socklen_t ai_addrlen
Definition: bsd_socket.h:558
struct sockaddr_storage * PSOCKADDR_STORAGE
struct addrinfo ADDRINFO
Information about address of a service provider.
uint32_t sin6_scope_id
Definition: bsd_socket.h:392
struct group_req * PGROUP_REQ
struct in6_pktinfo IN6_PKTINFO
IPv6 packet information.
int_t gethostname(char_t *name, size_t len)
Get system host name.
Definition: bsd_socket.c:3251
struct ip_mreq_source IP_MREQ_SOURCE
Source-specific multicast group information (for IPv4 only)
struct sockaddr * PSOCKADDR
in_addr_t s_addr
Definition: bsd_socket.h:355
uint16_t in_port_t
Port number.
Definition: bsd_socket.h:317
uint8_t flags
Definition: tcp.h:351
struct sockaddr_storage gr_group
Definition: bsd_socket.h:437
int_t connect(int_t s, const struct sockaddr *addr, socklen_t addrlen)
Establish a connection to a specified socket.
Definition: bsd_socket.c:204
int_t recvmsg(int_t s, struct msghdr *msg, int_t flags)
Receive a message.
Definition: bsd_socket.c:1115
char char_t
Definition: compiler_port.h:48
struct in6_addr * PIN6_ADDR
struct group_source_req GROUP_SOURCE_REQ
Source-specific multicast group information (for IPv4/IPv6)
struct in_addr ipi_addr
Definition: bsd_socket.h:510
Information about a given host.
Definition: bsd_socket.h:541
Scatter/gather array.
Definition: bsd_socket.h:469
int_t socketFdIsSet(fd_set *fds, int_t s)
Check whether a descriptor is set.
size_t cmsg_len
Definition: bsd_socket.h:497
int_t l_onoff
Definition: bsd_socket.h:459
uint_t if_nametoindex(const char_t *ifname)
Map an interface name into its corresponding index.
Definition: bsd_socket.c:3756
int_t getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char_t *host, size_t hostlen, char_t *serv, size_t servlen, int flags)
Convert a socket address to a corresponding host and service.
Definition: bsd_socket.c:3658
const char_t * inet_ntoa(struct in_addr in)
Convert a binary IPv4 address to dot-decimal notation.
Definition: bsd_socket.c:3902
struct sockaddr SOCKADDR
Socket address.
int_t ipv6mr_interface
Definition: bsd_socket.h:426
void freeaddrinfo(struct addrinfo *res)
Free socket address structures.
Definition: bsd_socket.c:3629
struct msghdr * PMSGHDR
Timeout structure.
Definition: bsd_socket.h:572
struct in6_addr ipi6_addr
Definition: bsd_socket.h:521
int_t getipv4sourcefilter(int_t s, struct in_addr interface, struct in_addr group, uint32_t *fmode, uint_t *numsrc, struct in_addr *slist)
Get multicast source filter (IPv4 only)
Definition: bsd_socket.c:2414
int_t accept(int_t s, struct sockaddr *addr, socklen_t *addrlen)
Permit an incoming connection attempt on a socket.
Definition: bsd_socket.c:360
struct in_addr sin_addr
Definition: bsd_socket.h:367
#define FD_SET(s, fds)
Definition: bsd_socket.h:600
int_t ai_socktype
Definition: bsd_socket.h:556
int_t setipv4sourcefilter(int_t s, struct in_addr interface, struct in_addr group, uint32_t fmode, uint_t numsrc, struct in_addr *slist)
Set multicast source filter (IPv4 only)
Definition: bsd_socket.c:2313
sa_family_t sa_family
Definition: bsd_socket.h:333
int_t inet_pton(int_t af, const char_t *src, void *dst)
Convert an IPv4 or IPv6 address from text to binary form.
Definition: bsd_socket.c:3947
struct sockaddr_storage gsr_group
Definition: bsd_socket.h:448
uint8_t s
Definition: igmp_common.h:234
struct cmsghdr CMSGHDR
Ancillary data header.
int_t setsockopt(int_t s, int_t level, int_t optname, const void *optval, socklen_t optlen)
The setsockopt function sets a socket option.
Definition: bsd_socket.c:1672
struct linger * PLINGER
struct iovec * msg_iov
Definition: bsd_socket.h:483
Ipv4Addr addr
Definition: nbns_common.h:123
Any-source multicast group information (for IPv6 only)
Definition: bsd_socket.h:424
int_t cmsg_type
Definition: bsd_socket.h:499
int_t inet_aton(const char_t *cp, struct in_addr *inp)
Convert a dot-decimal string into binary form.
Definition: bsd_socket.c:3867
struct hostent * gethostbyname(const char_t *name)
Host name resolution.
Definition: bsd_socket.c:3292
int_t sendto(int_t s, const void *data, size_t length, int_t flags, const struct sockaddr *addr, socklen_t addrlen)
Send a datagram to a specific destination.
Definition: bsd_socket.c:535
int_t fcntl(int_t s, int_t cmd, int_t arg)
Perform specific operation.
Definition: bsd_socket.c:2933
int_t ai_family
Definition: bsd_socket.h:555
struct group_source_req * PGROUP_SOURCE_REQ
unsigned int uint_t
Definition: compiler_port.h:50
size_t msg_controllen
Definition: bsd_socket.h:486
uint8_t ss_pad[26]
Definition: bsd_socket.h:345
int_t recv(int_t s, void *data, size_t size, int_t flags)
Receive data from a connected socket.
Definition: bsd_socket.c:917
#define FD_SETSIZE
Definition: bsd_socket.h:43
Source-specific multicast group information (for IPv4 only)
Definition: bsd_socket.h:412
RTOS abstraction layer.
struct fd_set * PFD_SET
int_t getsockopt(int_t s, int_t level, int_t optname, void *optval, socklen_t *optlen)
The getsockopt function retrieves a socket option.
Definition: bsd_socket.c:2024
int_t getpeername(int_t s, struct sockaddr *addr, socklen_t *addrlen)
Retrieves the address of the peer to which a socket is connected.
Definition: bsd_socket.c:1572
int_t l_linger
Definition: bsd_socket.h:460
struct sockaddr_in6 * PSOCKADDR_IN6
Information about address of a service provider.
Definition: bsd_socket.h:553
struct in_pktinfo IN_PKTINFO
IPv4 packet information.
int_t msg_flags
Definition: bsd_socket.h:487
struct sockaddr_storage SOCKADDR_STORAGE
Socket address storage.
struct ipv6_mreq * PIPV6_MREQ
Any-source multicast group information (for IPv4/IPv6)
Definition: bsd_socket.h:435
uint8_t s6_addr[16]
Definition: bsd_socket.h:378
struct fd_set fd_set
Set of sockets.
int_t shutdown(int_t s, int_t how)
The shutdown function disables sends or receives on a socket.
Definition: bsd_socket.c:2991
uint16_t h_addrtype
Definition: bsd_socket.h:542
struct addrinfo * ai_next
Definition: bsd_socket.h:561
IPv4 packet information.
Definition: bsd_socket.h:508
char_t * ai_canonname
Definition: bsd_socket.h:560