1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 /**************************************************************************/ 12 /**************************************************************************/ 13 /** */ 14 /** NetX Component */ 15 /** */ 16 /** BSD 4.3 Socket API Compatible Interface to NetX Duo */ 17 /** */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 /**************************************************************************/ 23 /* */ 24 /* BSD DEFINITIONS RELEASE */ 25 /* */ 26 /* nxd_bsd.h PORTABLE C */ 27 /* 6.4.0 */ 28 /* AUTHOR */ 29 /* */ 30 /* Yuxin Zhou, Microsoft Corporation */ 31 /* */ 32 /* DESCRIPTION */ 33 /* */ 34 /* This file defines the constants, structures, etc... needed to */ 35 /* implement the BSD 4.3 Socket API Compatible Interface to NetX Duo. */ 36 /* */ 37 /* */ 38 /* RELEASE HISTORY */ 39 /* */ 40 /* DATE NAME DESCRIPTION */ 41 /* */ 42 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 43 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 44 /* resulting in version 6.1 */ 45 /* 03-02-2021 Yuxin Zhou Modified comment(s), and */ 46 /* fixed compiler warnings, */ 47 /* resulting in version 6.1.5 */ 48 /* 10-15-2021 Yuxin Zhou Modified comment(s), and */ 49 /* defined IP protocols for */ 50 /* ICMP, IGMP and ICMPv6, */ 51 /* resulting in version 6.1.9 */ 52 /* 10-31-2023 Chaoqiong Xiao Modified comment(s), and */ 53 /* added option to enable */ 54 /* native APIs with prefix, */ 55 /* resulting in version 6.3.0 */ 56 /* 12-31-2023 Yanwu Cai Modified comment(s), and */ 57 /* added support of recvmsg, */ 58 /* added nx_link to raw socket,*/ 59 /* resulting in version 6.4.0 */ 60 /* */ 61 /**************************************************************************/ 62 63 #ifndef NXD_BSD_H 64 #define NXD_BSD_H 65 66 /* Determine if a C++ compiler is being used. If so, ensure that standard 67 C is used to process the API information. */ 68 69 #ifdef __cplusplus 70 71 /* Yes, C++ compiler is present. Use standard C. */ 72 extern "C" { 73 74 #endif 75 76 #ifndef __CCRX__ 77 #include "time.h" 78 #endif /* __CCRX__ */ 79 80 /* Bring in the necessary NetX include file. */ 81 #include "nx_api.h" 82 83 84 /* Define the print error macro for reporting source line number. 85 86 #define NX_BSD_PRINT_ERRORS 87 */ 88 89 /* Defined, raw pppoe feature is enabled. */ 90 /* 91 #define NX_BSD_RAW_PPPOE_SUPPORT 92 */ 93 94 /* Defined, raw feature is enabled. */ 95 /* 96 #define NX_BSD_RAW_SUPPORT 97 */ 98 99 /* Defined, raw packet is not duplicated. Then NetX will not handle packets such as ARP. */ 100 /* 101 #define NX_DISABLE_BSD_RAW_PACKET_DUPLICATE 102 */ 103 104 #if defined(NX_BSD_RAW_SUPPORT) && defined(NX_BSD_RAW_PPPOE_SUPPORT) 105 #error "Raw feature conflicts with raw PPPoE feature" 106 #endif /* defined(NX_BSD_RAW_SUPPORT) && defined(NX_BSD_RAW_PPPOE_SUPPORT) */ 107 108 /* Defined, getaddrinfo is able to get address by name/cname. getnameinfo is able to get name by address. */ 109 /* 110 #define NX_BSD_ENABLE_DNS 111 */ 112 113 114 /* 115 Define the BSD socket timeout process to execute in the timer context. 116 If this option is not defined, application needs to create stack space for the BSD timeout process 117 thread, and passes the stack to the BSD layer through the bsd_initialize() call. In this configuration, 118 the BSD timeout process is all done in the BSD timeout process thread context. 119 120 User may choose to define NX_BSD_TIMEOUT_PROCESS_IN_TIMER, so the BSD timeout process is executed in the 121 ThreadX timer object context. This configuration could eliminate an extra thread (and associated stack 122 space.) The following parameters passed into bsd_initialize are ignored: 123 * bsd_thread_stack_area 124 * bsd_thread_stack_size 125 * bsd_thread_priority 126 However system designer needs to be aware of the following if the BSD timeout process is 127 executed in ThreadX timer context: 128 * The amount of BSD socket processing may slow down the ThreadX timer; 129 * If the timer is executed in ISR context (ThreadX library is built with TX_TIMER_PROCESS_IN_ISR), 130 the BSD timeout process is now executing in the ISR context; 131 132 By default NX_BSD_TIMEOUT_PROCESS_IN_TIMER is NOT defined. 133 */ 134 /* #define NX_BSD_TIMEOUT_PROCESS_IN_TIMER */ 135 136 137 /* Defined, APIs are natively named with nx_bsd_ prefix to avoid conflicting/overriding OS BSD APIs. */ 138 /* 139 #define NX_BSD_ENABLE_NATIVE_API 140 */ 141 142 143 /* Define configuration constants for the BSD compatibility layer. Note that these can be overridden via -D or a #define somewhere else. */ 144 145 #ifndef NX_BSD_TCP_WINDOW 146 #define NX_BSD_TCP_WINDOW 65535 /* 64k is typical window size for 100Mb ethernet. */ 147 #endif 148 149 #ifndef NX_BSD_SOCKFD_START 150 #define NX_BSD_SOCKFD_START 32 /* Logical FD starting value. */ 151 #endif 152 153 #ifndef NX_BSD_MAX_SOCKETS 154 #define NX_BSD_MAX_SOCKETS 32 /* Maximum number of total sockets available in the BSD layer. Note */ 155 #endif /* NOTE: Must be multiple of 32! */ 156 157 #ifndef NX_BSD_MAX_LISTEN_BACKLOG 158 #define NX_BSD_MAX_LISTEN_BACKLOG 5 /* Maximum listen backlog. */ 159 #endif 160 161 #ifndef NX_MICROSECOND_PER_CPU_TICK 162 #define NX_MICROSECOND_PER_CPU_TICK (1000000/NX_IP_PERIODIC_RATE) /* Number of microseconds per timer interrupt, default 10ms. */ 163 #endif 164 #ifndef NX_BSD_TIMEOUT 165 #define NX_BSD_TIMEOUT (20*NX_IP_PERIODIC_RATE) 166 /* By default all internal NetX calls wait and block for 20 seconds. */ 167 #endif 168 169 170 #ifndef NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT 171 #define NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT 1 /* Timeout in timer ticks for internal NetX to disconnect the socket. 172 The default value of 1 tick is so NetX BSD emulates native BSD 173 socket and performs an immediate socket close without sending an RST 174 packet. */ 175 #endif 176 177 #ifndef NX_BSD_IFNAMSIZE 178 #define NX_BSD_IFNAMSIZE 32 179 #endif 180 181 /* Define configurable options for BSD extended options. */ 182 183 184 #ifndef NX_BSD_TIMER_RATE 185 #define NX_BSD_TIMER_RATE (1 * NX_IP_PERIODIC_RATE) /* Rate at which BSD timer runs. */ 186 #endif 187 188 189 /* Define BSD events */ 190 191 #define NX_BSD_RECEIVE_EVENT ((ULONG) 0x00000001) /* Event flag to signal a receive packet event */ 192 #define NX_BSD_SELECT_EVENT ((ULONG) 0x00008000) /* Event flag to signal a thread is waiting in select */ 193 #define NX_BSD_ALL_EVENTS ((ULONG) 0xFFFFFFFF) /* All event flag */ 194 #define NX_BSD_CONNECT_EVENT ((ULONG) 0x00000002) 195 #define NX_BSD_LINGER_EVENT ((ULONG) 0x00000004) /* Event flag to signal a timed linger state has expired on a socket */ 196 #define NX_BSD_TIMED_WAIT_EVENT ((ULONG) 0x00000008) /* Event flag to signal a timed wait state has expired on a socket */ 197 #define NX_BSD_TIMER_EVENT ((ULONG) 0x00000010) /* Event flag to singal a BSD 1 sec timer */ 198 199 200 /* For BSD APIs overriding. */ 201 202 #if !defined(NX_BSD_ENABLE_NATIVE_API) 203 204 205 /* Overriding struct names. */ 206 207 #define nx_bsd_time_t time_t 208 #define nx_bsd_suseconds_t suseconds_t 209 210 #define nx_bsd_timeval timeval 211 212 #define nx_bsd_sockaddr_storage sockaddr_storage 213 214 #define nx_bsd_sockaddr sockaddr 215 216 #define nx_bsd_in6_addr in6_addr 217 218 #define nx_bsd_sockaddr_in6 sockaddr_in6 219 220 #define nx_bsd_in_addr in_addr 221 #define nx_bsd_in_addr_t in_addr_t 222 #define nx_bsd_socklen_t socklen_t 223 224 #define nx_bsd_sockaddr_in sockaddr_in 225 226 #define nx_bsd_fd_set fd_set 227 228 #define nx_bsd_ip_mreq ip_mreq 229 230 #define nx_bsd_sock_errno sock_errno 231 232 #define nx_bsd_linger linger 233 234 #define nx_bsd_sock_keepalive sock_keepalive 235 236 #define nx_bsd_sock_reuseaddr sock_reuseaddr 237 238 #define nx_bsd_sock_winsize sock_winsize 239 240 #define nx_bsd_addrinfo addrinfo 241 242 #define nx_bsd_pollfd pollfd 243 244 #define nx_bsd_sockaddr_ll sockaddr_ll 245 246 247 /* Overriding function names. */ 248 249 #define nx_bsd_accept accept 250 #define nx_bsd_initialize bsd_initialize 251 #define nx_bsd_bind bind 252 #define nx_bsd_connect connect 253 #define nx_bsd_getpeername getpeername 254 #define nx_bsd_getsockname getsockname 255 #define nx_bsd_ioctl ioctl 256 #define nx_bsd_inet_addr inet_addr 257 #define nx_bsd_inet_ntoa inet_ntoa 258 #define nx_bsd_inet_aton inet_aton 259 #define nx_bsd_inet_pton inet_pton 260 #define nx_bsd_inet_ntop inet_ntop 261 #define nx_bsd_listen listen 262 #define nx_bsd_recvfrom recvfrom 263 #define nx_bsd_recv recv 264 #define nx_bsd_recvmsg recvmsg 265 #define nx_bsd_sendto sendto 266 #define nx_bsd_send send 267 #define nx_bsd_select select 268 #define nx_bsd_soc_close soc_close 269 #define nx_bsd_socket socket 270 #define nx_bsd_fcntl fcntl 271 #define nx_bsd_getsockopt getsockopt 272 #define nx_bsd_setsockopt setsockopt 273 #define nx_bsd_getaddrinfo getaddrinfo 274 #define nx_bsd_freeaddrinfo freeaddrinfo 275 #define nx_bsd_getnameinfo getnameinfo 276 #define nx_bsd_set_errno set_errno 277 #define nx_bsd_poll poll 278 279 #define NX_BSD_FD_SET FD_SET 280 #define NX_BSD_FD_CLR FD_CLR 281 #define NX_BSD_FD_ISSET FD_ISSET 282 #define NX_BSD_FD_ZERO FD_ZERO 283 284 285 286 #endif 287 288 /* For compatibility undefine the fd_set. Then define the FD set size. */ 289 290 #ifdef fd_set 291 #undef fd_set 292 #endif 293 294 #ifdef FD_SETSIZE 295 #undef FD_SETSIZE /* May be different in other header files e.g 64 in GNU types.h file */ 296 #define FD_SETSIZE (NX_BSD_MAX_SOCKETS + NX_BSD_SOCKFD_START) /* Number of sockets to select on - same is max sockets! */ 297 #else 298 #define FD_SETSIZE (NX_BSD_MAX_SOCKETS + NX_BSD_SOCKFD_START) /* Number of sockets to select on - same is max sockets! */ 299 #endif 300 301 302 /* Define some BSD protocol constants. */ 303 304 #define SOCK_STREAM 1 /* TCP Socket */ 305 #define SOCK_DGRAM 2 /* UDP Socket */ 306 #define SOCK_RAW 3 /* Raw socket */ 307 #define IPPROTO_ICMP 1 /* ICMP used with socket type SOCK_RAW */ 308 #define IPPROTO_IGMP 2 /* IGMP used with socket type SOCK_RAW */ 309 #define IPPROTO_TCP 6 /* TCP Socket */ 310 #define IPPROTO_UDP 17 /* TCP Socket */ 311 #define IPPROTO_ICMPV6 58 /* ICMPv6 used with socket type SOCK_RAW */ 312 #define IPPROTO_RAW 255 /* Raw Socket */ 313 314 /* Define supported flags for 'send' and 'recv'. */ 315 #define MSG_PEEK 0x02 /* Peek incoming message */ 316 #define MSG_DONTWAIT 0x40 /* Nonblocking IO */ 317 318 /* Address families. */ 319 320 #define AF_UNSPEC 0 /* Unspecified. */ 321 #define AF_NS 1 /* Local to host (pipes, portals). */ 322 #define AF_INET 2 /* IPv4 socket (UDP, TCP, etc) */ 323 #define AF_INET6 3 /* IPv6 socket (UDP, TCP, etc) */ 324 #define AF_PACKET 4 /* Raw Packet type (Link Layer packets) */ 325 326 /* Protocol families, same as address families. */ 327 #define PF_INET AF_INET 328 #define PF_INET6 AF_INET6 329 #define PF_PACKET AF_PACKET 330 #define ETH_P_ALL 3 331 332 #define INADDR_ANY 0 333 #define NX_BSD_LOCAL_IF_INADDR_ANY 0xFFFFFFFF 334 /* Define API error codes. */ 335 336 #define NX_SOC_ERROR -1 /* Failure. */ 337 #ifndef ERROR 338 #define ERROR NX_SOC_ERROR 339 #endif 340 #define NX_SOC_OK 0 /* Success. */ 341 #ifndef OK 342 #define OK NX_SOC_OK 343 #endif 344 #define NX_BSD_BLOCK_POOL_ERROR 1 345 #define NX_BSD_MUTEX_ERROR 2 346 #define NX_BSD_THREAD_ERROR 4 347 #define NX_BSD_EVENT_ERROR 7 348 #define NX_BSD_ENVIRONMENT_ERROR 8 349 350 #ifndef NX_PACKET_OFFSET_ERROR 351 #define NX_PACKET_OFFSET_ERROR 0x53 352 #endif 353 354 /* The Netx API does not require Host to Network conversion or vice versa. The following macro's are provided for source compatibility reasons only. */ 355 356 #ifndef htons 357 #define htons(a) a 358 #endif 359 #ifndef htonl 360 #define htonl(a) a 361 #endif 362 #ifndef ntohs 363 #define ntohs(a) a 364 #endif 365 #ifndef ntohl 366 #define ntohl(a) a 367 #endif 368 369 /* Define error handling macro. */ 370 371 #ifdef NX_BSD_PRINT_ERRORS 372 #define NX_BSD_ERROR(status, line) printf(" NX BSD debug error message:, NX status: %x source line: %i \n", status, line) 373 #else 374 #define NX_BSD_ERROR(status, line) 375 #endif 376 377 378 /* Define file descriptor operation flags. */ 379 380 /* Note: FIONREAD is hardware dependant. The default is for i386 processor. */ 381 #ifndef FIONREAD 382 #define FIONREAD 0x541B /* Read bytes available for the ioctl() command */ 383 #endif 384 385 #define F_GETFL 3 /* Get file descriptors */ 386 #define F_SETFL 4 /* Set a subset of file descriptors (e.g. O_NONBlOCK */ 387 #define O_NONBLOCK 0x4000 /* Option to enable non blocking on a file (e.g. socket) */ 388 389 #ifndef FIONBIO 390 #define FIONBIO 0x5421 /* Enables socket non blocking option for the ioctl() command */ 391 #endif 392 393 #define SIOCGIFINDEX 0x8933 /* Get if_index from name */ 394 #define SIOCGIFHWADDR 0x8927 /* Get hardware address */ 395 396 /* Define the minimal TCP socket listen backlog value. */ 397 #ifndef NX_BSD_TCP_LISTEN_MIN_BACKLOG 398 #define NX_BSD_TCP_LISTEN_MIN_BACKLOG 1 399 #endif 400 401 /* Define the maximum number of packets that can be queued on a UDP socket or RAW socket. */ 402 #ifndef NX_BSD_SOCKET_QUEUE_MAX 403 #define NX_BSD_SOCKET_QUEUE_MAX 5 404 #endif 405 406 /* Define the constants that determine how big the hash table is for raw socket Protocol. The 407 value must be a power of two, so subtracting one gives us the mask. */ 408 409 #ifndef NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE 410 #define NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE 32 411 #endif /* NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE */ 412 413 #define NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_MASK (NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE-1) 414 415 /* Define additional BSD socket errors. */ 416 417 /* From errno-base.h in /usr/include/asm-generic; */ 418 #define EPERM 1 /* Operation not permitted */ 419 #define E_MIN 1 /* Minimum Socket/IO error */ 420 #define ENOENT 2 /* No such file or directory */ 421 #define ESRCH 3 /* No such process */ 422 #define EINTR 4 /* Interrupted system call */ 423 #define EIO 5 /* I/O error */ 424 #define ENXIO 6 /* No such device or address */ 425 #define E2BIG 7 /* Argument list too long */ 426 #define ENOEXEC 8 /* Exec format error */ 427 #define EBADF 9 /* Bad file number */ 428 #define ECHILD 10 /* No child processes */ 429 #define EAGAIN 11 /* Try again */ 430 #define ENOMEM 12 /* Out of memory */ 431 #define EACCES 13 /* Permission denied */ 432 #define EFAULT 14 /* Bad address */ 433 #define ENOTBLK 15 /* Block device required */ 434 #define EBUSY 16 /* Device or resource busy */ 435 #define EEXIST 17 /* File exists */ 436 #define EXDEV 18 /* Cross-device link */ 437 #define ENODEV 19 /* No such device */ 438 #define ENOTDIR 20 /* Not a directory */ 439 #define EISDIR 21 /* Is a directory */ 440 #define EINVAL 22 /* Invalid argument */ 441 #define ENFILE 23 /* File table overflow */ 442 #define EMFILE 24 /* Too many open files */ 443 #define ENOTTY 25 /* Not a typewriter */ 444 #define ETXTBSY 26 /* Text file busy */ 445 #define EFBIG 27 /* File too large */ 446 #define ENOSPC 28 /* No space left on device */ 447 #define ESPIPE 29 /* Illegal seek */ 448 #define EROFS 30 /* Read-only file system */ 449 #define EMLINK 31 /* Too many links */ 450 #define EPIPE 32 /* Broken pipe */ 451 #define EDOM 33 /* Math argument out of domain of func */ 452 #define ERANGE 34 /* Math result not representable */ 453 454 /* From errno.h in /usr/include/asm-generic; */ 455 456 #define EDEADLK 35 /* Resource deadlock would occur */ 457 #define ENAMETOOLONG 36 /* File name too long */ 458 #define ENOLCK 37 /* No record locks available */ 459 #define ENOSYS 38 /* Function not implemented */ 460 #define ENOTEMPTY 39 /* Directory not empty */ 461 #define ELOOP 40 /* Too many symbolic links encountered */ 462 #define EWOULDBLOCK EAGAIN /* Operation would block */ 463 #define ENOMSG 42 /* No message of desired type */ 464 #define EIDRM 43 /* Identifier removed */ 465 #define ECHRNG 44 /* Channel number out of range */ 466 #define EL2NSYNC 45 /* Level 2 not synchronized */ 467 #define EL3HLT 46 /* Level 3 halted */ 468 #define EL3RST 47 /* Level 3 reset */ 469 #define ELNRNG 48 /* Link number out of range */ 470 #define EUNATCH 49 /* Protocol driver not attached */ 471 #define ENOCSI 50 /* No CSI structure available */ 472 #define EL2HLT 51 /* Level 2 halted */ 473 #define EBADE 52 /* Invalid exchange */ 474 #define EBADR 53 /* Invalid request descriptor */ 475 #define EXFULL 54 /* Exchange full */ 476 #define ENOANO 55 /* No anode */ 477 #define EBADRQC 56 /* Invalid request code */ 478 #define EBADSLT 57 /* Invalid slot */ 479 #define EDEADLOCK EDEADLK 480 #define EBFONT 59 /* Bad font file format */ 481 #define ENOSTR 60 /* Device not a stream */ 482 #define ENODATA 61 /* No data available */ 483 #define ETIME 62 /* Timer expired */ 484 #define ENOSR 63 /* Out of streams resources */ 485 #define ENONET 64 /* Machine is not on the network */ 486 #define ENOPKG 65 /* Package not installed */ 487 #define EREMOTE 66 /* Object is remote */ 488 #define ENOLINK 67 /* Link has been severed */ 489 #define EADV 68 /* Advertise error */ 490 #define ESRMNT 69 /* Srmount error */ 491 #define ECOMM 70 /* Communication error on send */ 492 #define EPROTO 71 /* Protocol error */ 493 #define EMULTIHOP 72 /* Multihop attempted */ 494 #define EDOTDOT 73 /* RFS specific error */ 495 #define EBADMSG 74 /* Not a data message */ 496 #define EOVERFLOW 75 /* Value too large for defined data type */ 497 #define ENOTUNIQ 76 /* Name not unique on network */ 498 #define EBADFD 77 /* File descriptor in bad state */ 499 #define EREMCHG 78 /* Remote address changed */ 500 #define ELIBACC 79 /* Can not access a needed shared library */ 501 #define ELIBBAD 80 /* Accessing a corrupted shared library */ 502 #define ELIBSCN 81 /* .lib section in a.out corrupted */ 503 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ 504 #define ELIBEXEC 83 /* Cannot exec a shared library directly */ 505 #define EILSEQ 84 /* Illegal byte sequence */ 506 #define ERESTART 85 /* Interrupted system call should be restarted */ 507 #define ESTRPIPE 86 /* Streams pipe error */ 508 #define EUSERS 87 /* Too many users */ 509 #define ENOTSOCK 88 /* Socket operation on non-socket */ 510 #define EDESTADDRREQ 89 /* Destination address required */ 511 #define EMSGSIZE 90 /* Message too long */ 512 #define EPROTOTYPE 91 /* Protocol wrong type for socket */ 513 #define ENOPROTOOPT 92 /* Protocol not available */ 514 #define EPROTONOSUPPORT 93 /* Protocol not supported */ 515 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ 516 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 517 #define EPFNOSUPPORT 96 /* Protocol family not supported */ 518 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ 519 #define EADDRINUSE 98 /* Address already in use */ 520 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ 521 #define ENETDOWN 100 /* Network is down */ 522 #define ENETUNREACH 101 /* Network is unreachable */ 523 #define ENETRESET 102 /* Network dropped connection because of reset */ 524 #define ECONNABORTED 103 /* Software caused connection abort */ 525 #define ECONNRESET 104 /* Connection reset by peer */ 526 #define ENOBUFS 105 /* No buffer space available */ 527 #define EISCONN 106 /* Transport endpoint is already connected */ 528 #define ENOTCONN 107 /* Transport endpoint is not connected */ 529 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ 530 #define ETOOMANYREFS 109 /* Too many references: cannot splice */ 531 #define ETIMEDOUT 110 /* Connection timed out */ 532 #define ECONNREFUSED 111 /* Connection refused */ 533 #define EHOSTDOWN 112 /* Host is down */ 534 #define EHOSTUNREACH 113 /* No route to host */ 535 #define EALREADY 114 /* Operation already in progress */ 536 #define EINPROGRESS 115 /* Operation now in progress */ 537 #define ESTALE 116 /* Stale NFS file handle */ 538 #define EUCLEAN 117 /* Structure needs cleaning */ 539 #define ENOTNAM 118 /* Not a XENIX named type file */ 540 #define ENAVAIL 119 /* No XENIX semaphores available */ 541 #define EISNAM 120 /* Is a named type file */ 542 #define EREMOTEIO 121 /* Remote I/O error */ 543 #define EDQUOT 122 /* Quota exceeded */ 544 #define ENOMEDIUM 123 /* No medium found */ 545 #define EMEDIUMTYPE 124 /* Wrong medium type */ 546 #define ECANCELED 125 /* Operation Canceled */ 547 #define ENOKEY 126 /* Required key not available */ 548 #define EKEYEXPIRED 127 /* Key has expired */ 549 #define EKEYREVOKED 128 /* Key has been revoked */ 550 #define EKEYREJECTED 129 /* Key was rejected by service */ 551 #define EOWNERDEAD 130 /* Owner died - for robust mutexes*/ 552 #define ENOTRECOVERABLE 131 /* State not recoverable */ 553 #define ERFKILL 132 /* Operation not possible due to RF-kill */ 554 555 556 /* List of BSD sock options from socket.h in /usr/include/asm/socket.h and asm-generic/socket.h. 557 Note: not all of these are implemented in NetX Duo Extended socket options. 558 559 The first set of socket options take the socket level (category) SOL_SOCKET. */ 560 561 #define SOL_SOCKET 1 /* Define the socket option category. */ 562 #define IPPROTO_IP 2 /* Define the IP option category. */ 563 #define SOL_PACKET 3 /* Define the packet option category. */ 564 #define SO_MIN 1 /* Minimum Socket option ID */ 565 #define SO_DEBUG 1 /* Debugging information is being recorded.*/ 566 #define SO_REUSEADDR 2 /* Enable reuse of local addresses in the time wait state */ 567 #define SO_TYPE 3 /* Socket type */ 568 #define SO_ERROR 4 /* Socket error status */ 569 #define SO_DONTROUTE 5 /* Bypass normal routing */ 570 #define SO_BROADCAST 6 /* Transmission of broadcast messages is supported.*/ 571 #define SO_SNDBUF 7 /* Enable setting trasnmit buffer size */ 572 #define SO_RCVBUF 8 /* Enable setting receive buffer size */ 573 #define SO_KEEPALIVE 9 /* Connections are kept alive with periodic messages */ 574 #define SO_OOBINLINE 10 /* Out-of-band data is transmitted in line */ 575 #define SO_NO_CHECK 11 /* Disable UDP checksum */ 576 #define SO_PRIORITY 12 /* Set the protocol-defined priority for all packets to be sent on this socket */ 577 #define SO_LINGER 13 /* Socket lingers on close pending remaining send/receive packets. */ 578 #define SO_BSDCOMPAT 14 /* Enable BSD bug-to-bug compatibility */ 579 #define SO_REUSEPORT 15 /* Rebind a port already in use */ 580 581 #ifndef SO_PASSCRED /* Used for passing credentials. Not currently in use. */ 582 #define SO_PASSCRED 16 /* Enable passing local user credentials */ 583 #define SO_PEERCRED 17 /* Obtain the process, user and group ids of the other end of the socket connection */ 584 #define SO_RCVLOWAT 18 /* Enable receive "low water mark" */ 585 #define SO_SNDLOWAT 19 /* Enable send "low water mark" */ 586 #define SO_RCVTIMEO 20 /* Enable receive timeout */ 587 #define SO_SNDTIMEO 21 /* Enable send timeout */ 588 #endif /* SO_PASSCRED */ 589 #define SO_SNDBUFFORCE 22 /* Enable setting trasnmit buffer size overriding user limit (admin privelege) */ 590 #define SO_RCVBUFFORCE 23 /* Enable setting trasnmit buffer size overriding user limit (admin privelege) */ 591 #define SO_MAX SO_RCVBUFFORCE /* Maximum Socket option ID */ 592 593 /* This second set of socket options take the socket level (category) IPPROTO_IP. */ 594 595 #define IP_MULTICAST_IF 27 /* Specify outgoing multicast interface */ 596 #define IP_MULTICAST_TTL 28 /* Specify the TTL value to use for outgoing multicast packet. */ 597 #define IP_MULTICAST_LOOP 29 /* Whether or not receive the outgoing multicast packet, loopbacloopbackk mode. */ 598 #define IP_BLOCK_SOURCE 30 /* Block multicast from certain source. */ 599 #define IP_UNBLOCK_SOURCE 31 /* Unblock multicast from certain source. */ 600 #define IP_ADD_MEMBERSHIP 32 /* Join IPv4 multicast membership */ 601 #define IP_DROP_MEMBERSHIP 33 /* Leave IPv4 multicast membership */ 602 #define IP_HDRINCL 34 /* Raw socket IPv4 header included. */ 603 #define IP_RAW_RX_NO_HEADER 35 /* NetX proprietary socket option that does not include 604 IPv4/IPv6 header (and extension headers) on received raw sockets.*/ 605 #define IP_RAW_IPV6_HDRINCL 36 /* Transmitted buffer over IPv6 socket contains IPv6 header. */ 606 #define IP_OPTION_MAX IP_RAW_IPV6_HDRINCL 607 608 #define PACKET_ADD_MEMBERSHIP 41 609 #define PACKET_DROP_MEMBERSHIP 42 610 #define PACKET_OPTION_MAX PACKET_DROP_MEMBERSHIP 611 612 #define PACKET_MR_MULTICAST 1 613 614 /* 615 * User-settable options (used with setsockopt). 616 */ 617 #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ 618 #define TCP_MAXSEG 0x02 /* set maximum segment size */ 619 #define TCP_NOPUSH 0x04 /* don't push last block of write */ 620 #define TCP_NOOPT 0x08 /* don't use TCP options */ 621 622 623 /* Define data types used in structure timeval. */ 624 625 #if defined(__CCRX__) || defined(NX_BSD_ENABLE_NATIVE_API) 626 typedef LONG nx_bsd_time_t; 627 #endif /* __CCRX__ || NX_BSD_ENABLE_NATIVE_API */ 628 typedef LONG nx_bsd_suseconds_t; 629 630 #ifndef __SES_ARM 631 struct nx_bsd_timeval 632 { 633 nx_bsd_time_t tv_sec; /* Seconds */ 634 nx_bsd_suseconds_t 635 tv_usec; /* Microseconds */ 636 }; 637 #endif /* __SES_ARM */ 638 639 struct nx_bsd_sockaddr_storage 640 { 641 USHORT ss_len; 642 USHORT ss_family; 643 }; 644 645 struct nx_bsd_sockaddr 646 { 647 USHORT sa_family; /* Address family (e.g. , AF_INET). */ 648 UCHAR sa_data[14]; /* Protocol- specific address information. */ 649 }; 650 651 struct nx_bsd_in6_addr 652 { 653 union 654 { 655 UCHAR _S6_u8[16]; 656 ULONG _S6_u32[4]; 657 } _S6_un; 658 }; 659 660 #define s6_addr _S6_un._S6_u8 661 #define s6_addr32 _S6_un._S6_u32 662 663 struct nx_bsd_sockaddr_in6 664 { 665 USHORT sin6_family; /* AF_INET6 */ 666 USHORT sin6_port; /* Transport layer port. */ 667 ULONG sin6_flowinfo; /* IPv6 flow information. */ 668 struct nx_bsd_in6_addr 669 sin6_addr; /* IPv6 address. */ 670 ULONG sin6_scope_id; /* set of interafces for a scope. */ 671 672 }; 673 674 /* Internet address (a structure for historical reasons). */ 675 676 struct nx_bsd_in_addr 677 { 678 ULONG s_addr; /* Internet address (32 bits). */ 679 }; 680 681 typedef ULONG nx_bsd_in_addr_t; 682 typedef ULONG nx_bsd_socklen_t; 683 684 685 686 /* Socket address, Internet style. */ 687 688 struct nx_bsd_sockaddr_in 689 { 690 USHORT sin_family; /* Internet Protocol (AF_INET). */ 691 USHORT sin_port; /* Address port (16 bits). */ 692 struct nx_bsd_in_addr 693 sin_addr; /* Internet address (32 bits). */ 694 CHAR sin_zero[8]; /* Not used. */ 695 }; 696 697 698 699 typedef struct FD_SET_STRUCT /* The select socket array manager. */ 700 { 701 INT fd_count; /* How many are SET? */ 702 ULONG fd_array[(NX_BSD_MAX_SOCKETS + 31)/32]; /* Bit map of SOCKET Descriptors. */ 703 } nx_bsd_fd_set; 704 705 706 707 typedef struct NX_BSD_SOCKET_SUSPEND_STRUCT 708 { 709 ULONG nx_bsd_socket_suspend_actual_flags; 710 nx_bsd_fd_set nx_bsd_socket_suspend_read_fd_set; 711 nx_bsd_fd_set nx_bsd_socket_suspend_write_fd_set; 712 nx_bsd_fd_set nx_bsd_socket_suspend_exception_fd_set; 713 714 } NX_BSD_SOCKET_SUSPEND; 715 716 717 struct nx_bsd_ip_mreq 718 { 719 struct nx_bsd_in_addr 720 imr_multiaddr; /* The IPv4 multicast address to join. */ 721 struct nx_bsd_in_addr 722 imr_interface; /* The interface to use for this group. */ 723 }; 724 725 #ifdef NX_BSD_RAW_SUPPORT 726 727 struct nx_bsd_packet_mreq 728 { 729 INT mr_ifindex; 730 USHORT mr_type; 731 USHORT mr_alen; 732 UCHAR mr_address[8]; 733 }; 734 735 #define ETH_ALEN 6 736 #define ETHERTYPE_VLAN 0x8100 737 738 struct nx_bsd_ether_header 739 { 740 UCHAR ether_dhost[ETH_ALEN]; 741 UCHAR ether_shost[ETH_ALEN]; 742 USHORT ether_type; 743 }; 744 745 struct nx_bsd_ifreq { 746 CHAR ifr_name[NX_BSD_IFNAMSIZE]; 747 union { 748 struct nx_bsd_sockaddr ifru_addr; 749 struct nx_bsd_sockaddr ifru_hwaddr; 750 SHORT ifru_flags; 751 INT ifru_ivalue; 752 } ifr_ifru; 753 }; 754 755 #define ifr_hwaddr ifr_ifru.ifru_hwaddr 756 #define ifr_ifindex ifr_ifru.ifru_ivalue 757 #endif 758 759 760 761 struct nx_bsd_iovec { 762 void *iov_base; 763 size_t iov_len; 764 }; 765 766 struct nx_bsd_msghdr { 767 void *msg_name; 768 nx_bsd_socklen_t msg_namelen; 769 struct nx_bsd_iovec *msg_iov; 770 size_t msg_iovlen; 771 void *msg_control; 772 size_t msg_controllen; 773 int msg_flags; 774 }; 775 776 /* Define additional BSD data structures for supporting socket options. */ 777 778 struct nx_bsd_sock_errno 779 { 780 INT error; /* default = 0; */ 781 }; 782 783 struct nx_bsd_linger 784 { 785 INT l_onoff; /* 0 = disabled; 1 = enabled; default = 0;*/ 786 INT l_linger; /* linger time in seconds; default = 0;*/ 787 }; 788 789 struct nx_bsd_sock_keepalive 790 { 791 INT keepalive_enabled; /* 0 = disabled; 1 = enabled; default = 0;*/ 792 }; 793 794 struct nx_bsd_sock_reuseaddr 795 { 796 INT reuseaddr_enabled; /* 0 = disabled; 1 = enabled; default = 1; */ 797 }; 798 799 struct nx_bsd_sock_winsize 800 { 801 INT winsize; /* receive window size for TCP sockets ; */ 802 }; 803 804 /* Define an union struct for master ID and secondary ID used in NX_BSD_SOCKET_STRUCT. */ 805 union UNION_ID 806 { 807 INT nx_bsd_socket_master_socket_id; 808 INT nx_bsd_socket_secondary_socket_id; 809 }; 810 811 812 struct nx_bsd_addrinfo 813 { 814 INT ai_flags; 815 INT ai_family; 816 INT ai_socktype; 817 INT ai_protocol; 818 nx_bsd_socklen_t ai_addrlen; 819 struct nx_bsd_sockaddr *ai_addr; 820 CHAR *ai_canonname; 821 struct nx_bsd_addrinfo 822 *ai_next; 823 }; 824 825 struct NX_BSD_SERVICE_LIST 826 { 827 CHAR *service_name; 828 USHORT service_port; 829 INT service_socktype; 830 INT service_protocol; 831 }; 832 833 /* Define the Errors return by getaddrinfo. */ 834 835 /* The specified host doesn't have addresses in the specified address family. */ 836 #define EAI_ADDRFAMILY 40 837 /* Name server temporary failure. */ 838 #define EAI_AGAIN 41 839 /* hints.si_flags contains invalid flag. */ 840 #define EAI_BADFLAGS 42 841 /* DNS fail. */ 842 #define EAI_FAIL 43 843 /* Invalid address family. */ 844 #define EAI_FAMILY 44 845 /* memory failure. */ 846 #define EAI_MEMORY 45 847 /* host exsits, but doesn't have address in specified family. */ 848 #define EAI_NODATA 46 849 #define EAI_NONAME 47 850 /* service not available for the specified socket type. */ 851 #define EAI_SERVICE 48 852 #define EAI_OVERFLOW 49 853 /* invalid socktype. */ 854 #define EAI_SOCKTYPE 50 855 #define EAI_SYSTEM 51 856 857 858 /* Define ai_flags value. */ 859 #define AI_PASSIVE 0x0001 860 /* request CNAME. */ 861 #define AI_CANONNAME 0x0002 862 /* host must be a address string. */ 863 #define AI_NUMERICHOST 0x0004 864 /* service must be a port string. */ 865 #define AI_NUMERICSERV 0x0008 866 #define AI_V4MAPPED 0x0010 867 #define AI_ALL 0x0020 868 #define AI_ADDRCONFIG 0x0040 869 870 /* Return numeric string for hostname. */ 871 #define NI_NUMERICHOST 0x0001 872 /* Return numeric string for service name. */ 873 #define NI_NUMERICSERV 0x0002 874 /* Return only hostname portion of FQDN. */ 875 #define NI_NOFQDN 0x0004 876 /* Return error if name can't be resolved from address. */ 877 #define NI_NAMEREQD 0x0008 878 /* Datagram service. */ 879 #define NI_DGRAM 0x0010 880 881 882 /* Define the struct used by poll. */ 883 struct nx_bsd_pollfd 884 { 885 INT fd; /* file descriptor. */ 886 SHORT events; /* requested events. */ 887 SHORT revents; /* returned events. */ 888 }; 889 890 /* Define the options used by poll. */ 891 892 #define POLLRDNORM 0x0100 893 #define POLLRDBAND 0x0200 /* Not supported. */ 894 #define POLLIN (POLLRDNORM) 895 #define POLLPRI 0x0400 896 897 #define POLLWRNORM 0x0010 898 #define POLLOUT (POLLWRNORM) 899 #define POLLWRBAND 0x0020 /* Not supported. */ 900 901 #define POLLERR 0x0001 902 #define POLLHUP 0x0002 903 #define POLLNVAL 0x0004 904 905 906 /* Defines maximum IPv4 addresses for getaddrinfo. */ 907 #ifndef NX_BSD_IPV4_ADDR_MAX_NUM 908 #define NX_BSD_IPV4_ADDR_MAX_NUM 5 909 #endif /* NX_BSD_IPV4_ADDR_MAX_NUM */ 910 911 /* Defines maximum IPv6 addresses for getaddrinfo. */ 912 #ifndef NX_BSD_IPV6_ADDR_MAX_NUM 913 #define NX_BSD_IPV6_ADDR_MAX_NUM 5 914 #endif /* NX_BSD_IPV6_ADDR_MAX_NUM */ 915 916 /* Defines maximum IPv4 addresses stored from DNS. */ 917 #ifndef NX_BSD_IPV4_ADDR_PER_HOST 918 #define NX_BSD_IPV4_ADDR_PER_HOST 5 919 #endif /* NX_BSD_IPV4_ADDR_PER_HOST */ 920 921 /* Defines maximum IPv6 addresses stored from DNS. */ 922 #ifndef NX_BSD_IPV6_ADDR_PER_HOST 923 #define NX_BSD_IPV6_ADDR_PER_HOST 2 924 #endif /* NX_BSD_IPV6_ADDR_PER_HOST */ 925 926 /* Define the BSD socket status bits. */ 927 #define NX_BSD_SOCKET_CONNECTION_INPROGRESS 1 928 #define NX_BSD_SOCKET_ERROR (1 << 1) 929 #define NX_BSD_SOCKET_CONNECTED (1 << 2) 930 /* Disconnected from the stack. */ 931 #define NX_BSD_SOCKET_DISCONNECT_FROM_STACK (1 << 3) 932 #define NX_BSD_SOCKET_SERVER_MASTER_SOCKET (1 << 4) 933 #define NX_BSD_SOCKET_SERVER_SECONDARY_SOCKET (1 << 5) 934 #define NX_BSD_SOCKET_TX_HDR_INCLUDE (1 << 6) 935 #define NX_BSD_SOCKET_RX_NO_HDR (1 << 7) 936 #define NX_BSD_SOCKET_IN_USE (1 << 8) 937 #define NX_BSD_SOCKET_CLIENT (1 << 9) 938 #define NX_BSD_SOCKET_ENABLE_LISTEN (1 << 10) 939 #define NX_BSD_SOCKET_BOUND (1 << 11) 940 #define NX_BSD_SOCKET_ACCEPTING (1 << 12) 941 #define NX_BSD_SOCKET_CONNECTION_REQUEST (1 << 13) 942 #define NX_BSD_SOCKET_DISCONNECTION_REQUEST (1 << 14) 943 944 /* Define the BSD socket options bits. */ 945 #define NX_BSD_SOCKET_ENABLE_RAW_SOCKET 1 946 #define NX_BSD_SOCKET_ENABLE_OPTION_LINGER (1 << 1) 947 #define NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR (1 << 2) 948 #define NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING (1 << 3) 949 950 /* Define the internal management structure for the BSD layer. */ 951 952 typedef struct NX_BSD_SOCKET_STRUCT 953 { 954 NX_TCP_SOCKET *nx_bsd_socket_tcp_socket; 955 NX_UDP_SOCKET *nx_bsd_socket_udp_socket; 956 ULONG nx_bsd_socket_family; 957 /* Store the protocol number. For example TCP is 6, UDP is 17. For raw socket 958 it is the protocol it wishes to receive. */ 959 USHORT nx_bsd_socket_protocol; 960 TX_THREAD *nx_bsd_socket_busy; 961 union UNION_ID nx_bsd_socket_union_id; 962 NX_PACKET* nx_bsd_socket_received_packet; 963 NX_PACKET* nx_bsd_socket_received_packet_tail; 964 UINT nx_bsd_socket_received_byte_count; 965 UINT nx_bsd_socket_received_byte_count_max; 966 UINT nx_bsd_socket_received_packet_count; 967 UINT nx_bsd_socket_received_packet_count_max; 968 ULONG nx_bsd_socket_received_packet_offset; 969 INT nx_bsd_socket_source_port; 970 ULONG nx_bsd_socket_local_bind_interface; 971 UINT nx_bsd_socket_local_bind_interface_index; 972 NXD_ADDRESS nx_bsd_socket_source_ip_address; 973 NXD_ADDRESS nx_bsd_socket_peer_ip; 974 975 /* For TCP/UDP, the local port is the port number this socket receives on. 976 For raw socket this field is not used. */ 977 USHORT nx_bsd_socket_local_port; 978 USHORT nx_bsd_socket_peer_port; 979 INT nx_bsd_option_linger_time; 980 UINT nx_bsd_option_linger_time_closed; 981 UINT nx_bsd_option_linger_start_close; 982 UINT nx_bsd_socket_time_wait_remaining; 983 ULONG nx_bsd_option_receive_timeout; 984 ULONG nx_bsd_option_send_timeout; 985 INT nx_bsd_file_descriptor_flags; 986 ULONG nx_bsd_socket_status_flags; 987 ULONG nx_bsd_socket_option_flags; 988 int nx_bsd_socket_error_code; 989 990 struct NX_BSD_SOCKET_STRUCT 991 *nx_bsd_socket_next; 992 struct NX_BSD_SOCKET_STRUCT 993 *nx_bsd_socket_previous; 994 995 INT nx_bsd_socket_id; 996 #ifdef NX_BSD_RAW_PPPOE_SUPPORT 997 UINT nx_bsd_socket_create_id; 998 #endif /* NX_BSD_RAW_PPPOE_SUPPORT */ 999 #if defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) 1000 UCHAR nx_bsd_socket_sll_addr[6]; 1001 USHORT nx_bsd_socket_sll_protocol; 1002 INT nx_bsd_socket_sll_ifindex; 1003 #endif /* defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) */ 1004 1005 } NX_BSD_SOCKET; 1006 1007 1008 /* Define the BSD function prototypes for use by the application. */ 1009 1010 1011 INT nx_bsd_accept(INT sockID, struct nx_bsd_sockaddr *ClientAddress, INT *addressLength); 1012 INT nx_bsd_initialize(NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, ULONG bsd_thread_stack_size, UINT bsd_thread_priority); 1013 INT nx_bsd_bind(INT sockID, const struct nx_bsd_sockaddr *localAddress, INT addressLength); 1014 INT nx_bsd_connect(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT addressLength); 1015 INT nx_bsd_getpeername(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT *addressLength); 1016 INT nx_bsd_getsockname(INT sockID, struct nx_bsd_sockaddr *localAddress, INT *addressLength); 1017 INT nx_bsd_ioctl(INT sockID, INT command, INT *result); 1018 nx_bsd_in_addr_t nx_bsd_inet_addr(const CHAR *buffer); 1019 CHAR *nx_bsd_inet_ntoa(struct nx_bsd_in_addr address_to_convert); 1020 INT nx_bsd_inet_aton(const CHAR *cp_arg, struct nx_bsd_in_addr *addr); 1021 INT nx_bsd_inet_pton(INT af, const CHAR *src, VOID *dst); 1022 const CHAR *nx_bsd_inet_ntop(INT af, const VOID *src, CHAR *dst, nx_bsd_socklen_t size); 1023 INT nx_bsd_listen(INT sockID, INT backlog); 1024 #ifdef NX_ENABLE_IP_RAW_PACKET_FILTER 1025 UINT nx_bsd_raw_packet_receive(NX_BSD_SOCKET *bsd_socket_ptr, NX_PACKET **packet_ptr); 1026 UINT nx_bsd_raw_packet_info_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *nxd_address, UINT *interface_index); 1027 VOID nx_bsd_raw_receive_notify(NX_IP *ip_ptr, UINT bsd_socket_index); 1028 #endif 1029 UINT nx_bsd_socket_set_inherited_settings(UINT master_sock_id, UINT secondary_sock_id); 1030 INT nx_bsd_recvfrom(INT sockID, CHAR *buffer, INT buffersize, INT flags,struct nx_bsd_sockaddr *fromAddr, INT *fromAddrLen); 1031 INT nx_bsd_recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags); 1032 INT nx_bsd_recvmsg(INT sockID, struct nx_bsd_msghdr *msg, INT flags); 1033 INT nx_bsd_sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr *destAddr, INT destAddrLen); 1034 INT nx_bsd_send(INT sockID, const CHAR *msg, INT msgLength, INT flags); 1035 INT nx_bsd_select(INT nfds, nx_bsd_fd_set *readfds, nx_bsd_fd_set *writefds, nx_bsd_fd_set *exceptfds, struct nx_bsd_timeval *timeout); 1036 INT nx_bsd_soc_close( INT sockID); 1037 INT nx_bsd_socket(INT protocolFamily, INT type, INT protocol); 1038 INT nx_bsd_fcntl(INT sock_ID, UINT flag_type, UINT f_options); 1039 INT nx_bsd_getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length); 1040 INT nx_bsd_setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length); 1041 INT nx_bsd_getaddrinfo(const CHAR *node, const CHAR *service, const struct nx_bsd_addrinfo *hints, struct nx_bsd_addrinfo **res); 1042 VOID nx_bsd_freeaddrinfo(struct nx_bsd_addrinfo *res); 1043 INT nx_bsd_getnameinfo(const struct nx_bsd_sockaddr *sa, nx_bsd_socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); 1044 VOID nx_bsd_set_service_list(struct NX_BSD_SERVICE_LIST *serv_list_ptr, ULONG serv_list_len); 1045 INT nx_bsd_poll(struct nx_bsd_pollfd *fds, ULONG nfds, INT timeout); 1046 1047 #if !defined(NX_BSD_ENABLE_NATIVE_API) 1048 #undef FD_SET 1049 #undef FD_CLR 1050 #undef FD_ISSET 1051 #undef FD_ZERO 1052 #endif 1053 1054 VOID NX_BSD_FD_SET(INT fd, nx_bsd_fd_set *fdset); 1055 VOID NX_BSD_FD_CLR(INT fd, nx_bsd_fd_set *fdset); 1056 INT NX_BSD_FD_ISSET(INT fd, nx_bsd_fd_set *fdset); 1057 VOID NX_BSD_FD_ZERO(nx_bsd_fd_set *fdset); 1058 VOID nx_bsd_set_errno(INT tx_errno); 1059 1060 INT _nxd_get_errno(VOID); 1061 1062 #if !defined(NX_BSD_ENABLE_NATIVE_API) 1063 #define errno (tx_thread_identify() -> bsd_errno) 1064 #else 1065 #define nx_bsd_errno (tx_thread_identify() -> bsd_errno) 1066 #endif 1067 1068 1069 #ifdef NX_BSD_RAW_PPPOE_SUPPORT 1070 1071 #define ETHERTYPE_PPPOE_DISC 0x8863 /* PPPoE Discovery protocol type */ 1072 #define ETHERTYPE_PPPOE_SESS 0x8864 /* PPPoE Session Protocol type */ 1073 1074 #define NX_LINK_PACKET_PPPOE_SESS_SEND ETHERTYPE_PPPOE_SESS 1075 #define NX_LINK_PACKET_PPPOE_DISC_SEND ETHERTYPE_PPPOE_DISC 1076 1077 1078 UINT _nx_bsd_pppoe_packet_received(NX_PACKET *packet_ptr, UINT frame_type, UINT interface_id); 1079 #endif /* NX_BSD_RAW_PPPOE_SUPPORT */ 1080 1081 #if defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) 1082 /* Link Layer Socket Addressing */ 1083 struct nx_bsd_sockaddr_ll 1084 { 1085 USHORT sll_family; /* Address Family. Must be AF_PACKET */ 1086 USHORT sll_protocol; /* LL frame type */ 1087 INT sll_ifindex; /* Interface Index. */ 1088 USHORT sll_hatype; /* Header type */ 1089 UCHAR sll_pkttype; /* Packet type */ 1090 UCHAR sll_halen; /* Length of address */ 1091 UCHAR sll_addr[8]; /* Physical layer address */ 1092 }; 1093 #endif /* defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) */ 1094 1095 #ifdef NX_BSD_RAW_SUPPORT 1096 extern UINT _nx_driver_hardware_packet_send(NX_PACKET *packet_ptr); /* Send hardware packet. */ 1097 extern VOID (*_nx_driver_hardware_packet_received_callback)(NX_PACKET *packet_ptr, UCHAR *consumed);/* Callback function pointer when packet is received. */ 1098 #endif /* NX_BSD_RAW_SUPPORT */ 1099 1100 1101 /* Determine if a C++ compiler is being used. If so, complete the standard 1102 C conditional started above. */ 1103 #ifdef __cplusplus 1104 } 1105 #endif 1106 1107 #endif /* NXD_BSD_H */ 1108 1109