summaryrefslogtreecommitdiff
path: root/addons/BSD/nxd_bsd.h
blob: 5223efd0e34621ae58ed07c5f92aea744bcb3e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2025-present Eclipse ThreadX Contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/

/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** NetX Component                                                        */
/**                                                                       */
/** BSD 4.3 Socket API Compatible Interface to NetX Duo                   */
/**                                                                       */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

/**************************************************************************/
/*                                                                        */
/*  BSD DEFINITIONS                                        RELEASE        */
/*                                                                        */
/*    nxd_bsd.h                                           PORTABLE C      */
/*                                                           6.4.3        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This file defines the constants, structures, etc... needed to       */
/*    implement the BSD 4.3 Socket API Compatible Interface to NetX Duo.  */
/*                                                                        */
/*                                                                        */
/**************************************************************************/

#ifndef NXD_BSD_H
#define NXD_BSD_H

/* Determine if a C++ compiler is being used.  If so, ensure that standard
   C is used to process the API information.  */

#ifdef   __cplusplus

/* Yes, C++ compiler is present.  Use standard C.  */
extern   "C" {

#endif

#ifndef __CCRX__
#include "time.h"
#endif /* __CCRX__ */

/* Bring in the necessary NetX include file.  */
#include "nx_api.h"


/* Define the print error macro for reporting source line number.

#define NX_BSD_PRINT_ERRORS
*/

/* Defined, raw pppoe feature is enabled. */
/*
#define NX_BSD_RAW_PPPOE_SUPPORT
*/

/* Defined, raw feature is enabled. */
/*
#define NX_BSD_RAW_SUPPORT
*/

/* Defined, raw packet is not duplicated. Then NetX will not handle packets such as ARP. */
/*
#define NX_DISABLE_BSD_RAW_PACKET_DUPLICATE
*/

#if defined(NX_BSD_RAW_SUPPORT) && defined(NX_BSD_RAW_PPPOE_SUPPORT)
#error "Raw feature conflicts with raw PPPoE feature"
#endif /* defined(NX_BSD_RAW_SUPPORT) && defined(NX_BSD_RAW_PPPOE_SUPPORT) */

/* Defined, getaddrinfo is able to get address by name/cname. getnameinfo is able to get name by address. */
/*
#define NX_BSD_ENABLE_DNS
*/


/*
   Define the BSD socket timeout process to execute in the timer context.
   If this option is not defined, application needs to create stack space for the BSD timeout process
   thread, and passes the stack to the BSD layer through the bsd_initialize() call.  In this configuration,
   the BSD timeout process is all done in the BSD timeout process thread context.

   User may choose to define NX_BSD_TIMEOUT_PROCESS_IN_TIMER, so the BSD timeout process is executed in the
   ThreadX timer object context.  This configuration could eliminate an extra thread (and associated stack
   space.)  The following parameters passed into bsd_initialize are ignored:
   * bsd_thread_stack_area
   * bsd_thread_stack_size
   * bsd_thread_priority
   However system designer needs to be aware of the following if the BSD timeout process is
   executed in ThreadX timer context:
   * The amount of BSD socket processing may slow down the ThreadX timer;
   * If the timer is executed in ISR context (ThreadX library is built with TX_TIMER_PROCESS_IN_ISR),
     the BSD timeout process is now executing in the ISR context;

     By default NX_BSD_TIMEOUT_PROCESS_IN_TIMER is NOT defined.
*/
/* #define NX_BSD_TIMEOUT_PROCESS_IN_TIMER */


/* Defined, APIs are natively named with nx_bsd_ prefix to avoid conflicting/overriding OS BSD APIs.  */
/*
#define NX_BSD_ENABLE_NATIVE_API
*/


/* Define configuration constants for the BSD compatibility layer.  Note that these can be overridden via -D or a #define somewhere else.  */

#ifndef NX_BSD_TCP_WINDOW
#define NX_BSD_TCP_WINDOW                   65535                   /* 64k is typical window size for 100Mb ethernet.                       */
#endif

#ifndef NX_BSD_SOCKFD_START
#define NX_BSD_SOCKFD_START                 32                      /* Logical FD starting value.                                           */
#endif

#ifndef NX_BSD_MAX_SOCKETS
#define NX_BSD_MAX_SOCKETS                  32                      /* Maximum number of total sockets available in the BSD layer. Note     */
#endif                                                              /*   NOTE:  Must be multiple of 32!                                     */

#ifndef NX_BSD_MAX_LISTEN_BACKLOG
#define NX_BSD_MAX_LISTEN_BACKLOG           5                       /* Maximum listen backlog.                                              */
#endif

#ifndef NX_MICROSECOND_PER_CPU_TICK
#define NX_MICROSECOND_PER_CPU_TICK         (1000000/NX_IP_PERIODIC_RATE) /* Number of microseconds per timer interrupt, default 10ms.            */
#endif
#ifndef NX_BSD_TIMEOUT
#define NX_BSD_TIMEOUT                      (20*NX_IP_PERIODIC_RATE)
                                                                    /* By default all internal NetX calls wait and block for 20 seconds.    */
#endif


#ifndef NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT
#define NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT 1                      /* Timeout in timer ticks for internal NetX to disconnect the socket.
                                                                       The default value of 1 tick is so NetX BSD emulates native BSD
                                                                       socket and performs an immediate socket close without sending an RST
                                                                       packet.                                                              */
#endif

#ifndef NX_BSD_IFNAMSIZE
#define NX_BSD_IFNAMSIZE                     32
#endif

/* Define configurable options for BSD extended options. */


#ifndef NX_BSD_TIMER_RATE
#define NX_BSD_TIMER_RATE                   (1 * NX_IP_PERIODIC_RATE)        /* Rate at which BSD timer runs.                                   */
#endif


/* Define BSD events */

#define NX_BSD_RECEIVE_EVENT                ((ULONG) 0x00000001)    /* Event flag to signal a receive packet event                          */
#define NX_BSD_SELECT_EVENT                 ((ULONG) 0x00008000)    /* Event flag to signal a thread is waiting in select                   */
#define NX_BSD_ALL_EVENTS                   ((ULONG) 0xFFFFFFFF)    /* All event flag                                                       */
#define NX_BSD_CONNECT_EVENT                ((ULONG) 0x00000002)
#define NX_BSD_LINGER_EVENT                 ((ULONG) 0x00000004)    /* Event flag to signal a timed linger state has expired on a socket    */
#define NX_BSD_TIMED_WAIT_EVENT             ((ULONG) 0x00000008)    /* Event flag to signal a timed wait state has expired on a socket      */
#define NX_BSD_TIMER_EVENT                  ((ULONG) 0x00000010)    /* Event flag to singal a BSD 1 sec timer */


/* For BSD APIs overriding.  */

#if !defined(NX_BSD_ENABLE_NATIVE_API)


/* Overriding struct names.  */

#define nx_bsd_time_t           time_t
#define nx_bsd_suseconds_t      suseconds_t

#define nx_bsd_timeval          timeval

#define nx_bsd_sockaddr_storage sockaddr_storage

#define nx_bsd_sockaddr         sockaddr

#define nx_bsd_in6_addr         in6_addr

#define nx_bsd_sockaddr_in6     sockaddr_in6

#define nx_bsd_in_addr          in_addr
#define nx_bsd_in_addr_t        in_addr_t
#define nx_bsd_socklen_t        socklen_t

#define nx_bsd_sockaddr_in      sockaddr_in

#define nx_bsd_fd_set           fd_set

#define nx_bsd_ip_mreq          ip_mreq

#define nx_bsd_sock_errno       sock_errno

#define nx_bsd_linger           linger

#define nx_bsd_sock_keepalive   sock_keepalive

#define nx_bsd_sock_reuseaddr   sock_reuseaddr

#define nx_bsd_sock_winsize     sock_winsize

#define nx_bsd_addrinfo         addrinfo

#define nx_bsd_pollfd           pollfd

#define nx_bsd_sockaddr_ll      sockaddr_ll


/* Overriding function names.  */

#define nx_bsd_accept           accept
#define nx_bsd_initialize       bsd_initialize
#define nx_bsd_bind             bind
#define nx_bsd_connect          connect
#define nx_bsd_getpeername      getpeername
#define nx_bsd_getsockname      getsockname
#define nx_bsd_ioctl            ioctl
#define nx_bsd_inet_addr        inet_addr
#define nx_bsd_inet_ntoa        inet_ntoa
#define nx_bsd_inet_aton        inet_aton
#define nx_bsd_inet_pton        inet_pton
#define nx_bsd_inet_ntop        inet_ntop
#define nx_bsd_listen           listen
#define nx_bsd_recvfrom         recvfrom
#define nx_bsd_recvfromto       recvfromto
#define nx_bsd_recv             recv
#define nx_bsd_recvmsg          recvmsg
#define nx_bsd_sendto           sendto
#define nx_bsd_send             send
#define nx_bsd_select           select
#define nx_bsd_soc_close        soc_close
#define nx_bsd_socket           socket
#define nx_bsd_fcntl            fcntl
#define nx_bsd_getsockopt       getsockopt
#define nx_bsd_setsockopt       setsockopt
#define nx_bsd_getaddrinfo      getaddrinfo
#define nx_bsd_freeaddrinfo     freeaddrinfo
#define nx_bsd_getnameinfo      getnameinfo
#define nx_bsd_set_errno        set_errno
#define nx_bsd_poll             poll

#define NX_BSD_FD_SET           FD_SET
#define NX_BSD_FD_CLR           FD_CLR
#define NX_BSD_FD_ISSET         FD_ISSET
#define NX_BSD_FD_ZERO          FD_ZERO



#endif

/* For compatibility undefine the fd_set.  Then define the FD set size.  */

#ifdef fd_set
#undef fd_set
#endif

#ifdef   FD_SETSIZE
#undef   FD_SETSIZE                                                                     /* May be different in other header files e.g 64 in GNU types.h file    */
#define  FD_SETSIZE                         (NX_BSD_MAX_SOCKETS + NX_BSD_SOCKFD_START)  /* Number of sockets to select on - same is max sockets!                */
#else
#define  FD_SETSIZE                         (NX_BSD_MAX_SOCKETS + NX_BSD_SOCKFD_START)  /* Number of sockets to select on - same is max sockets!                */
#endif


/* Define some BSD protocol constants.  */

#define SOCK_STREAM                         1                       /* TCP Socket                                                          */
#define SOCK_DGRAM                          2                       /* UDP Socket                                                          */
#define SOCK_RAW                            3                       /* Raw socket                                                          */
#define IPPROTO_ICMP                        1                       /* ICMP used with socket type SOCK_RAW                                 */
#define IPPROTO_IGMP                        2                       /* IGMP used with socket type SOCK_RAW                                 */
#define IPPROTO_TCP                         6                       /* TCP Socket                                                          */
#define IPPROTO_UDP                         17                      /* TCP Socket                                                          */
#define IPPROTO_ICMPV6                      58                      /* ICMPv6 used with socket type SOCK_RAW                               */
#define IPPROTO_RAW                         255                     /* Raw Socket                                                          */

/* Define supported flags for 'send' and 'recv'. */
#define MSG_PEEK                            0x02                    /* Peek incoming message */
#define MSG_DONTWAIT                        0x40                    /* Nonblocking IO        */

/* Address families.  */

#define     AF_UNSPEC                       0                       /* Unspecified.                                                         */
#define     AF_NS                           1                       /* Local to host (pipes, portals).                                      */
#define     AF_INET                         2                       /* IPv4 socket (UDP, TCP, etc)                                          */
#define     AF_INET6                        3                       /* IPv6 socket (UDP, TCP, etc)                                          */
#define     AF_PACKET                       4                       /* Raw Packet type (Link Layer packets)                                 */
#define     AF_MAX                          AF_PACKET

/* Protocol families, same as address families.  */
#define     PF_INET                         AF_INET
#define     PF_INET6                        AF_INET6
#define     PF_PACKET                       AF_PACKET
#define     ETH_P_ALL                       3

#define     INADDR_ANY                      0
#define     NX_BSD_LOCAL_IF_INADDR_ANY      0xFFFFFFFF
/* Define API error codes.  */

#define NX_SOC_ERROR                       -1                       /* Failure.                                                             */
#ifndef ERROR
#define ERROR                               NX_SOC_ERROR
#endif
#define NX_SOC_OK                           0                       /* Success.                                                             */
#ifndef OK
#define OK                                  NX_SOC_OK
#endif
#define NX_BSD_BLOCK_POOL_ERROR             1
#define NX_BSD_MUTEX_ERROR                  2
#define NX_BSD_THREAD_ERROR                 4
#define NX_BSD_EVENT_ERROR                  7
#define NX_BSD_ENVIRONMENT_ERROR            8

#ifndef NX_PACKET_OFFSET_ERROR
#define NX_PACKET_OFFSET_ERROR              0x53
#endif

/* The Netx API does not require Host to Network conversion or vice versa. The following macro's are provided for source compatibility reasons only.  */

#ifndef htons
#define htons(a)                            a
#endif
#ifndef htonl
#define htonl(a)                            a
#endif
#ifndef ntohs
#define ntohs(a)                            a
#endif
#ifndef ntohl
#define ntohl(a)                            a
#endif

/* Define error handling macro.  */

#ifdef NX_BSD_PRINT_ERRORS
#define NX_BSD_ERROR(status, line) printf(" NX BSD debug error message:, NX status: %x source line: %i \n", status, line)
#else
#define NX_BSD_ERROR(status, line)
#endif


/* Define file descriptor operation flags. */

/* Note: FIONREAD is hardware dependant. The default is for i386 processor. */
#ifndef FIONREAD
#define FIONREAD                            0x541B                  /* Read bytes available for the ioctl() command                         */
#endif

#define F_GETFL                             3                       /* Get file descriptors                                                 */
#define F_SETFL                             4                       /* Set a subset of file descriptors (e.g. O_NONBlOCK                    */
#define O_NONBLOCK                          0x4000                  /* Option to enable non blocking on a file (e.g. socket)                */

#ifndef FIONBIO
#define FIONBIO                             0x5421                  /* Enables socket non blocking option for the ioctl() command            */
#endif

#define SIOCGIFINDEX                        0x8933                  /* Get if_index from name  */
#define SIOCGIFHWADDR                       0x8927                  /* Get hardware address    */

/* Define the minimal TCP socket listen backlog value. */
#ifndef NX_BSD_TCP_LISTEN_MIN_BACKLOG
#define NX_BSD_TCP_LISTEN_MIN_BACKLOG   1
#endif

/* Define the maximum number of packets that can be queued on a UDP socket or RAW socket. */
#ifndef NX_BSD_SOCKET_QUEUE_MAX
#define NX_BSD_SOCKET_QUEUE_MAX 5
#endif

/* Define the constants that determine how big the hash table is for raw socket Protocol. The
   value must be a power of two, so subtracting one gives us the mask. */

#ifndef NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE
#define NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE   32
#endif /* NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE */

#define NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_MASK   (NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE-1)

/* Define additional BSD socket errors. */

/* From errno-base.h in /usr/include/asm-generic;  */
#define EPERM        1  /* Operation not permitted */
#define E_MIN        1  /* Minimum Socket/IO error */
#define ENOENT       2  /* No such file or directory */
#define ESRCH        3  /* No such process */
#define EINTR        4  /* Interrupted system call */
#define EIO          5  /* I/O error */
#define ENXIO        6  /* No such device or address */
#define E2BIG        7  /* Argument list too long */
#define ENOEXEC      8  /* Exec format error */
#define EBADF        9  /* Bad file number */
#define ECHILD      10  /* No child processes */
#define EAGAIN      11  /* Try again */
#define ENOMEM      12  /* Out of memory */
#define EACCES      13  /* Permission denied */
#define EFAULT      14  /* Bad address */
#define ENOTBLK     15  /* Block device required */
#define EBUSY       16  /* Device or resource busy */
#define EEXIST      17  /* File exists */
#define EXDEV       18  /* Cross-device link */
#define ENODEV      19  /* No such device */
#define ENOTDIR     20  /* Not a directory */
#define EISDIR      21  /* Is a directory */
#define EINVAL      22  /* Invalid argument */
#define ENFILE      23  /* File table overflow */
#define EMFILE      24  /* Too many open files */
#define ENOTTY      25  /* Not a typewriter */
#define ETXTBSY     26  /* Text file busy */
#define EFBIG       27  /* File too large */
#define ENOSPC      28  /* No space left on device */
#define ESPIPE      29  /* Illegal seek */
#define EROFS       30  /* Read-only file system */
#define EMLINK      31  /* Too many links */
#define EPIPE       32  /* Broken pipe */
#define EDOM        33  /* Math argument out of domain of func */
#define ERANGE      34  /* Math result not representable */

/* From errno.h in /usr/include/asm-generic;   */

#define EDEADLK         35  /* Resource deadlock would occur */
#define ENAMETOOLONG    36  /* File name too long */
#define ENOLCK          37  /* No record locks available */
#define ENOSYS          38  /* Function not implemented */
#define ENOTEMPTY       39  /* Directory not empty */
#define ELOOP           40  /* Too many symbolic links encountered */
#define EWOULDBLOCK     EAGAIN  /* Operation would block */
#define ENOMSG          42  /* No message of desired type */
#define EIDRM           43  /* Identifier removed */
#define ECHRNG          44  /* Channel number out of range */
#define EL2NSYNC        45  /* Level 2 not synchronized */
#define EL3HLT          46  /* Level 3 halted */
#define EL3RST          47  /* Level 3 reset */
#define ELNRNG          48  /* Link number out of range */
#define EUNATCH         49  /* Protocol driver not attached */
#define ENOCSI          50  /* No CSI structure available */
#define EL2HLT          51  /* Level 2 halted */
#define EBADE           52  /* Invalid exchange */
#define EBADR           53  /* Invalid request descriptor */
#define EXFULL          54  /* Exchange full */
#define ENOANO          55  /* No anode */
#define EBADRQC         56  /* Invalid request code */
#define EBADSLT         57  /* Invalid slot */
#define EDEADLOCK       EDEADLK
#define EBFONT          59  /* Bad font file format */
#define ENOSTR          60  /* Device not a stream */
#define ENODATA         61  /* No data available */
#define ETIME           62  /* Timer expired */
#define ENOSR           63  /* Out of streams resources */
#define ENONET          64  /* Machine is not on the network */
#define ENOPKG          65  /* Package not installed */
#define EREMOTE         66  /* Object is remote */
#define ENOLINK         67  /* Link has been severed */
#define EADV            68  /* Advertise error */
#define ESRMNT          69  /* Srmount error */
#define ECOMM           70  /* Communication error on send */
#define EPROTO          71  /* Protocol error */
#define EMULTIHOP       72  /* Multihop attempted */
#define EDOTDOT         73  /* RFS specific error */
#define EBADMSG         74  /* Not a data message */
#define EOVERFLOW       75  /* Value too large for defined data type */
#define ENOTUNIQ        76  /* Name not unique on network */
#define EBADFD          77  /* File descriptor in bad state */
#define EREMCHG         78  /* Remote address changed */
#define ELIBACC         79  /* Can not access a needed shared library */
#define ELIBBAD         80  /* Accessing a corrupted shared library */
#define ELIBSCN         81  /* .lib section in a.out corrupted */
#define ELIBMAX         82  /* Attempting to link in too many shared libraries */
#define ELIBEXEC        83  /* Cannot exec a shared library directly */
#define EILSEQ          84  /* Illegal byte sequence */
#define ERESTART        85  /* Interrupted system call should be restarted */
#define ESTRPIPE        86  /* Streams pipe error */
#define EUSERS          87  /* Too many users */
#define ENOTSOCK        88  /* Socket operation on non-socket */
#define EDESTADDRREQ    89  /* Destination address required */
#define EMSGSIZE        90  /* Message too long */
#define EPROTOTYPE      91  /* Protocol wrong type for socket */
#define ENOPROTOOPT     92  /* Protocol not available */
#define EPROTONOSUPPORT 93  /* Protocol not supported */
#define ESOCKTNOSUPPORT 94  /* Socket type not supported */
#define EOPNOTSUPP      95  /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT    96  /* Protocol family not supported */
#define EAFNOSUPPORT    97  /* Address family not supported by protocol */
#define EADDRINUSE      98  /* Address already in use */
#define EADDRNOTAVAIL   99  /* Cannot assign requested address */
#define ENETDOWN        100 /* Network is down */
#define ENETUNREACH     101 /* Network is unreachable */
#define ENETRESET       102 /* Network dropped connection because of reset */
#define ECONNABORTED    103 /* Software caused connection abort */
#define ECONNRESET      104 /* Connection reset by peer */
#define ENOBUFS         105 /* No buffer space available */
#define EISCONN         106 /* Transport endpoint is already connected */
#define ENOTCONN        107 /* Transport endpoint is not connected */
#define ESHUTDOWN       108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS    109 /* Too many references: cannot splice */
#define ETIMEDOUT       110 /* Connection timed out */
#define ECONNREFUSED    111 /* Connection refused */
#define EHOSTDOWN       112 /* Host is down */
#define EHOSTUNREACH    113 /* No route to host */
#define EALREADY        114 /* Operation already in progress */
#define EINPROGRESS     115 /* Operation now in progress */
#define ESTALE          116 /* Stale NFS file handle */
#define EUCLEAN         117 /* Structure needs cleaning */
#define ENOTNAM         118 /* Not a XENIX named type file */
#define ENAVAIL         119 /* No XENIX semaphores available */
#define EISNAM          120 /* Is a named type file */
#define EREMOTEIO       121 /* Remote I/O error */
#define EDQUOT          122 /* Quota exceeded */
#define ENOMEDIUM       123 /* No medium found */
#define EMEDIUMTYPE     124 /* Wrong medium type */
#define ECANCELED       125 /* Operation Canceled */
#define ENOKEY          126 /* Required key not available */
#define EKEYEXPIRED     127 /* Key has expired */
#define EKEYREVOKED     128 /* Key has been revoked */
#define EKEYREJECTED    129 /* Key was rejected by service */
#define EOWNERDEAD      130 /* Owner died - for robust mutexes*/
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define ERFKILL         132 /* Operation not possible due to RF-kill */


/* List of BSD sock options from socket.h in /usr/include/asm/socket.h and asm-generic/socket.h.
   Note: not all of these are implemented in NetX Duo Extended socket options.

   The first set of socket options take the socket level (category) SOL_SOCKET. */

#define SOL_SOCKET      1   /* Define the socket option category. */
#define IPPROTO_IP      2   /* Define the IP option category.     */
#define SOL_PACKET      3   /* Define the packet option category.     */
#define SO_MIN          1   /* Minimum Socket option ID */
#define SO_DEBUG        1   /* Debugging information is being recorded.*/
#define SO_REUSEADDR    2   /* Enable reuse of local addresses in the time wait state */
#define SO_TYPE         3   /* Socket type */
#define SO_ERROR        4   /* Socket error status */
#define SO_DONTROUTE    5   /* Bypass normal routing */
#define SO_BROADCAST    6   /* Transmission of broadcast messages is supported.*/
#define SO_SNDBUF       7   /* Enable setting trasnmit buffer size */
#define SO_RCVBUF       8   /* Enable setting receive buffer size */
#define SO_KEEPALIVE    9   /* Connections are kept alive with periodic messages */
#define SO_OOBINLINE    10  /* Out-of-band data is transmitted in line */
#define SO_NO_CHECK     11  /* Disable UDP checksum */
#define SO_PRIORITY     12  /* Set the protocol-defined priority for all packets to be sent on this socket */
#define SO_LINGER       13  /* Socket lingers on close pending remaining send/receive packets. */
#define SO_BSDCOMPAT    14  /* Enable BSD bug-to-bug compatibility */
#define SO_REUSEPORT    15  /* Rebind a port already in use */

#ifndef SO_PASSCRED          /* Used for passing credentials. Not currently in use. */
#define SO_PASSCRED     16   /* Enable passing local user credentials  */
#define SO_PEERCRED     17   /* Obtain the process, user and group ids of the other end of the socket connection */
#define SO_RCVLOWAT     18   /* Enable receive "low water mark" */
#define SO_SNDLOWAT     19   /* Enable send "low water mark" */
#define SO_RCVTIMEO     20   /* Enable receive timeout */
#define SO_SNDTIMEO     21   /* Enable send timeout */
#endif  /* SO_PASSCRED */
#define SO_SNDBUFFORCE  22  /* Enable setting trasnmit buffer size overriding user limit (admin privelege) */
#define SO_RCVBUFFORCE  23  /* Enable setting trasnmit buffer size overriding user limit (admin privelege) */
#define SO_MAX          SO_RCVBUFFORCE /* Maximum Socket option ID      */

/*  This second set of socket options take the socket level (category) IPPROTO_IP. */

#define IP_TOS              25 /* Type Of Service */
#define IP_TTL              26 /* Specify the TTL value. */
#define IP_MULTICAST_IF     27 /* Specify outgoing multicast interface */
#define IP_MULTICAST_TTL    28 /* Specify the TTL value to use for outgoing multicast packet. */
#define IP_MULTICAST_LOOP   29 /* Whether or not receive the outgoing multicast packet, loopbacloopbackk mode. */
#define IP_BLOCK_SOURCE     30 /* Block multicast from certain source. */
#define IP_UNBLOCK_SOURCE   31 /* Unblock multicast from certain source. */
#define IP_ADD_MEMBERSHIP   32 /* Join IPv4 multicast membership */
#define IP_DROP_MEMBERSHIP  33 /* Leave IPv4 multicast membership */
#define IP_HDRINCL          34 /* Raw socket IPv4 header included. */
#define IP_RAW_RX_NO_HEADER 35 /* NetX proprietary socket option that does not include
                                  IPv4/IPv6 header (and extension headers) on received raw sockets.*/
#define IP_RAW_IPV6_HDRINCL 36 /* Transmitted buffer over IPv6 socket contains IPv6 header. */
#define IP_OPTION_MAX       IP_RAW_IPV6_HDRINCL

#define PACKET_ADD_MEMBERSHIP  41
#define PACKET_DROP_MEMBERSHIP 42
#define PACKET_OPTION_MAX      PACKET_DROP_MEMBERSHIP

#define PACKET_MR_MULTICAST 1

/*
 * User-settable options (used with setsockopt).
 */
#define TCP_NODELAY 0x01    /* don't delay send to coalesce packets     */
#define TCP_MAXSEG  0x02    /* set maximum segment size                 */
#define TCP_NOPUSH  0x04    /* don't push last block of write           */
#define TCP_NOOPT   0x08    /* don't use TCP options                    */


/* Define data types used in structure timeval.  */

#if defined(__CCRX__) || defined(NX_BSD_ENABLE_NATIVE_API)
typedef LONG        nx_bsd_time_t;
#endif /* __CCRX__ || NX_BSD_ENABLE_NATIVE_API */
typedef LONG        nx_bsd_suseconds_t;

#ifndef __SES_ARM
struct nx_bsd_timeval
{
    nx_bsd_time_t   tv_sec;             /* Seconds      */
    nx_bsd_suseconds_t
                    tv_usec;            /* Microseconds */
};
#endif /* __SES_ARM */

struct nx_bsd_sockaddr_storage
{
    USHORT ss_len;
    USHORT ss_family;
};

struct nx_bsd_sockaddr
{
    USHORT          sa_family;              /* Address family (e.g. , AF_INET).                 */
    UCHAR           sa_data[14];            /* Protocol- specific address information.          */
};

struct nx_bsd_in6_addr
{
    union
    {
        UCHAR _S6_u8[16];
        ULONG _S6_u32[4];
    } _S6_un;
};

#define s6_addr     _S6_un._S6_u8
#define s6_addr32   _S6_un._S6_u32

struct nx_bsd_sockaddr_in6
{
    USHORT          sin6_family;                 /* AF_INET6 */
    USHORT          sin6_port;                   /* Transport layer port.  */
    ULONG           sin6_flowinfo;               /* IPv6 flow information. */
    struct nx_bsd_in6_addr
                    sin6_addr;                   /* IPv6 address. */
    ULONG           sin6_scope_id;               /* set of interafces for a scope. */

};

/* Internet address (a structure for historical reasons).  */

struct nx_bsd_in_addr
{
    ULONG           s_addr;             /* Internet address (32 bits).                         */
};

typedef ULONG       nx_bsd_in_addr_t;
typedef ULONG       nx_bsd_socklen_t;



/* Socket address, Internet style. */

struct nx_bsd_sockaddr_in
{
    USHORT              sin_family;         /* Internet Protocol (AF_INET).                    */
    USHORT              sin_port;           /* Address port (16 bits).                         */
    struct nx_bsd_in_addr
                        sin_addr;           /* Internet address (32 bits).                     */
    CHAR                sin_zero[8];        /* Not used.                                       */
};



typedef struct FD_SET_STRUCT                /* The select socket array manager.                                                             */
{
   INT                  fd_count;           /* How many are SET?                                                                            */
   ULONG                fd_array[(NX_BSD_MAX_SOCKETS + 31)/32]; /* Bit map of SOCKET Descriptors.                                                   */
} nx_bsd_fd_set;



typedef struct NX_BSD_SOCKET_SUSPEND_STRUCT
{
    ULONG               nx_bsd_socket_suspend_actual_flags;
    nx_bsd_fd_set       nx_bsd_socket_suspend_read_request_fd_set;
    nx_bsd_fd_set       nx_bsd_socket_suspend_write_request_fd_set;
    nx_bsd_fd_set       nx_bsd_socket_suspend_exception_request_fd_set;
    nx_bsd_fd_set       nx_bsd_socket_suspend_read_fd_set;
    nx_bsd_fd_set       nx_bsd_socket_suspend_write_fd_set;
    nx_bsd_fd_set       nx_bsd_socket_suspend_exception_fd_set;

} NX_BSD_SOCKET_SUSPEND;


struct nx_bsd_ip_mreq
{
    struct nx_bsd_in_addr
                        imr_multiaddr;     /* The IPv4 multicast address to join. */
    struct nx_bsd_in_addr
                        imr_interface;     /* The interface to use for this group. */
};

#ifdef NX_BSD_RAW_SUPPORT

struct nx_bsd_packet_mreq
{
    INT    mr_ifindex;
    USHORT mr_type;
    USHORT mr_alen;
    UCHAR  mr_address[8];
};

#define ETH_ALEN 6
#define ETHERTYPE_VLAN 0x8100

struct nx_bsd_ether_header
{
    UCHAR ether_dhost[ETH_ALEN];
    UCHAR ether_shost[ETH_ALEN];
    USHORT ether_type;
};

struct nx_bsd_ifreq {
    CHAR ifr_name[NX_BSD_IFNAMSIZE];
    union {
        struct nx_bsd_sockaddr ifru_addr;
        struct nx_bsd_sockaddr ifru_hwaddr;
        SHORT                  ifru_flags;
        INT                    ifru_ivalue;
    } ifr_ifru;
};

#define ifr_hwaddr  ifr_ifru.ifru_hwaddr
#define ifr_ifindex ifr_ifru.ifru_ivalue
#endif



struct nx_bsd_iovec {
    void  *iov_base;
    size_t iov_len;
};

struct nx_bsd_msghdr {
    void                *msg_name;
    nx_bsd_socklen_t     msg_namelen;
    struct nx_bsd_iovec *msg_iov;
    size_t               msg_iovlen;
    void                *msg_control;
    size_t               msg_controllen;
    int                  msg_flags;
};

/* Define additional BSD data structures for supporting socket options.  */

struct nx_bsd_sock_errno
{
    INT error;                              /* default = 0; */
};

struct nx_bsd_linger
{
    INT l_onoff;                            /* 0 = disabled; 1 = enabled; default = 0;*/
    INT l_linger;                           /* linger time in seconds; default = 0;*/
};

struct nx_bsd_sock_keepalive
{
    INT keepalive_enabled;                  /* 0 = disabled; 1 = enabled; default = 0;*/
};

struct nx_bsd_sock_reuseaddr
{
    INT reuseaddr_enabled;                  /* 0 = disabled; 1 = enabled; default = 1; */
};

struct nx_bsd_sock_winsize
{
    INT winsize;                            /* receive window size for TCP sockets   ; */
};

/* Define an union struct for master ID and secondary ID used in NX_BSD_SOCKET_STRUCT. */
union UNION_ID
{
    INT nx_bsd_socket_master_socket_id;
    INT nx_bsd_socket_secondary_socket_id;
};


struct nx_bsd_addrinfo
{
    INT             ai_flags;
    INT             ai_family;
    INT             ai_socktype;
    INT             ai_protocol;
    nx_bsd_socklen_t ai_addrlen;
    struct nx_bsd_sockaddr *ai_addr;
    CHAR            *ai_canonname;
    struct nx_bsd_addrinfo
                    *ai_next;
};

struct NX_BSD_SERVICE_LIST
{
    CHAR    *service_name;
    USHORT  service_port;
    INT     service_socktype;
    INT     service_protocol;
};

/* Define the Errors return by getaddrinfo. */

/* The specified host doesn't have addresses in the specified address family. */
#define EAI_ADDRFAMILY  40
/* Name server temporary failure. */
#define EAI_AGAIN       41
/* hints.si_flags contains invalid flag. */
#define EAI_BADFLAGS    42
/* DNS fail. */
#define EAI_FAIL        43
/* Invalid address family. */
#define EAI_FAMILY      44
/* memory failure. */
#define EAI_MEMORY      45
/* host exsits, but doesn't have address in specified family. */
#define EAI_NODATA      46
#define EAI_NONAME      47
/* service not available for the specified socket type. */
#define EAI_SERVICE     48
#define EAI_OVERFLOW    49
/* invalid socktype. */
#define EAI_SOCKTYPE    50
#define EAI_SYSTEM      51


/* Define ai_flags value. */
#define AI_PASSIVE      0x0001
/* request CNAME. */
#define AI_CANONNAME    0x0002
/* host must be a address string. */
#define AI_NUMERICHOST  0x0004
/* service must be a port string. */
#define AI_NUMERICSERV  0x0008
#define AI_V4MAPPED     0x0010
#define AI_ALL          0x0020
#define AI_ADDRCONFIG   0x0040

/* Return numeric string for hostname. */
#define NI_NUMERICHOST  0x0001
/* Return numeric string for service name. */
#define NI_NUMERICSERV  0x0002
/* Return only hostname portion of FQDN. */
#define NI_NOFQDN       0x0004
/* Return error if name can't be resolved from address. */
#define NI_NAMEREQD     0x0008
/* Datagram service. */
#define NI_DGRAM        0x0010


/* Define the struct used by poll.  */
struct nx_bsd_pollfd
{
    INT     fd;         /* file descriptor. */
    SHORT   events;     /* requested events. */
    SHORT   revents;    /* returned events. */
};

/* Define the options used by poll. */

#define POLLRDNORM  0x0100
#define POLLRDBAND  0x0200          /* Not supported.  */
#define POLLIN      (POLLRDNORM)
#define POLLPRI     0x0400

#define POLLWRNORM  0x0010
#define POLLOUT     (POLLWRNORM)
#define POLLWRBAND  0x0020          /* Not supported.  */

#define POLLERR     0x0001
#define POLLHUP     0x0002
#define POLLNVAL    0x0004


/* Defines maximum IPv4 addresses for getaddrinfo. */
#ifndef NX_BSD_IPV4_ADDR_MAX_NUM
#define NX_BSD_IPV4_ADDR_MAX_NUM 5
#endif /* NX_BSD_IPV4_ADDR_MAX_NUM  */

/* Defines maximum IPv6 addresses for getaddrinfo. */
#ifndef NX_BSD_IPV6_ADDR_MAX_NUM
#define NX_BSD_IPV6_ADDR_MAX_NUM 5
#endif /* NX_BSD_IPV6_ADDR_MAX_NUM  */

/* Defines maximum IPv4 addresses stored from DNS. */
#ifndef NX_BSD_IPV4_ADDR_PER_HOST
#define NX_BSD_IPV4_ADDR_PER_HOST 5
#endif /* NX_BSD_IPV4_ADDR_PER_HOST */

/* Defines maximum IPv6 addresses stored from DNS. */
#ifndef NX_BSD_IPV6_ADDR_PER_HOST
#define NX_BSD_IPV6_ADDR_PER_HOST 2
#endif /* NX_BSD_IPV6_ADDR_PER_HOST */

/* Define the BSD socket status bits. */
#define NX_BSD_SOCKET_CONNECTION_INPROGRESS      1
#define NX_BSD_SOCKET_ERROR                      (1 << 1)
#define NX_BSD_SOCKET_CONNECTED                  (1 << 2)
/* Disconnected from the stack. */
#define NX_BSD_SOCKET_DISCONNECT_FROM_STACK      (1 << 3)
#define NX_BSD_SOCKET_SERVER_MASTER_SOCKET       (1 << 4)
#define NX_BSD_SOCKET_SERVER_SECONDARY_SOCKET    (1 << 5)
#define NX_BSD_SOCKET_TX_HDR_INCLUDE             (1 << 6)
#define NX_BSD_SOCKET_RX_NO_HDR                  (1 << 7)
#define NX_BSD_SOCKET_IN_USE                     (1 << 8)
#define NX_BSD_SOCKET_CLIENT                     (1 << 9)
#define NX_BSD_SOCKET_ENABLE_LISTEN              (1 << 10)
#define NX_BSD_SOCKET_BOUND                      (1 << 11)
#define NX_BSD_SOCKET_ACCEPTING                  (1 << 12)
#define NX_BSD_SOCKET_CONNECTION_REQUEST         (1 << 13)
#define NX_BSD_SOCKET_DISCONNECTION_REQUEST      (1 << 14)

/* Define the BSD socket options bits. */
#define NX_BSD_SOCKET_ENABLE_RAW_SOCKET             1
#define NX_BSD_SOCKET_ENABLE_OPTION_LINGER          (1 << 1)
#define NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR       (1 << 2)
#define NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING    (1 << 3)

/* Define the internal management structure for the BSD layer.  */

typedef struct NX_BSD_SOCKET_STRUCT
{
    NX_TCP_SOCKET       *nx_bsd_socket_tcp_socket;
    NX_UDP_SOCKET       *nx_bsd_socket_udp_socket;
    ULONG               nx_bsd_socket_family;
    /* Store the protocol number.  For example TCP is 6, UDP is 17. For raw socket
       it is the protocol it wishes to receive. */
    USHORT              nx_bsd_socket_protocol;
    TX_THREAD           *nx_bsd_socket_busy;
    union UNION_ID      nx_bsd_socket_union_id;
    NX_PACKET*          nx_bsd_socket_received_packet;
    NX_PACKET*          nx_bsd_socket_received_packet_tail;
    UINT                nx_bsd_socket_received_byte_count;
    UINT                nx_bsd_socket_received_byte_count_max;
    UINT                nx_bsd_socket_received_packet_count;
    UINT                nx_bsd_socket_received_packet_count_max;
    ULONG               nx_bsd_socket_received_packet_offset;
    INT                 nx_bsd_socket_source_port;
    ULONG               nx_bsd_socket_local_bind_interface;
    UINT                nx_bsd_socket_local_bind_interface_index;
    NXD_ADDRESS         nx_bsd_socket_source_ip_address;
    NXD_ADDRESS         nx_bsd_socket_peer_ip;

    /* For TCP/UDP, the local port is the port number this socket receives on.
       For raw socket this field is not used. */
    USHORT              nx_bsd_socket_local_port;
    USHORT              nx_bsd_socket_peer_port;
    INT                 nx_bsd_option_linger_time;
    UINT                nx_bsd_option_linger_time_closed;
    UINT                nx_bsd_option_linger_start_close;
    struct nx_bsd_linger
                        nx_bsd_option_linger;
    UINT                nx_bsd_socket_time_wait_remaining;
    ULONG               nx_bsd_option_receive_timeout;
    ULONG               nx_bsd_option_send_timeout;
    INT                 nx_bsd_file_descriptor_flags;
    ULONG               nx_bsd_socket_status_flags;
    ULONG               nx_bsd_socket_option_flags;
    int                 nx_bsd_socket_error_code;

    struct NX_BSD_SOCKET_STRUCT
                        *nx_bsd_socket_next;
    struct NX_BSD_SOCKET_STRUCT
                        *nx_bsd_socket_previous;

    INT                 nx_bsd_socket_id;
#ifdef NX_BSD_RAW_PPPOE_SUPPORT
    UINT                nx_bsd_socket_create_id;
#endif /* NX_BSD_RAW_PPPOE_SUPPORT */
#if defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT)
    UCHAR               nx_bsd_socket_sll_addr[6];
    USHORT              nx_bsd_socket_sll_protocol;
    INT                 nx_bsd_socket_sll_ifindex;
#endif /* defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) */

} NX_BSD_SOCKET;


/* Define the BSD function prototypes for use by the application.  */


INT  nx_bsd_accept(INT sockID, struct nx_bsd_sockaddr *ClientAddress, INT *addressLength);
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);
INT  nx_bsd_bind(INT sockID, const struct nx_bsd_sockaddr *localAddress, INT addressLength);
INT  nx_bsd_connect(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT addressLength);
INT  nx_bsd_getpeername(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT *addressLength);
INT  nx_bsd_getsockname(INT sockID, struct nx_bsd_sockaddr *localAddress, INT *addressLength);
INT  nx_bsd_ioctl(INT sockID, INT command, INT *result);
nx_bsd_in_addr_t nx_bsd_inet_addr(const CHAR *buffer);
CHAR *nx_bsd_inet_ntoa(struct nx_bsd_in_addr address_to_convert);
INT  nx_bsd_inet_aton(const CHAR *cp_arg, struct nx_bsd_in_addr *addr);
INT  nx_bsd_inet_pton(INT af, const CHAR *src, VOID *dst);
const CHAR *nx_bsd_inet_ntop(INT af, const VOID *src, CHAR *dst, nx_bsd_socklen_t size);
INT  nx_bsd_listen(INT sockID, INT backlog);
#ifdef NX_ENABLE_IP_RAW_PACKET_FILTER
UINT nx_bsd_raw_packet_receive(NX_BSD_SOCKET *bsd_socket_ptr, NX_PACKET **packet_ptr);
UINT nx_bsd_raw_packet_info_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *nxd_address, UINT *interface_index);
VOID nx_bsd_raw_receive_notify(NX_IP *ip_ptr, UINT bsd_socket_index);
#endif
UINT nx_bsd_socket_set_inherited_settings(UINT master_sock_id, UINT secondary_sock_id);
INT  nx_bsd_recvfrom(INT sockID, CHAR *buffer, INT buffersize, INT flags,struct nx_bsd_sockaddr *fromAddr, INT *fromAddrLen);
INT  nx_bsd_recvfromto(INT sockID, CHAR *rcvBuffer, INT bufferLength, INT flags, struct nx_bsd_sockaddr *fromAddr, INT *fromAddrLen, struct nx_bsd_sockaddr *toAddr, INT *toAddrLen);
INT  nx_bsd_recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags);
INT  nx_bsd_recvmsg(INT sockID, struct nx_bsd_msghdr *msg, INT flags);
INT  nx_bsd_sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr *destAddr, INT destAddrLen);
INT  nx_bsd_send(INT sockID, const CHAR *msg, INT msgLength, INT flags);
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);
INT  nx_bsd_soc_close( INT sockID);
INT  nx_bsd_socket(INT protocolFamily, INT type, INT protocol);
INT  nx_bsd_fcntl(INT sock_ID, UINT flag_type, UINT f_options);
INT  nx_bsd_getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length);
INT  nx_bsd_setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length);
INT  nx_bsd_getaddrinfo(const CHAR *node, const CHAR *service, const struct nx_bsd_addrinfo *hints, struct nx_bsd_addrinfo **res);
VOID nx_bsd_freeaddrinfo(struct nx_bsd_addrinfo *res);
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);
VOID nx_bsd_set_service_list(struct NX_BSD_SERVICE_LIST *serv_list_ptr, ULONG serv_list_len);
INT  nx_bsd_poll(struct nx_bsd_pollfd *fds, ULONG nfds, INT timeout);

#if !defined(NX_BSD_ENABLE_NATIVE_API)
#undef FD_SET
#undef FD_CLR
#undef FD_ISSET
#undef FD_ZERO
#endif

VOID NX_BSD_FD_SET(INT fd, nx_bsd_fd_set *fdset);
VOID NX_BSD_FD_CLR(INT fd, nx_bsd_fd_set *fdset);
INT  NX_BSD_FD_ISSET(INT fd, nx_bsd_fd_set *fdset);
VOID NX_BSD_FD_ZERO(nx_bsd_fd_set *fdset);
VOID nx_bsd_set_errno(INT tx_errno);

INT _nxd_get_errno(VOID);

#if !defined(NX_BSD_ENABLE_NATIVE_API)
#define errno (tx_thread_identify() -> bsd_errno)
#else
#define nx_bsd_errno (tx_thread_identify() -> bsd_errno)
#endif


#ifdef NX_BSD_RAW_PPPOE_SUPPORT

#define ETHERTYPE_PPPOE_DISC            0x8863  /* PPPoE Discovery protocol type */
#define ETHERTYPE_PPPOE_SESS            0x8864  /* PPPoE Session Protocol type */

#define NX_LINK_PACKET_PPPOE_SESS_SEND   ETHERTYPE_PPPOE_SESS
#define NX_LINK_PACKET_PPPOE_DISC_SEND   ETHERTYPE_PPPOE_DISC


UINT  _nx_bsd_pppoe_packet_received(NX_PACKET *packet_ptr, UINT frame_type, UINT interface_id);
#endif /* NX_BSD_RAW_PPPOE_SUPPORT */

#if defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT)
/* Link Layer Socket Addressing */
struct nx_bsd_sockaddr_ll
{
    USHORT sll_family;   /* Address Family.  Must be AF_PACKET */
    USHORT sll_protocol; /* LL frame type */
    INT    sll_ifindex;  /* Interface Index. */
    USHORT sll_hatype;   /* Header type */
    UCHAR  sll_pkttype;  /* Packet type */
    UCHAR  sll_halen;    /* Length of address */
    UCHAR  sll_addr[8];  /* Physical layer address */
};
#endif /* defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) */

#ifdef NX_BSD_RAW_SUPPORT
extern UINT _nx_driver_hardware_packet_send(NX_PACKET *packet_ptr);                                 /* Send hardware packet. */
extern VOID (*_nx_driver_hardware_packet_received_callback)(NX_PACKET *packet_ptr, UCHAR *consumed);/* Callback function pointer when packet is received. */
#endif /* NX_BSD_RAW_SUPPORT */


/* Determine if a C++ compiler is being used.  If so, complete the standard
   C conditional started above.  */
#ifdef   __cplusplus
        }
#endif

#endif  /* NXD_BSD_H */