diff --git a/addons/BSD/nx_bsd.c b/addons/BSD/nx_bsd.c index 486399b..af61b85 100644 --- a/addons/BSD/nx_bsd.c +++ b/addons/BSD/nx_bsd.c @@ -97,7 +97,7 @@ TX_BLOCK_POOL nx_bsd_addrinfo_block_pool; * 3 blocks for addrinfo) + 1 block for IP adddress = 4 blocks */ static ULONG nx_bsd_addrinfo_pool_memory[NX_BSD_IPV4_ADDR_MAX_NUM * 4 - *(sizeof(struct addrinfo) + sizeof(VOID *)) / sizeof(ULONG)]; + *(sizeof(struct nx_bsd_addrinfo) + sizeof(VOID *)) / sizeof(ULONG)]; #ifdef NX_BSD_ENABLE_DNS @@ -147,7 +147,7 @@ static ULONG _nx_bsd_string_length(CHAR * string); #ifdef NX_BSD_RAW_SUPPORT static INT _nx_bsd_hardware_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, - INT flags, struct sockaddr* destAddr, INT destAddrLen); + INT flags, struct nx_bsd_sockaddr* destAddr, INT destAddrLen); static VOID _nx_bsd_hardware_packet_received(NX_PACKET *packet_ptr, UCHAR *consumed); #endif /* NX_BSD_RAW_SUPPORT */ static VOID _nx_bsd_fast_periodic_timer_entry(ULONG id); @@ -177,7 +177,7 @@ static struct NX_BSD_SERVICE_LIST *_nx_bsd_serv_list_ptr; /* FUNCTION RELEASE */ /* */ /* bsd_initialize PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -227,9 +227,12 @@ static struct NX_BSD_SERVICE_LIST *_nx_bsd_serv_list_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT bsd_initialize(NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, +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) { @@ -259,7 +262,7 @@ ULONG info; } /* Create a block pool for dynamically allocating addrinfo. */ - status = tx_block_pool_create(&nx_bsd_addrinfo_block_pool, "NetX BSD Addrinfo Block Pool", sizeof(struct addrinfo), + status = tx_block_pool_create(&nx_bsd_addrinfo_block_pool, "NetX BSD Addrinfo Block Pool", sizeof(struct nx_bsd_addrinfo), nx_bsd_addrinfo_pool_memory, sizeof(nx_bsd_addrinfo_pool_memory)); /* Determine if the pool was created. */ @@ -636,7 +639,7 @@ VOID nx_bsd_thread_entry(ULONG info) /* FUNCTION RELEASE */ /* */ /* socket PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -681,9 +684,12 @@ VOID nx_bsd_thread_entry(ULONG info) /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT socket(INT protocolFamily, INT type, INT protocol) +INT nx_bsd_socket(INT protocolFamily, INT type, INT protocol) { INT i; @@ -710,7 +716,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -725,7 +731,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error. */ - set_errno(EPROTOTYPE); + nx_bsd_set_errno(EPROTOTYPE); /* Invalid type. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -738,7 +744,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; if((protocolFamily == AF_PACKET) && (type != SOCK_RAW)) { /* Set the socket error. */ - set_errno(EPROTOTYPE); + nx_bsd_set_errno(EPROTOTYPE); /* Invalid type. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -755,7 +761,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Error getting the protection mutex. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -822,7 +828,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* No, set the error status and return. */ /* Set the socket error. */ - set_errno(ENFILE); + nx_bsd_set_errno(ENFILE); /* Release the mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -861,7 +867,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* Clear the allocated internal BSD socket. */ bsd_socket_ptr -> nx_bsd_socket_status_flags &= (ULONG)(~NX_BSD_SOCKET_IN_USE); @@ -913,7 +919,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the allocated socket memory block. */ tx_block_release(socket_memory); @@ -995,7 +1001,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error getting NetX socket memory. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1028,7 +1034,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; else { /* Not a supported socket type. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Invalid type. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1064,7 +1070,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error present, return error code. */ NX_BSD_ERROR(status, __LINE__); @@ -1084,7 +1090,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* connect PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -1141,9 +1147,12 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT connect(INT sockID, struct sockaddr *remoteAddress, INT addressLength) +INT nx_bsd_connect(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT addressLength) { UINT status; NX_TCP_SOCKET *tcp_socket_ptr; @@ -1157,7 +1166,7 @@ ULONG actual_status; { /* Set the socket error. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1175,7 +1184,7 @@ ULONG actual_status; { /* Set the socket error. */ - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1192,7 +1201,7 @@ ULONG actual_status; /* Socket is no longer in use. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1207,7 +1216,7 @@ ULONG actual_status; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -1244,7 +1253,7 @@ ULONG actual_status; /* Release the mutex. */ tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1255,7 +1264,7 @@ ULONG actual_status; /* Check if the remote address family matches the local BSD socket address family. */ if((remoteAddress -> sa_family != bsd_socket_ptr -> nx_bsd_socket_family) || - ((remoteAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct sockaddr_in)))) + ((remoteAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct nx_bsd_sockaddr_in)))) { /* Mismatch! */ @@ -1264,7 +1273,7 @@ ULONG actual_status; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(ERROR); @@ -1280,8 +1289,8 @@ ULONG actual_status; set the IP version. */ /* NetX API expects multi byte values to be in host byte order. Therefore ntohl/s are used to make the conversion. */ - bsd_socket_ptr -> nx_bsd_socket_peer_ip = htonl(((struct sockaddr_in *) remoteAddress ) -> sin_addr.s_addr); - bsd_socket_ptr -> nx_bsd_socket_peer_port = htons(((struct sockaddr_in *) remoteAddress ) -> sin_port); + bsd_socket_ptr -> nx_bsd_socket_peer_ip = htonl(((struct nx_bsd_sockaddr_in *) remoteAddress ) -> sin_addr.s_addr); + bsd_socket_ptr -> nx_bsd_socket_peer_port = htons(((struct nx_bsd_sockaddr_in *) remoteAddress ) -> sin_port); } else @@ -1293,7 +1302,7 @@ ULONG actual_status; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(ERROR); @@ -1376,7 +1385,7 @@ ULONG actual_status; } /* Already connected. */ - set_errno(EISCONN); + nx_bsd_set_errno(EISCONN); tx_mutex_put(nx_bsd_protection_ptr); @@ -1391,7 +1400,7 @@ ULONG actual_status; { - set_errno(EALREADY); + nx_bsd_set_errno(EALREADY); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1413,7 +1422,7 @@ ULONG actual_status; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & ((ULONG)(~NX_BSD_SOCKET_ERROR)); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1505,7 +1514,7 @@ ULONG actual_status; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1598,7 +1607,7 @@ ULONG actual_status; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error. */ - set_errno(EINTR); + nx_bsd_set_errno(EINTR); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1610,7 +1619,7 @@ ULONG actual_status; /* FUNCTION RELEASE */ /* */ /* bind PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -1654,9 +1663,12 @@ ULONG actual_status; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT bind(INT sockID, struct sockaddr *localAddress, INT addressLength) +INT nx_bsd_bind(INT sockID, const struct nx_bsd_sockaddr *localAddress, INT addressLength) { INT local_port = 0; @@ -1673,7 +1685,7 @@ INT address_conflict; { /* Set the socket error. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Error, invalid socket ID. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1685,16 +1697,16 @@ INT address_conflict; { /* Set the socket error if extended socket options enabled. */ - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Error, invalid local address. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - if (((localAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct sockaddr_in)))) + if (((localAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct nx_bsd_sockaddr_in)))) { - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1712,7 +1724,7 @@ INT address_conflict; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -1731,7 +1743,7 @@ INT address_conflict; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1746,7 +1758,7 @@ INT address_conflict; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(bsd_socket_ptr -> nx_bsd_socket_error_code); + nx_bsd_set_errno(bsd_socket_ptr -> nx_bsd_socket_error_code); /* Clear the error code. */ bsd_socket_ptr -> nx_bsd_socket_error_code = 0; @@ -1768,7 +1780,7 @@ INT address_conflict; /* Check the address family. */ if (bsd_socket_ptr -> nx_bsd_socket_family != localAddress -> sa_family) { - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1784,7 +1796,7 @@ INT address_conflict; /* It is. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1804,10 +1816,10 @@ INT address_conflict; INT if_index; /* Pickup the local port. */ - local_port = ntohs(((struct sockaddr_in *) localAddress) -> sin_port); + local_port = ntohs(((struct nx_bsd_sockaddr_in *) localAddress) -> sin_port); /* Pick up the local IP address */ - local_addr = ntohl(((struct sockaddr_in*)localAddress) -> sin_addr.s_addr); + local_addr = ntohl(((struct nx_bsd_sockaddr_in*)localAddress) -> sin_addr.s_addr); if(local_addr == INADDR_ANY) { @@ -1833,7 +1845,7 @@ INT address_conflict; } } #ifdef NX_BSD_RAW_SUPPORT - if ((localAddress -> sa_family == AF_PACKET) && (addressLength == sizeof(struct sockaddr_ll))) + if ((localAddress -> sa_family == AF_PACKET) && (addressLength == sizeof(struct nx_bsd_sockaddr_ll))) { UINT if_index; @@ -1851,7 +1863,7 @@ INT address_conflict; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EADDRNOTAVAIL); + nx_bsd_set_errno(EADDRNOTAVAIL); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -2041,7 +2053,7 @@ INT address_conflict; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EADDRINUSE); + nx_bsd_set_errno(EADDRINUSE); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -2082,7 +2094,7 @@ INT address_conflict; { #ifdef NX_BSD_RAW_SUPPORT - if ((localAddress -> sa_family == AF_PACKET) && (addressLength == sizeof(struct sockaddr_ll))) + if ((localAddress -> sa_family == AF_PACKET) && (addressLength == sizeof(struct nx_bsd_sockaddr_ll))) { /* Bind to link layer address is supported. */ @@ -2094,7 +2106,7 @@ INT address_conflict; /* Unsupported socket type. */ /* Set the socket error. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error, unsuccessful socket bind call. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2149,7 +2161,7 @@ INT address_conflict; /* FUNCTION RELEASE */ /* */ /* listen PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -2194,9 +2206,12 @@ INT address_conflict; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT listen(INT sockID, INT backlog) +INT nx_bsd_listen(INT sockID, INT backlog) { UINT status; @@ -2211,7 +2226,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2229,7 +2244,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -2244,7 +2259,7 @@ INT ret; { /* The underlying protocol is not TCP, therefore it does not support the listen operation. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2259,7 +2274,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2281,7 +2296,7 @@ INT ret; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2307,7 +2322,7 @@ INT ret; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2324,7 +2339,7 @@ INT ret; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2339,7 +2354,7 @@ INT ret; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error code. */ - set_errno(EDESTADDRREQ); + nx_bsd_set_errno(EDESTADDRREQ); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2396,7 +2411,7 @@ INT ret; /* FUNCTION RELEASE */ /* */ /* accept PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -2448,9 +2463,12 @@ INT ret; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT accept(INT sockID, struct sockaddr *ClientAddress, INT *addressLength) +INT nx_bsd_accept(INT sockID, struct nx_bsd_sockaddr *ClientAddress, INT *addressLength) { /* Define the accept function if NetX BSD accept() is not set to asynchronous (on automatic callback). */ @@ -2462,7 +2480,8 @@ INT ret = 0; INT connected = 0; ULONG requested_events; INT secondary_socket_id = 0; -struct sockaddr_in peer4_address; +struct nx_bsd_sockaddr_in + peer4_address; /* Check for valid socket ID. */ @@ -2470,7 +2489,7 @@ struct sockaddr_in peer4_address; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2491,7 +2510,7 @@ struct sockaddr_in peer4_address; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error.*/ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -2506,7 +2525,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2526,7 +2545,7 @@ struct sockaddr_in peer4_address; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2553,7 +2572,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2570,7 +2589,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2588,7 +2607,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2656,7 +2675,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EWOULDBLOCK); + nx_bsd_set_errno(EWOULDBLOCK); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2678,7 +2697,7 @@ struct sockaddr_in peer4_address; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2702,7 +2721,7 @@ struct sockaddr_in peer4_address; bsd_secondary_socket -> nx_bsd_socket_status_flags = bsd_secondary_socket -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2750,11 +2769,11 @@ struct sockaddr_in peer4_address; /* Copy the peer address/port info to the ClientAddress. Truncate if addressLength is smaller than the size of struct sockaddr_in */ - if(*addressLength > (INT)sizeof(struct sockaddr_in)) + if(*addressLength > (INT)sizeof(struct nx_bsd_sockaddr_in)) { - memcpy(ClientAddress, &peer4_address, sizeof(struct sockaddr_in)); /* Use case of memcpy is verified. */ - *addressLength = sizeof(struct sockaddr_in); + memcpy(ClientAddress, &peer4_address, sizeof(struct nx_bsd_sockaddr_in)); /* Use case of memcpy is verified. */ + *addressLength = sizeof(struct nx_bsd_sockaddr_in); } else { @@ -2769,7 +2788,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Make sure this thread is still the owner. */ if (bsd_socket_ptr -> nx_bsd_socket_busy == tx_thread_identify()) @@ -2923,7 +2942,7 @@ ULONG data_sent = (ULONG)msgLength; if(packet_type == 0) { /* Set the socket error. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2955,7 +2974,7 @@ ULONG data_sent = (ULONG)msgLength; { /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -2972,7 +2991,7 @@ ULONG data_sent = (ULONG)msgLength; nx_packet_release(packet_ptr); /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -2991,7 +3010,7 @@ ULONG data_sent = (ULONG)msgLength; nx_packet_release(packet_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error status.*/ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -3006,7 +3025,7 @@ ULONG data_sent = (ULONG)msgLength; nx_packet_release(packet_ptr); /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3086,20 +3105,20 @@ ULONG data_sent = (ULONG)msgLength; { case NX_IP_ADDRESS_ERROR: - set_errno(EDESTADDRREQ); + nx_bsd_set_errno(EDESTADDRREQ); break; case NX_NOT_ENABLED: - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); break; case NX_NOT_CONNECTED: - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); break; case NX_NO_PACKET: case NX_UNDERFLOW: - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); break; case NX_WINDOW_OVERFLOW: @@ -3107,16 +3126,16 @@ ULONG data_sent = (ULONG)msgLength; case NX_TX_QUEUE_DEPTH: if ((bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING) || (flags & MSG_DONTWAIT)) - set_errno( EWOULDBLOCK); + nx_bsd_set_errno( EWOULDBLOCK); else - set_errno(ETIMEDOUT); + nx_bsd_set_errno(ETIMEDOUT); break; default: /* NX_NOT_BOUND */ /* NX_PTR_ERROR */ /* NX_INVALID_PACKET */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; } @@ -3140,7 +3159,7 @@ ULONG data_sent = (ULONG)msgLength; /* FUNCTION RELEASE */ /* */ /* send PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3195,9 +3214,12 @@ ULONG data_sent = (ULONG)msgLength; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT send(INT sockID, const CHAR *msg, INT msgLength, INT flags) +INT nx_bsd_send(INT sockID, const CHAR *msg, INT msgLength, INT flags) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -3208,7 +3230,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3233,7 +3255,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3251,7 +3273,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error */ - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3271,7 +3293,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* sendto PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3325,9 +3347,12 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct sockaddr *destAddr, INT destAddrLen) +INT nx_bsd_sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr *destAddr, INT destAddrLen) { UINT status; NX_BSD_SOCKET *bsd_socket_ptr; @@ -3339,7 +3364,7 @@ USHORT peer_port = 0; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3361,7 +3386,7 @@ USHORT peer_port = 0; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3378,7 +3403,7 @@ USHORT peer_port = 0; { if((bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_CONNECTED) == 0) { - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3413,7 +3438,7 @@ USHORT peer_port = 0; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -3422,7 +3447,7 @@ USHORT peer_port = 0; /* Validate the destination address. */ if(bsd_socket_ptr -> nx_bsd_socket_family != destAddr -> sa_family) { - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3437,7 +3462,7 @@ USHORT peer_port = 0; status = nx_udp_socket_bind(bsd_socket_ptr -> nx_bsd_socket_udp_socket, NX_ANY_PORT, NX_NO_WAIT); if((status != NX_SUCCESS) && (status != NX_ALREADY_BOUND)) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3460,8 +3485,8 @@ USHORT peer_port = 0; { /* This is for an IPv4 packet. */ - peer_ip_address = htonl(((struct sockaddr_in *) destAddr) -> sin_addr.s_addr); - peer_port = htons(((struct sockaddr_in *) destAddr) -> sin_port); + peer_ip_address = htonl(((struct nx_bsd_sockaddr_in *) destAddr) -> sin_addr.s_addr); + peer_port = htons(((struct nx_bsd_sockaddr_in *) destAddr) -> sin_port); /* Local interface ID is set to invalid value, so the send routine needs to find the best interface to send the packet based on destination IP address. */ @@ -3485,7 +3510,7 @@ USHORT peer_port = 0; /* FUNCTION RELEASE */ /* */ /* recv PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3547,9 +3572,12 @@ USHORT peer_port = 0; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags) +INT nx_bsd_recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags) { UINT status; @@ -3570,7 +3598,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3611,7 +3639,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -3631,7 +3659,7 @@ ULONG start_time = nx_bsd_system_clock; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3659,7 +3687,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3707,7 +3735,7 @@ ULONG start_time = nx_bsd_system_clock; } /* Set the socket status (not really an error). */ - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3766,9 +3794,9 @@ ULONG start_time = nx_bsd_system_clock; if ((bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING) || (wait_option == NX_WAIT_FOREVER) || (flags & MSG_DONTWAIT)) - set_errno(EWOULDBLOCK); + nx_bsd_set_errno(EWOULDBLOCK); else - set_errno (EAGAIN); + nx_bsd_set_errno(EAGAIN); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3778,7 +3806,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3793,7 +3821,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -3805,7 +3833,7 @@ ULONG start_time = nx_bsd_system_clock; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3837,7 +3865,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3890,7 +3918,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3961,7 +3989,7 @@ ULONG start_time = nx_bsd_system_clock; /* FUNCTION RELEASE */ /* */ /* recvfrom PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4012,21 +4040,25 @@ ULONG start_time = nx_bsd_system_clock; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT recvfrom(INT sockID, CHAR *rcvBuffer, INT bufferLength, INT flags, struct sockaddr *fromAddr, INT *fromAddrLen) +INT nx_bsd_recvfrom(INT sockID, CHAR *rcvBuffer, INT bufferLength, INT flags, struct nx_bsd_sockaddr *fromAddr, INT *fromAddrLen) { INT bytes_received; NX_BSD_SOCKET *bsd_socket_ptr; -struct sockaddr_in peer4_address; +struct nx_bsd_sockaddr_in + peer4_address; /* Check for a valid socket ID. */ if ((sockID < NX_BSD_SOCKFD_START) || (sockID >= (NX_BSD_SOCKFD_START + NX_BSD_MAX_SOCKETS))) { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -4038,7 +4070,7 @@ struct sockaddr_in peer4_address; /* Socket error checking is done inside recv() call. */ /* Call the equivalent recv() function. */ - bytes_received = recv(sockID, rcvBuffer, bufferLength, flags); + bytes_received = nx_bsd_recv(sockID, rcvBuffer, bufferLength, flags); /* Check for error. */ if (bytes_received < 0) @@ -4076,9 +4108,9 @@ struct sockaddr_in peer4_address; } /* Copy the peer address/port info to the ClientAddress. Truncate if addressLength is smaller than the size of struct sockaddr_in */ - if(*fromAddrLen > (INT)sizeof(struct sockaddr_in)) + if(*fromAddrLen > (INT)sizeof(struct nx_bsd_sockaddr_in)) { - *fromAddrLen = sizeof(struct sockaddr_in); + *fromAddrLen = sizeof(struct nx_bsd_sockaddr_in); } memcpy(fromAddr, &peer4_address, (UINT)(*fromAddrLen)); /* Use case of memcpy is verified. */ } @@ -4087,9 +4119,9 @@ struct sockaddr_in peer4_address; #if defined(NX_BSD_RAW_PPPOE_SUPPORT) || defined(NX_BSD_RAW_SUPPORT) if(bsd_socket_ptr -> nx_bsd_socket_family == AF_PACKET) { - if(*fromAddrLen >= (INT)sizeof(struct sockaddr_ll)) + if(*fromAddrLen >= (INT)sizeof(struct nx_bsd_sockaddr_ll)) { - struct sockaddr_ll *sockaddr = (struct sockaddr_ll*)fromAddr; + struct nx_bsd_sockaddr_ll *sockaddr = (struct nx_bsd_sockaddr_ll*)fromAddr; INT i; sockaddr -> sll_family = AF_PACKET; sockaddr -> sll_protocol = bsd_socket_ptr -> nx_bsd_socket_sll_protocol; @@ -4099,7 +4131,7 @@ struct sockaddr_in peer4_address; sockaddr -> sll_halen = 6; for(i = 0; i < 6; i++) sockaddr -> sll_addr[i] = bsd_socket_ptr -> nx_bsd_socket_sll_addr[i]; - *fromAddrLen = sizeof(struct sockaddr_ll); + *fromAddrLen = sizeof(struct nx_bsd_sockaddr_ll); } } @@ -4111,7 +4143,7 @@ struct sockaddr_in peer4_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error, IPv6 support is not enabled. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -4129,7 +4161,7 @@ struct sockaddr_in peer4_address; /* FUNCTION RELEASE */ /* */ /* soc_close PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4186,9 +4218,12 @@ struct sockaddr_in peer4_address; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT soc_close(INT sockID) +INT nx_bsd_soc_close(INT sockID) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -4206,7 +4241,7 @@ INT delete_socket; { /* Set the socket error. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Error, invalid socket ID. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4242,7 +4277,7 @@ INT delete_socket; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4307,7 +4342,7 @@ INT delete_socket; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4404,7 +4439,7 @@ INT delete_socket; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4540,7 +4575,7 @@ INT delete_socket; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4555,7 +4590,7 @@ INT delete_socket; /* FUNCTION RELEASE */ /* */ /* fcntl PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4594,9 +4629,12 @@ INT delete_socket; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT fcntl(INT sockID, UINT flag_type, UINT f_options) +INT nx_bsd_fcntl(INT sockID, UINT flag_type, UINT f_options) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -4606,7 +4644,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4648,7 +4686,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* Flag_type is not the one we support */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4665,7 +4703,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* ioctl PORTABLE C */ -/* 6.2.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4710,9 +4748,12 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 03-08-2023 Wenhui Xie Modified comment(s), corrected*/ /* the result of FIONREAD, */ /* resulting in version 6.2.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT ioctl(INT sockID, INT command, INT *result) +INT nx_bsd_ioctl(INT sockID, INT command, INT *result) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -4764,7 +4805,7 @@ UINT status; { tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Error, invalid address. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4791,7 +4832,7 @@ UINT status; else { *result += (INT)(bsd_socket_ptr -> nx_bsd_socket_received_byte_count); - } + } } else if (udp_socket_ptr) { @@ -4811,7 +4852,7 @@ UINT status; { tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Error, invalid address. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4857,7 +4898,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* inet_ntoa PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4894,9 +4935,12 @@ UINT status; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -CHAR *inet_ntoa(struct in_addr address_to_convert) +CHAR *nx_bsd_inet_ntoa(struct nx_bsd_in_addr address_to_convert) { UINT status; @@ -5024,7 +5068,7 @@ UINT size; /* FUNCTION RELEASE */ /* */ /* inet_aton PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5062,9 +5106,12 @@ UINT size; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT inet_aton(const CHAR *address_buffer_ptr, struct in_addr *addr) +INT nx_bsd_inet_aton(const CHAR *address_buffer_ptr, struct nx_bsd_in_addr *addr) { ULONG value; INT base = 10, ip_address_index; @@ -5305,7 +5352,7 @@ UINT dot_flag; /* FUNCTION RELEASE */ /* */ /* inet_addr PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5340,15 +5387,18 @@ UINT dot_flag; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -in_addr_t inet_addr(const CHAR *buffer) +nx_bsd_in_addr_t nx_bsd_inet_addr(const CHAR *buffer) { -struct in_addr ip_address; +struct nx_bsd_in_addr ip_address; UINT status; - status = (UINT)inet_aton(buffer, &ip_address); + status = (UINT)nx_bsd_inet_aton(buffer, &ip_address); if (status == 0) { @@ -5364,7 +5414,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* getsockopt PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5404,21 +5454,24 @@ UINT status; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length) +INT nx_bsd_getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length) { TX_INTERRUPT_SAVE_AREA -INT status; -NX_BSD_SOCKET *bsd_socket_ptr; -struct sock_errno *so_errno; -struct sock_keepalive *so_keepalive; -struct sock_reuseaddr *so_reuseaddr; -struct timeval *so_rcvtimeval; -struct sock_winsize *soc_window_size; -ULONG ticks; +INT status; +NX_BSD_SOCKET *bsd_socket_ptr; +struct nx_bsd_sock_errno *so_errno; +struct nx_bsd_sock_keepalive *so_keepalive; +struct nx_bsd_sock_reuseaddr *so_reuseaddr; +struct nx_bsd_timeval *so_rcvtimeval; +struct nx_bsd_sock_winsize *soc_window_size; +ULONG ticks; /* Check for valid socket ID/descriptor. */ @@ -5426,7 +5479,7 @@ ULONG ticks; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -5437,7 +5490,7 @@ ULONG ticks; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5452,7 +5505,7 @@ ULONG ticks; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5467,7 +5520,7 @@ ULONG ticks; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5479,7 +5532,7 @@ ULONG ticks; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5496,7 +5549,7 @@ ULONG ticks; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -5519,13 +5572,13 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_errno = (struct sock_errno *)option_value; + so_errno = (struct nx_bsd_sock_errno *)option_value; TX_DISABLE if(bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_ERROR) @@ -5543,7 +5596,7 @@ ULONG ticks; TX_RESTORE /* Set the actual size of the data returned. */ - *option_length = sizeof(struct sock_errno); + *option_length = sizeof(struct nx_bsd_sock_errno); } @@ -5560,19 +5613,19 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_keepalive = (struct sock_keepalive *)option_value; + so_keepalive = (struct nx_bsd_sock_keepalive *)option_value; #ifndef NX_ENABLE_TCP_KEEPALIVE so_keepalive -> keepalive_enabled = NX_FALSE; #else so_keepalive -> keepalive_enabled = (INT)(bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_keepalive_enabled); #endif /* NX_ENABLE_TCP_KEEPALIVE */ - *option_length = sizeof(struct sock_keepalive); + *option_length = sizeof(struct nx_bsd_sock_keepalive); break; @@ -5584,27 +5637,27 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_rcvtimeval = (struct timeval *)option_value; + so_rcvtimeval = (struct nx_bsd_timeval *)option_value; ticks = bsd_socket_ptr -> nx_bsd_option_receive_timeout; - so_rcvtimeval -> tv_usec = (suseconds_t)(ticks * NX_MICROSECOND_PER_CPU_TICK) % 1000000; - so_rcvtimeval -> tv_sec = (time_t)((ticks * NX_MICROSECOND_PER_CPU_TICK) / 1000000); + so_rcvtimeval -> tv_usec = (nx_bsd_suseconds_t)(ticks * NX_MICROSECOND_PER_CPU_TICK) % 1000000; + so_rcvtimeval -> tv_sec = (nx_bsd_time_t)((ticks * NX_MICROSECOND_PER_CPU_TICK) / 1000000); *option_length = sizeof(so_rcvtimeval); break; case SO_RCVBUF: - soc_window_size = (struct sock_winsize *)option_value; + soc_window_size = (struct nx_bsd_sock_winsize *)option_value; soc_window_size -> winsize = (INT)(bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_rx_window_default); *option_length = sizeof(soc_window_size); @@ -5619,15 +5672,15 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_reuseaddr= (struct sock_reuseaddr *)option_value; + so_reuseaddr= (struct nx_bsd_sock_reuseaddr *)option_value; so_reuseaddr -> reuseaddr_enabled = bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR; - *option_length = sizeof(struct sock_reuseaddr); + *option_length = sizeof(struct nx_bsd_sock_reuseaddr); break; @@ -5640,7 +5693,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5653,7 +5706,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5666,7 +5719,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5681,7 +5734,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Unsupported or unknown option. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5699,7 +5752,7 @@ ULONG ticks; /* FUNCTION RELEASE */ /* */ /* setsockopt PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5738,17 +5791,21 @@ ULONG ticks; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT setsockopt(INT sockID, INT option_level, INT option_name, const 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) { -UINT reuse_enabled; -NX_BSD_SOCKET *bsd_socket_ptr; -ULONG window_size; -ULONG timer_ticks; -struct timeval *time_val; +UINT reuse_enabled; +NX_BSD_SOCKET *bsd_socket_ptr; +ULONG window_size; +ULONG timer_ticks; +struct nx_bsd_timeval *time_val; INT i; -struct ip_mreq *mreq; +struct nx_bsd_ip_mreq + *mreq; UINT mcast_interface; UINT status; @@ -5760,7 +5817,7 @@ UINT status; /* Error, invalid socket ID. */ /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -5773,7 +5830,7 @@ UINT status; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5788,7 +5845,7 @@ UINT status; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5803,18 +5860,33 @@ UINT status; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; } } + else if (option_level == IPPROTO_TCP) + { + + if ((option_name > TCP_NOOPT) || + (option_name < TCP_NODELAY)) + { + /* Error, one or more invalid arguments. */ + + /* Set the socket error if extended socket options enabled. */ + nx_bsd_set_errno(ENOPROTOOPT); + + NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); + return NX_SOC_ERROR; + } + } else { /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5844,7 +5916,7 @@ UINT status; #ifndef NX_ENABLE_TCP_KEEPALIVE /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5854,7 +5926,7 @@ UINT status; /* Update the BSD socket with this attribute. */ bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_keepalive_enabled = - (UINT)(((struct sock_keepalive *)option_value) -> keepalive_enabled); + (UINT)(((struct nx_bsd_sock_keepalive *)option_value) -> keepalive_enabled); if (bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_keepalive_enabled == NX_TRUE) { @@ -5875,7 +5947,7 @@ UINT status; /* Not a TCP socket. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5892,7 +5964,7 @@ UINT status; case SO_SNDTIMEO: - time_val = (struct timeval *)option_value; + time_val = (struct nx_bsd_timeval *)option_value; /* Calculate ticks for the ThreadX Timer. */ timer_ticks = (ULONG)(time_val -> tv_usec)/NX_MICROSECOND_PER_CPU_TICK + (ULONG)(time_val -> tv_sec) * NX_IP_PERIODIC_RATE; @@ -5903,7 +5975,7 @@ UINT status; case SO_RCVTIMEO: - time_val = (struct timeval *)option_value; + time_val = (struct nx_bsd_timeval *)option_value; /* Calculate ticks for the ThreadX Timer. */ timer_ticks = (ULONG)(time_val -> tv_usec)/NX_MICROSECOND_PER_CPU_TICK + (ULONG)(time_val -> tv_sec) * NX_IP_PERIODIC_RATE; @@ -5919,7 +5991,7 @@ UINT status; { /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5927,7 +5999,7 @@ UINT status; } - window_size = (ULONG)(((struct sock_winsize *)option_value) -> winsize); + window_size = (ULONG)(((struct nx_bsd_sock_winsize *)option_value) -> winsize); #ifdef NX_ENABLE_TCP_WINDOW_SCALING @@ -5949,7 +6021,7 @@ UINT status; case SO_REUSEADDR: - reuse_enabled = (UINT)(((struct sock_reuseaddr *)option_value) -> reuseaddr_enabled); + reuse_enabled = (UINT)(((struct nx_bsd_sock_reuseaddr *)option_value) -> reuseaddr_enabled); if(reuse_enabled) bsd_socket_ptr -> nx_bsd_socket_option_flags |= NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR; @@ -5968,11 +6040,11 @@ UINT status; case IP_MULTICAST_TTL: /* Validate the option length. */ - if(option_length != sizeof(UCHAR)) + if(option_length != sizeof(UCHAR) && option_length != sizeof(INT)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5983,7 +6055,7 @@ UINT status; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -5993,13 +6065,33 @@ UINT status; if(bsd_socket_ptr -> nx_bsd_socket_udp_socket == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; } + /* Set the TTL value. */ - bsd_socket_ptr -> nx_bsd_socket_udp_socket -> nx_udp_socket_time_to_live = *(UCHAR*)option_value; + if (option_length == sizeof(UCHAR)) + { + bsd_socket_ptr -> nx_bsd_socket_udp_socket -> nx_udp_socket_time_to_live = *(UCHAR*)option_value; + } + else + { + bsd_socket_ptr -> nx_bsd_socket_udp_socket -> nx_udp_socket_time_to_live = (UCHAR)(*(INT*)option_value); + } + break; + + case IP_MULTICAST_LOOP: + + /* This is not supported yet. */ + + break; + + case IP_MULTICAST_IF: + + /* This is not supported yet. */ + break; @@ -6009,23 +6101,23 @@ UINT status; case IP_DROP_MEMBERSHIP: /* Validate the option length */ - if(option_length != sizeof(struct ip_mreq)) + if(option_length != sizeof(struct nx_bsd_ip_mreq)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; } - mreq = (struct ip_mreq*)option_value; + mreq = (struct nx_bsd_ip_mreq*)option_value; /* Make sure the multicast group address is valid. */ if((mreq -> imr_multiaddr.s_addr & ntohl(NX_IP_CLASS_D_TYPE)) != ntohl(NX_IP_CLASS_D_TYPE)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6035,7 +6127,7 @@ UINT status; if (!(bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_IN_USE)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6045,7 +6137,7 @@ UINT status; if(bsd_socket_ptr -> nx_bsd_socket_udp_socket == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6085,7 +6177,7 @@ UINT status; { /* Did not find a matching interface. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6113,7 +6205,7 @@ UINT status; if(status != NX_SUCCESS) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6125,7 +6217,7 @@ UINT status; default: /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6142,7 +6234,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* getsockname PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6183,12 +6275,15 @@ UINT status; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getsockname(INT sockID, struct sockaddr *localAddress, INT *addressLength) +INT nx_bsd_getsockname(INT sockID, struct nx_bsd_sockaddr *localAddress, INT *addressLength) { -struct sockaddr_in soc_struct; +struct nx_bsd_sockaddr_in soc_struct; UINT status; NX_BSD_SOCKET *bsd_socket_ptr; @@ -6198,7 +6293,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6208,7 +6303,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6229,7 +6324,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6240,7 +6335,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -6270,7 +6365,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; else if(bsd_socket_ptr -> nx_bsd_socket_local_bind_interface == 0) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -6288,9 +6383,9 @@ NX_BSD_SOCKET *bsd_socket_ptr; soc_struct.sin_family = AF_INET; - if((*addressLength) > (INT)sizeof(struct sockaddr_in)) + if((*addressLength) > (INT)sizeof(struct nx_bsd_sockaddr_in)) { - *addressLength = sizeof(struct sockaddr_in); + *addressLength = sizeof(struct nx_bsd_sockaddr_in); } memcpy(localAddress, &soc_struct, (UINT)(*addressLength)); /* Use case of memcpy is verified. */ } @@ -6300,7 +6395,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6322,7 +6417,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* getpeername PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6359,14 +6454,17 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getpeername(INT sockID, struct sockaddr *remoteAddress, INT *addressLength) +INT nx_bsd_getpeername(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT *addressLength) { UINT status; NX_BSD_SOCKET *bsd_socket_ptr; -struct sockaddr_in *soc_struct_ptr = NX_NULL; +struct nx_bsd_sockaddr_in *soc_struct_ptr = NX_NULL; /* Check whether supplied socket ID is valid. */ @@ -6374,7 +6472,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error, invalid socket ID. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6389,7 +6487,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6405,7 +6503,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Error getting the protection mutex. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -6421,7 +6519,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; /* This is an IPv4 only socket. */ /* Now validate the size of remoteAddress structure. */ - if(*addressLength < (INT)sizeof(struct sockaddr_in)) + if(*addressLength < (INT)sizeof(struct nx_bsd_sockaddr_in)) { /* User supplied buffer is too small .*/ @@ -6430,15 +6528,15 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); return(ERROR); } - soc_struct_ptr = (struct sockaddr_in*)remoteAddress; - *addressLength = sizeof(struct sockaddr_in); + soc_struct_ptr = (struct nx_bsd_sockaddr_in*)remoteAddress; + *addressLength = sizeof(struct nx_bsd_sockaddr_in); } else { @@ -6448,7 +6546,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6465,7 +6563,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6491,7 +6589,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6516,7 +6614,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6531,7 +6629,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -6551,7 +6649,7 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; /* FUNCTION RELEASE */ /* */ /* select PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6631,18 +6729,21 @@ struct sockaddr_in *soc_struct_ptr = NX_NULL; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT select(INT nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +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 i; UINT status; NX_BSD_SOCKET_SUSPEND suspend_request; NX_PACKET *packet_ptr; -fd_set readfds_found; -fd_set writefds_found; -fd_set exceptfds_found; +nx_bsd_fd_set readfds_found; +nx_bsd_fd_set writefds_found; +nx_bsd_fd_set exceptfds_found; INT readfds_left; INT writefds_left; INT exceptfds_left; @@ -6657,7 +6758,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6669,7 +6770,7 @@ INT ret; { /* Set the socket error */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6677,9 +6778,9 @@ INT ret; } /* Clear the read and the write selector set. */ - FD_ZERO(&readfds_found); - FD_ZERO(&writefds_found); - FD_ZERO(&exceptfds_found); + NX_BSD_FD_ZERO(&readfds_found); + NX_BSD_FD_ZERO(&writefds_found); + NX_BSD_FD_ZERO(&exceptfds_found); if(readfds) readfds_left = readfds -> fd_count; @@ -6730,7 +6831,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Set the socket error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -6745,7 +6846,7 @@ INT ret; break; /* Is this socket selected for read? */ - if (FD_ISSET((i + NX_BSD_SOCKFD_START), readfds)) + if (NX_BSD_FD_ISSET((i + NX_BSD_SOCKFD_START), readfds)) { /* Yes, decrement the number of read selectors left to search for. */ @@ -6756,7 +6857,7 @@ INT ret; { /* There is; add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } /* Check to see if there is a disconnection request pending. */ @@ -6764,7 +6865,7 @@ INT ret; { /* There is; add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } /* Check to see if there is a receive packet pending. */ @@ -6772,7 +6873,7 @@ INT ret; { /* Therer is; add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } /* Is this a TCP socket? */ else if (nx_bsd_socket_array[i].nx_bsd_socket_tcp_socket) @@ -6797,13 +6898,13 @@ INT ret; { /* Mark the FD set so the application could be notified. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } if(nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_CONNECTED) { - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } } @@ -6828,7 +6929,7 @@ INT ret; nx_bsd_socket_array[i].nx_bsd_socket_received_packet_count++; /* Add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } } @@ -6843,7 +6944,7 @@ INT ret; break; /* Is this socket selected for write? */ - if (FD_ISSET(i + NX_BSD_SOCKFD_START, writefds)) + if (NX_BSD_FD_ISSET(i + NX_BSD_SOCKFD_START, writefds)) { /* Yes, decrement the number of read selectors left to search for. */ @@ -6854,7 +6955,7 @@ INT ret; { /* Yes, add this socket to the write ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); } /* Check to see if there is a connection request pending. */ @@ -6862,14 +6963,14 @@ INT ret; { /* Yes, add this socket to the write ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); } /* Check to see if there is an error.*/ else if (nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_ERROR) { - FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); } } } @@ -6882,7 +6983,7 @@ INT ret; break; /* Is this socket selected for exceptions? */ - if (FD_ISSET(i + NX_BSD_SOCKFD_START, exceptfds)) + if (NX_BSD_FD_ISSET(i + NX_BSD_SOCKFD_START, exceptfds)) { /* Yes, decrement the number of read selectors left to search for. */ @@ -6892,14 +6993,14 @@ INT ret; if (!(nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_IN_USE)) { - FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); } /* Check to see if there is an error.*/ else if(nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_ERROR) { - FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); } } } @@ -6939,17 +7040,17 @@ INT ret; if(readfds) suspend_request.nx_bsd_socket_suspend_read_fd_set = *readfds; else - FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_fd_set); + NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_fd_set); if(writefds) suspend_request.nx_bsd_socket_suspend_write_fd_set = *writefds; else - FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_fd_set); + NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_fd_set); if(exceptfds) suspend_request.nx_bsd_socket_suspend_exception_fd_set = *exceptfds; else - FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_fd_set); + NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_fd_set); /* Temporarily disable preemption. */ tx_thread_preemption_change(current_thread_ptr, 0, &original_threshold); @@ -6975,9 +7076,9 @@ INT ret; /* Determine if the effected sockets are non blocking (zero ticks for the wait option). */ if (ticks == 0) - set_errno(EWOULDBLOCK); + nx_bsd_set_errno(EWOULDBLOCK); else - set_errno(ETIMEDOUT); + nx_bsd_set_errno(ETIMEDOUT); /* Do not handle as an error; just a timeout so return 0. */ return(0); @@ -6987,7 +7088,7 @@ INT ret; /* Actual error. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error getting the protection mutex. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -7446,7 +7547,7 @@ NX_UDP_SOCKET *udp_socket_ptr; /* FUNCTION RELEASE */ /* */ /* FD_SET PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -7479,9 +7580,12 @@ NX_UDP_SOCKET *udp_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID FD_SET(INT fd, fd_set *fdset) +VOID NX_BSD_FD_SET(INT fd, nx_bsd_fd_set *fdset) { UINT index; @@ -7523,7 +7627,7 @@ UINT index; /* FUNCTION RELEASE */ /* */ /* FD_CLR PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -7556,9 +7660,12 @@ UINT index; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID FD_CLR(INT fd, fd_set *fdset) +VOID NX_BSD_FD_CLR(INT fd, nx_bsd_fd_set *fdset) { UINT index; @@ -7637,7 +7744,7 @@ UINT index; /* resulting in version 6.1 */ /* */ /**************************************************************************/ -INT FD_ISSET(INT fd, fd_set *fdset) +INT NX_BSD_FD_ISSET(INT fd, nx_bsd_fd_set *fdset) { UINT index; @@ -7680,7 +7787,7 @@ UINT index; /* FUNCTION RELEASE */ /* */ /* FD_ZERO PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -7712,9 +7819,12 @@ UINT index; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID FD_ZERO(fd_set *fdset) +VOID NX_BSD_FD_ZERO(nx_bsd_fd_set *fdset) { INT i; @@ -8321,7 +8431,7 @@ static UINT nx_bsd_isxdigit(UCHAR c) /* FUNCTION RELEASE */ /* */ /* set_errno PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8355,9 +8465,12 @@ static UINT nx_bsd_isxdigit(UCHAR c) /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID set_errno(INT tx_errno) +VOID nx_bsd_set_errno(INT tx_errno) { TX_INTERRUPT_SAVE_AREA @@ -8439,7 +8552,7 @@ TX_THREAD *current_thread_ptr; /* FUNCTION RELEASE */ /* */ /* nx_bsd_select_wakeup PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8481,12 +8594,15 @@ TX_THREAD *current_thread_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static VOID nx_bsd_select_wakeup(UINT sock_id, UINT fd_sets) { TX_INTERRUPT_SAVE_AREA -fd_set local_fd; +nx_bsd_fd_set local_fd; TX_THREAD *suspended_thread; ULONG suspended_count; ULONG original_suspended_count; @@ -8497,8 +8613,8 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; BSD mutex. */ - FD_ZERO(&local_fd); - FD_SET((INT)sock_id + NX_BSD_SOCKFD_START, &local_fd); + NX_BSD_FD_ZERO(&local_fd); + NX_BSD_FD_SET((INT)sock_id + NX_BSD_SOCKFD_START, &local_fd); /* Disable interrupts temporarily. */ TX_DISABLE @@ -8524,7 +8640,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; suspend_info = (NX_BSD_SOCKET_SUSPEND *) suspended_thread -> tx_thread_additional_suspend_info; /* Now determine if this thread was waiting for this socket. */ - if ((fd_sets & FDSET_READ) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) + if ((fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) { /* Copy the local fd over so that the return shows the receive socket. */ @@ -8536,7 +8652,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; } /* Now determine if this thread was waiting for this socket. */ - if ((fd_sets & FDSET_WRITE) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) + if ((fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) { /* Copy the local fd over so that the return shows the receive socket. */ @@ -8548,7 +8664,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; } /* Now determine if this thread was waiting for this socket. */ - if ((fd_sets & FDSET_EXCEPTION) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) + if ((fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) { /* Copy the local fd over so that the return shows the receive socket. */ @@ -8562,25 +8678,25 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; /* Clear FD that is not set. */ if (suspended_thread -> tx_thread_suspend_info == NX_BSD_RECEIVE_EVENT) { - if (!(fd_sets & FDSET_READ) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) + if (!(fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) { /* Clear read FD. */ - FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set); + NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set); } - if (!(fd_sets & FDSET_WRITE) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) + if (!(fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) { /* Clear write FD. */ - FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set); + NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set); } - if (!(fd_sets & FDSET_EXCEPTION) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) + if (!(fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) { /* Clear exception FD. */ - FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set); + NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set); } } } @@ -8625,7 +8741,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; /* FUNCTION RELEASE */ /* */ /* nx_bsd_set_error_code PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8659,6 +8775,9 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static VOID nx_bsd_set_error_code(NX_BSD_SOCKET *bsd_socket_ptr, UINT status_code) @@ -8667,35 +8786,35 @@ static VOID nx_bsd_set_error_code(NX_BSD_SOCKET *bsd_socket_ptr, UINT status_cod { case NX_NOT_CLOSED: /* TCP connection is not closed state. */ - set_errno(EISCONN); + nx_bsd_set_errno(EISCONN); break; case NX_PTR_ERROR: case NX_INVALID_PORT: /* Invalid arguement. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; case NX_MAX_LISTEN: - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); break; case NX_PORT_UNAVAILABLE: case NX_NO_FREE_PORTS: - set_errno(EADDRNOTAVAIL); + nx_bsd_set_errno(EADDRNOTAVAIL); break; case NX_ALREADY_BOUND: - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; case NX_WAIT_ABORTED: - set_errno(ETIMEDOUT); + nx_bsd_set_errno(ETIMEDOUT); break; case NX_NOT_CONNECTED: /* NX TCP connect service may return NX_NOT_CONNECTED if the timeout is WAIT_FOREVER. */ - set_errno(ECONNREFUSED); + nx_bsd_set_errno(ECONNREFUSED); break; case NX_IN_PROGRESS: @@ -8704,25 +8823,25 @@ static VOID nx_bsd_set_error_code(NX_BSD_SOCKET *bsd_socket_ptr, UINT status_cod if (bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING) { bsd_socket_ptr -> nx_bsd_socket_status_flags |= NX_BSD_SOCKET_CONNECTION_INPROGRESS; - set_errno(EINPROGRESS); + nx_bsd_set_errno(EINPROGRESS); } else - set_errno(EINTR); + nx_bsd_set_errno(EINTR); break; case NX_INVALID_INTERFACE: case NX_IP_ADDRESS_ERROR: - set_errno(ENETUNREACH); + nx_bsd_set_errno(ENETUNREACH); break; case NX_NOT_ENABLED: - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); break; case NX_NOT_BOUND: case NX_DUPLICATE_LISTEN: default: - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; } @@ -9048,7 +9167,7 @@ NX_INTERFACE *interface_ptr; /* FUNCTION RELEASE */ /* */ /* nx_bsd_tcp_create_listen_socket PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9086,6 +9205,9 @@ NX_INTERFACE *interface_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static INT nx_bsd_tcp_create_listen_socket(INT master_sockid, INT backlog) @@ -9154,7 +9276,7 @@ INT secondary_sockID = NX_BSD_MAX_SOCKETS; /* Error, invalid backlog. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -9163,14 +9285,14 @@ INT secondary_sockID = NX_BSD_MAX_SOCKETS; } /* Now create a dedicated secondary socket to listen for next client connection. */ - secondary_sockID = socket((INT)(master_socket_ptr -> nx_bsd_socket_family), SOCK_STREAM, IPPROTO_TCP); + secondary_sockID = nx_bsd_socket((INT)(master_socket_ptr -> nx_bsd_socket_family), SOCK_STREAM, IPPROTO_TCP); /* Determine if there was an error. */ if (secondary_sockID == NX_SOC_ERROR) { /* Secondary socket create failed. Note: The socket thread error is set in socket(). */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -9438,10 +9560,11 @@ UINT ret; /* resulting in version 6.1 */ /* */ /**************************************************************************/ -static INT _nx_bsd_hardware_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, INT flags, struct sockaddr* destAddr, INT destAddrLen) +static INT _nx_bsd_hardware_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr* destAddr, INT destAddrLen) { UINT if_index; -struct sockaddr_ll *destAddr_ll; +struct nx_bsd_sockaddr_ll + *destAddr_ll; UINT status; NX_PACKET *packet_ptr = NX_NULL; @@ -9452,7 +9575,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(destAddr == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -9461,29 +9584,29 @@ NX_PACKET *packet_ptr = NX_NULL; if(destAddr -> sa_family != AF_PACKET) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - if(destAddrLen != sizeof(struct sockaddr_ll)) + if(destAddrLen != sizeof(struct nx_bsd_sockaddr_ll)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - destAddr_ll = (struct sockaddr_ll*)destAddr; + destAddr_ll = (struct nx_bsd_sockaddr_ll*)destAddr; /* Validate the interface ID */ if_index = (UINT)(destAddr_ll -> sll_ifindex); if(if_index >= NX_MAX_IP_INTERFACES) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -9492,7 +9615,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(nx_bsd_default_ip -> nx_ip_interface[if_index].nx_interface_valid == 0) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -9502,7 +9625,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(msgLength > (INT)(nx_bsd_default_ip -> nx_ip_interface[if_index].nx_interface_ip_mtu_size + 18)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -9515,7 +9638,7 @@ NX_PACKET *packet_ptr = NX_NULL; { /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -9535,7 +9658,7 @@ NX_PACKET *packet_ptr = NX_NULL; nx_packet_release(packet_ptr); /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -9553,7 +9676,7 @@ NX_PACKET *packet_ptr = NX_NULL; nx_packet_release(packet_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -9684,7 +9807,7 @@ NX_BSD_SOCKET *bsd_ptr; /* FUNCTION RELEASE */ /* */ /* inet_pton PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9723,17 +9846,20 @@ NX_BSD_SOCKET *bsd_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT inet_pton(INT af, const CHAR *src, VOID *dst) +INT nx_bsd_inet_pton(INT af, const CHAR *src, VOID *dst) { -struct in_addr ipv4_addr; +struct nx_bsd_in_addr ipv4_addr; if(af == AF_INET) { /* Convert IPv4 address from presentation to numeric. */ - if(inet_aton(src, &ipv4_addr)) + if(nx_bsd_inet_aton(src, &ipv4_addr)) { /* Copy the IPv4 address to the destination. */ *((ULONG *)dst) = ipv4_addr.s_addr; @@ -9753,7 +9879,7 @@ struct in_addr ipv4_addr; /* FUNCTION RELEASE */ /* */ /* inet_ntop PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9792,9 +9918,12 @@ struct in_addr ipv4_addr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -const CHAR *inet_ntop(INT af, const VOID *src, CHAR *dst, socklen_t size) +const CHAR *nx_bsd_inet_ntop(INT af, const VOID *src, CHAR *dst, nx_bsd_socklen_t size) { @@ -9936,7 +10065,7 @@ UINT index = 0; /* FUNCTION RELEASE */ /* */ /* getaddrinfo PORTABLE C */ -/* 6.1.12 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9998,9 +10127,12 @@ UINT index = 0; /* 07-29-2022 Yuxin Zhou Modified comment(s), and */ /* fixed compiler warnings, */ /* resulting in version 6.1.12 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getaddrinfo(const CHAR *node, const CHAR *service, const struct addrinfo *hints, struct addrinfo **res) +INT nx_bsd_getaddrinfo(const CHAR *node, const CHAR *service, const struct nx_bsd_addrinfo *hints, struct nx_bsd_addrinfo **res) { UINT status; @@ -10012,14 +10144,18 @@ UINT ipv4_addr_count = 0; UINT match_service_count; UINT match_service_socktype[3]; UINT match_service_protocol[3]; -struct addrinfo *addrinfo_cur_ptr = NX_NULL; -struct addrinfo *addrinfo_head_ptr = NX_NULL; -struct addrinfo *addrinfo_tail_ptr = NX_NULL; -struct sockaddr *sockaddr_ptr = NX_NULL; +struct nx_bsd_addrinfo + *addrinfo_cur_ptr = NX_NULL; +struct nx_bsd_addrinfo + *addrinfo_head_ptr = NX_NULL; +struct nx_bsd_addrinfo + *addrinfo_tail_ptr = NX_NULL; +struct nx_bsd_sockaddr + *sockaddr_ptr = NX_NULL; UCHAR *cname_buffer = NX_NULL; /* When hints is a null pointer, use the default value below. */ -static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, NX_NULL}; +static struct nx_bsd_addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, NX_NULL}; @@ -10180,7 +10316,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Convert node from a string presentation to a numeric address. */ - if(inet_pton(addr_family, node, &(nx_bsd_ipv4_addr_buffer[0])) == 1) + if(nx_bsd_inet_pton(addr_family, node, &(nx_bsd_ipv4_addr_buffer[0])) == 1) { /* pton has successful completion. */ pton_flag = 1; @@ -10211,7 +10347,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, if (status != TX_SUCCESS) { /* Set the error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* Error getting NetX socket memory. */ NX_BSD_ERROR(NX_BSD_BLOCK_POOL_ERROR, __LINE__); @@ -10352,11 +10488,11 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Set the error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* If head is not null, free the memory. */ if(addrinfo_head_ptr) - freeaddrinfo(addrinfo_head_ptr); + nx_bsd_freeaddrinfo(addrinfo_head_ptr); #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES if(hints -> ai_flags & AI_CANONNAME) @@ -10371,17 +10507,17 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, } /* Clear the memory. */ - memset((VOID*)sockaddr_ptr, 0, sizeof(struct addrinfo)); + memset((VOID*)sockaddr_ptr, 0, sizeof(struct nx_bsd_addrinfo)); if(i < ipv4_addr_count) { /* Process IPv4 address. */ - ((struct sockaddr_in*)sockaddr_ptr) -> sin_family = AF_INET; - ((struct sockaddr_in*)sockaddr_ptr) -> sin_port = (USHORT)port; - ((struct sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr = nx_bsd_ipv4_addr_buffer[i]; + ((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_family = AF_INET; + ((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_port = (USHORT)port; + ((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr = nx_bsd_ipv4_addr_buffer[i]; - NX_CHANGE_ULONG_ENDIAN(((struct sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr); + NX_CHANGE_ULONG_ENDIAN(((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr); } for(j = 0; j < match_service_count; j++) @@ -10395,11 +10531,11 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Set the error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* If head is not null, free the memory. */ if(addrinfo_head_ptr) - freeaddrinfo(addrinfo_head_ptr); + nx_bsd_freeaddrinfo(addrinfo_head_ptr); tx_block_release((VOID *)sockaddr_ptr); @@ -10416,14 +10552,14 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, } /* Clear the socket memory. */ - memset((VOID*)addrinfo_cur_ptr, 0, sizeof(struct addrinfo)); + memset((VOID*)addrinfo_cur_ptr, 0, sizeof(struct nx_bsd_addrinfo)); if(i < ipv4_addr_count) { /* IPv4 */ addrinfo_cur_ptr -> ai_family = AF_INET; - addrinfo_cur_ptr -> ai_addrlen = sizeof(struct sockaddr_in); + addrinfo_cur_ptr -> ai_addrlen = sizeof(struct nx_bsd_sockaddr_in); } addrinfo_cur_ptr -> ai_socktype = (INT)(match_service_socktype[j]); @@ -10456,7 +10592,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, /* FUNCTION RELEASE */ /* */ /* freeaddrinfo PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -10488,13 +10624,16 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID freeaddrinfo(struct addrinfo *res) +VOID nx_bsd_freeaddrinfo(struct nx_bsd_addrinfo *res) { -struct addrinfo *next_addrinfo; -struct sockaddr *ai_addr_ptr = NX_NULL; +struct nx_bsd_addrinfo *next_addrinfo; +struct nx_bsd_sockaddr *ai_addr_ptr = NX_NULL; #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES CHAR *ai_canonname_ptr = NX_NULL; #endif @@ -10599,7 +10738,7 @@ static INT bsd_string_to_number(const CHAR *string, UINT *number) /* FUNCTION RELEASE */ /* */ /* getnameinfo PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -10641,9 +10780,12 @@ static INT bsd_string_to_number(const CHAR *string, UINT *number) /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) +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) { UINT i = 0; @@ -10669,7 +10811,7 @@ const CHAR *rt_ptr; /* sa isn't NULL, but family type is invalid. */ return EAI_FAMILY; } - else if(sa -> sa_family == AF_INET && salen != sizeof(struct sockaddr_in)) + else if(sa -> sa_family == AF_INET && salen != sizeof(struct nx_bsd_sockaddr_in)) { /* Address length is invalid. */ @@ -10760,7 +10902,7 @@ const CHAR *rt_ptr; { /* Get host name by IPv4 address via DNS. */ - status = nx_dns_host_by_address_get(_nx_dns_instance_ptr, ntohl(((struct sockaddr_in *)sa) -> sin_addr.s_addr), + status = nx_dns_host_by_address_get(_nx_dns_instance_ptr, ntohl(((struct nx_bsd_sockaddr_in *)sa) -> sin_addr.s_addr), (UCHAR *)host, hostlen, NX_BSD_TIMEOUT); } else @@ -10794,7 +10936,7 @@ const CHAR *rt_ptr; { /* Host must be numeric string. Convert IP address from numeric to presentation. */ - rt_ptr = inet_ntop(AF_INET, &((struct sockaddr_in*)sa) -> sin_addr, (CHAR *)host, hostlen); + rt_ptr = nx_bsd_inet_ntop(AF_INET, &((struct nx_bsd_sockaddr_in*)sa) -> sin_addr, (CHAR *)host, hostlen); if(!rt_ptr) return EAI_OVERFLOW; @@ -10956,3 +11098,195 @@ static VOID _nx_bsd_fast_periodic_timer_entry(ULONG id) /* Call default IP fast periodic timer entry. */ nx_bsd_ip_fast_periodic_timer_entry(id); } + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* poll PORTABLE C */ +/* 6.x */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function allows for list of sockets to be checked for incoming */ +/* events. */ +/* */ +/* Before invoked, each item inside fds array should be initialized, */ +/* pollfd::fd must be the descriptor ID to check and pollfd::events */ +/* must be the events (bits) to check. */ +/* */ +/* Returned, the pollfd::revents of each item is updated, to indicate */ +/* if the checked events happen. */ +/* */ +/* The event (bit) currently supported: */ +/* - POLLIN : checking socket read FD */ +/* - POLLOUT: checking socket write FD */ +/* - POLLPRI: checking socket exception FD */ +/* */ +/* NOTE: ****** When select returns NX_SOC_ERROR it won't update */ +/* the fds descriptor. */ +/* */ +/* INPUT */ +/* */ +/* fds Socket descriptor list to poll */ +/* and report actual status */ +/* nfds Number of socket descriptors */ +/* timeOut Timeout in microseconds, set */ +/* to below 0 to wait infinitely */ +/* */ +/* OUTPUT */ +/* */ +/* NX_SUCCESS Descriptors check ends */ +/* (successful completion) */ +/* NX_SOC_ERROR (-1) Error occured */ +/* */ +/* CALLS */ +/* */ +/* FD_ZERO Clear a socket ready list */ +/* FD_ISSET Check a socket is ready */ +/* FD_SET Set a socket */ +/* select Perform checks, see select() */ +/* set_errno Set the error code */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* */ +/**************************************************************************/ +INT nx_bsd_poll(struct nx_bsd_pollfd *fds, ULONG nfds, INT timeout) +{ +nx_bsd_fd_set read_fds; +nx_bsd_fd_set write_fds; +nx_bsd_fd_set except_fds; +struct nx_bsd_timeval stime; +struct nx_bsd_timeval *ptime; +INT n_ready_fds; +INT max_fd; +ULONG i; +struct nx_bsd_pollfd *poll_fd; + + /* Check input parameter. */ + if (fds == NX_NULL) + { + nx_bsd_set_errno(EFAULT); + return(NX_SOC_ERROR); + } + if (nfds == 0) + { + nx_bsd_set_errno(EFAULT); + return(NX_SOC_ERROR); + } + + /* Initialize local FDs. */ + NX_BSD_FD_ZERO(&read_fds); + NX_BSD_FD_ZERO(&write_fds); + NX_BSD_FD_ZERO(&except_fds); + + /* Map the poll() FD to select() FDs. */ + max_fd = 0; + for(i = 0; i < nfds; i ++) + { + poll_fd = &fds[i]; + + /* Skip bad FDs. */ + if (poll_fd -> fd < 0) + continue; + + /* POLLIN. */ + if (poll_fd -> events & POLLIN) + { + NX_BSD_FD_SET(poll_fd -> fd, &read_fds); + } + + /* POLLOUT. */ + if (poll_fd -> events & POLLOUT) + { + NX_BSD_FD_SET(poll_fd -> fd, &write_fds); + } + + /* POLLPRI. */ + if (poll_fd -> events & POLLPRI) + { + NX_BSD_FD_SET(poll_fd -> fd, &except_fds); + } + + /* Update max FD. */ + if (poll_fd -> fd > max_fd) + max_fd = poll_fd -> fd; + } + + /* Map the select() timeout. */ + if (timeout < 0) + { + + /* select() wait infinitely. */ + ptime = NX_NULL; + } + else + { + + /* select() uses timeval option. */ + ptime = &stime; + + if (timeout == 0) + { + + /* select() no wait. */ + ptime -> tv_sec = 0; + ptime -> tv_usec = 0; + } + else + { + + /* select() wait specific time in ms. */ + ptime -> tv_sec = (timeout / 1000); + ptime -> tv_usec = (timeout % 1000); + } + + } + + /* Invoke select(). */ + n_ready_fds = nx_bsd_select(max_fd + 1, &read_fds, &write_fds, &except_fds, ptime); + + /* Parse result events if FDs updated. */ + if (n_ready_fds) + { + + for (i = 0; i < nfds; i ++) + { + poll_fd = &fds[i]; + + /* Skip bad FDs. */ + if (poll_fd -> fd < 0) + continue; + + /* Exceptions. */ + if (NX_BSD_FD_ISSET(poll_fd -> fd, &except_fds)) + poll_fd -> revents |= POLLPRI; + + else + { + + /* Inputs. */ + if (NX_BSD_FD_ISSET(poll_fd -> fd, &read_fds)) + poll_fd -> revents |= POLLIN; + } + + /* Outputs. */ + if (NX_BSD_FD_ISSET(poll_fd -> fd, &write_fds)) + poll_fd -> revents |= POLLOUT; + } + } + + return(n_ready_fds); +} diff --git a/addons/BSD/nx_bsd.h b/addons/BSD/nx_bsd.h index e521fc6..d518104 100644 --- a/addons/BSD/nx_bsd.h +++ b/addons/BSD/nx_bsd.h @@ -11,33 +11,33 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** NetX Component */ /** */ -/** BSD 4.3 Socket API Compatible Interface to NetX */ +/** NetX Component */ +/** */ +/** BSD 4.3 Socket API Compatible Interface to NetX */ /** */ /** */ /**************************************************************************/ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* BSD DEFINITIONS RELEASE */ -/* */ -/* nx_bsd.h PORTABLE C */ -/* 6.1.5 */ +/**************************************************************************/ +/* */ +/* BSD DEFINITIONS RELEASE */ +/* */ +/* nx_bsd.h PORTABLE C */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ -/* DESCRIPTION */ -/* */ -/* This file defines the constants, structures, etc... needed to */ +/* DESCRIPTION */ +/* */ +/* This file defines the constants, structures, etc... needed to */ /* implement the BSD 4.3 Socket API Compatible Interface to NetX. */ -/* */ -/* */ -/* RELEASE HISTORY */ -/* */ +/* */ +/* */ +/* RELEASE HISTORY */ +/* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ @@ -46,6 +46,10 @@ /* 03-02-2021 Yuxin Zhou Modified comment(s), and */ /* fixed compiler warnings, */ /* resulting in version 6.1.5 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* added option to enable */ +/* native APIs with prefix, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -70,7 +74,7 @@ extern "C" { #include "nx_api.h" -/* Define the print error macro for reporting source line number. +/* Define the print error macro for reporting source line number. #define NX_BSD_PRINT_ERRORS */ @@ -93,8 +97,8 @@ extern "C" { */ -/* - Define the BSD socket timeout process to execute in the timer context. +/* + 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. @@ -111,62 +115,157 @@ extern "C" { * 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. + 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 +#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! */ +#endif /* NOTE: Must be multiple of 32! */ #ifndef NX_BSD_MAX_LISTEN_BACKLOG -#define NX_BSD_MAX_LISTEN_BACKLOG 5 /* Maximum 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. */ +#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) +#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. */ +#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 /* Define configurable options for BSD extended options. */ - -#ifndef NX_BSD_TIMER_RATE + +#ifndef NX_BSD_TIMER_RATE #define NX_BSD_TIMER_RATE (1 * NX_IP_PERIODIC_RATE) /* Rate at which BSD timer runs. */ -#endif +#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_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_recv recv +#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 @@ -251,7 +350,7 @@ extern "C" { #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) +#define NX_BSD_ERROR(status, line) #endif @@ -277,7 +376,7 @@ extern "C" { #endif /* Define the maximum number of packets that can be queued on a UDP socket socket. */ -#ifndef NX_BSD_SOCKET_QUEUE_MAX +#ifndef NX_BSD_SOCKET_QUEUE_MAX #define NX_BSD_SOCKET_QUEUE_MAX 5 #endif @@ -424,7 +523,7 @@ extern "C" { /* 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 Extended socket options. + Note: not all of these are implemented in NetX Extended socket options. The first set of socket options take the socket level (category) SOL_SOCKET. */ @@ -486,26 +585,27 @@ extern "C" { /* Define data types used in structure timeval. */ -#ifdef __CCRX__ -typedef LONG time_t; -#endif /* __CCRX__ */ -typedef LONG suseconds_t; +#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 timeval +struct nx_bsd_timeval { - time_t tv_sec; /* Seconds */ - suseconds_t tv_usec; /* Microseconds */ + nx_bsd_time_t tv_sec; /* Seconds */ + nx_bsd_suseconds_t + tv_usec; /* Microseconds */ }; #endif /* __SES_ARM */ -struct sockaddr_storage +struct nx_bsd_sockaddr_storage { USHORT ss_len; USHORT ss_family; }; -struct sockaddr +struct nx_bsd_sockaddr { USHORT sa_family; /* Address family (e.g. , AF_INET). */ UCHAR sa_data[14]; /* Protocol- specific address information. */ @@ -514,77 +614,80 @@ struct sockaddr /* Internet address (a structure for historical reasons). */ -struct in_addr +struct nx_bsd_in_addr { - ULONG s_addr; /* Internet address (32 bits). */ + ULONG s_addr; /* Internet address (32 bits). */ }; -typedef ULONG in_addr_t; -typedef ULONG socklen_t; +typedef ULONG nx_bsd_in_addr_t; +typedef ULONG nx_bsd_socklen_t; + - /* Socket address, Internet style. */ -struct sockaddr_in +struct nx_bsd_sockaddr_in { USHORT sin_family; /* Internet Protocol (AF_INET). */ USHORT sin_port; /* Address port (16 bits). */ - struct in_addr sin_addr; /* Internet address (32 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. */ -} fd_set; +} nx_bsd_fd_set; typedef struct NX_BSD_SOCKET_SUSPEND_STRUCT { ULONG nx_bsd_socket_suspend_actual_flags; - fd_set nx_bsd_socket_suspend_read_fd_set; - fd_set nx_bsd_socket_suspend_write_fd_set; - fd_set nx_bsd_socket_suspend_exception_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 ip_mreq +struct nx_bsd_ip_mreq { - struct in_addr imr_multiaddr; /* The IPv4 multicast address to join. */ - struct in_addr imr_interface; /* The interface to use for this group. */ + 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. */ }; /* Define additional BSD data structures for supporting socket options. */ -struct sock_errno +struct nx_bsd_sock_errno { INT error; /* default = 0; */ }; -struct linger +struct nx_bsd_linger { INT l_onoff; /* 0 = disabled; 1 = enabled; default = 0;*/ INT l_linger; /* linger time in seconds; default = 0;*/ }; -struct sock_keepalive +struct nx_bsd_sock_keepalive { INT keepalive_enabled; /* 0 = disabled; 1 = enabled; default = 0;*/ }; -struct sock_reuseaddr +struct nx_bsd_sock_reuseaddr { INT reuseaddr_enabled; /* 0 = disabled; 1 = enabled; default = 1; */ }; -struct sock_winsize +struct nx_bsd_sock_winsize { INT winsize; /* receive window size for TCP sockets ; */ }; @@ -597,16 +700,17 @@ union UNION_ID }; -struct addrinfo +struct nx_bsd_addrinfo { INT ai_flags; INT ai_family; INT ai_socktype; INT ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; + nx_bsd_socklen_t ai_addrlen; + struct nx_bsd_sockaddr *ai_addr; CHAR *ai_canonname; - struct addrinfo *ai_next; + struct nx_bsd_addrinfo + *ai_next; }; struct NX_BSD_SERVICE_LIST @@ -620,7 +724,7 @@ struct NX_BSD_SERVICE_LIST /* Define the Errors return by getaddrinfo. */ /* The specified host doesn't have addresses in the specified address family. */ -#define EAI_ADDRFAMILY 40 +#define EAI_ADDRFAMILY 40 /* Name server temporary failure. */ #define EAI_AGAIN 41 /* hints.si_flags contains invalid flag. */ @@ -643,7 +747,7 @@ struct NX_BSD_SERVICE_LIST /* Define ai_flags value. */ -#define AI_PASSIVE 0x0001 +#define AI_PASSIVE 0x0001 /* request CNAME. */ #define AI_CANONNAME 0x0002 /* host must be a address string. */ @@ -655,7 +759,7 @@ struct NX_BSD_SERVICE_LIST #define AI_ADDRCONFIG 0x0040 /* Return numeric string for hostname. */ -#define NI_NUMERICHOST 0x0001 +#define NI_NUMERICHOST 0x0001 /* Return numeric string for service name. */ #define NI_NUMERICSERV 0x0002 /* Return only hostname portion of FQDN. */ @@ -666,8 +770,32 @@ struct NX_BSD_SERVICE_LIST #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 +#ifndef NX_BSD_IPV4_ADDR_MAX_NUM #define NX_BSD_IPV4_ADDR_MAX_NUM 5 #endif /* NX_BSD_IPV4_ADDR_MAX_NUM */ @@ -683,7 +811,7 @@ struct NX_BSD_SERVICE_LIST #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_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) @@ -701,7 +829,7 @@ struct NX_BSD_SERVICE_LIST #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. */ +/* Define the internal management structure for the BSD layer. */ typedef struct NX_BSD_SOCKET_STRUCT { @@ -729,19 +857,19 @@ typedef struct NX_BSD_SOCKET_STRUCT 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; + UINT nx_bsd_option_linger_time_closed; + UINT nx_bsd_option_linger_start_close; UINT nx_bsd_socket_time_wait_remaining; - ULONG nx_bsd_option_receive_timeout; - ULONG nx_bsd_option_send_timeout; + 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 + struct NX_BSD_SOCKET_STRUCT *nx_bsd_socket_next; - struct NX_BSD_SOCKET_STRUCT + struct NX_BSD_SOCKET_STRUCT *nx_bsd_socket_previous; INT nx_bsd_socket_id; @@ -756,52 +884,63 @@ typedef struct NX_BSD_SOCKET_STRUCT /* Define the BSD function prototypes for use by the application. */ -INT accept(INT sockID, struct sockaddr *ClientAddress, INT *addressLength); -INT 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 bind(INT sockID, struct sockaddr *localAddress, INT addressLength); -INT connect(INT sockID, struct sockaddr *remoteAddress, INT addressLength); -INT getpeername(INT sockID, struct sockaddr *remoteAddress, INT *addressLength); -INT getsockname(INT sockID, struct sockaddr *localAddress, INT *addressLength); -INT ioctl(INT sockID, INT command, INT *result); -in_addr_t inet_addr(const CHAR *buffer); -CHAR *inet_ntoa(struct in_addr address_to_convert); -INT inet_aton(const CHAR *cp_arg, struct in_addr *addr); -INT inet_pton(INT af, const CHAR *src, VOID *dst); -const CHAR *inet_ntop(INT af, const VOID *src, CHAR *dst, socklen_t size); -INT listen(INT sockID, INT backlog); -UINT nx_bsd_socket_set_inherited_settings(UINT master_sock_id, UINT secondary_sock_id); -INT recvfrom(INT sockID, CHAR *buffer, INT buffersize, INT flags,struct sockaddr *fromAddr, INT *fromAddrLen); -INT recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags); -INT sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct sockaddr *destAddr, INT destAddrLen); -INT send(INT sockID, const CHAR *msg, INT msgLength, INT flags); -INT select(INT nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -INT soc_close( INT sockID); -INT socket(INT protocolFamily, INT type, INT protocol); -INT fcntl(INT sock_ID, UINT flag_type, UINT f_options); -INT getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length); -INT setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length); -INT getaddrinfo(const CHAR *node, const CHAR *service, const struct addrinfo *hints, struct addrinfo **res); -VOID freeaddrinfo(struct addrinfo *res); -INT getnameinfo(const struct sockaddr *sa, 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_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); +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_recv(INT sockID, VOID *rcvBuffer, INT bufferLength, 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 _nx_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 -VOID FD_SET(INT fd, fd_set *fdset); -VOID FD_CLR(INT fd, fd_set *fdset); -INT FD_ISSET(INT fd, fd_set *fdset); -VOID FD_ZERO(fd_set *fdset); -VOID set_errno(INT tx_errno); -int _nx_get_errno(VOID); -#define errno (_nx_get_errno()) #if defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) /* Link Layer Socket Addressing */ -struct sockaddr_ll +struct nx_bsd_sockaddr_ll { USHORT sll_family; /* Address Family. Must be AF_PACKET */ USHORT sll_protocol; /* LL frame type */