📄 net_bsd.c
字号:
*
* -1, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) (a) (1) Datagram-type sockets transmit & receive all data atomically -- i.e. every
* single, complete datagram transmitted MUST be received as a single, complete
* datagram. Thus, each call to transmit data MUST be transmitted in a single,
* complete datagram.
*
* (2) Since IP transmit fragmentation is NOT currently supported (see 'net_ip.h
* Note #1e'), if the socket's type is datagram & the requested transmit data
* length is greater than MTU, then the maximum number of octets up to MTU is
* transmitted but the remaining data octets are silently discarded & NO error
* is returned.
*
* (b) 'size' of 0 octets allowed.
*
* (2) Only some sendto() flag options are implemented. If other flag options are requested,
* sendto() returns an error so that flag options are NOT silently ignored.
*
* (3) (a) Socket address structure 'Family' member MUST be configured in host-order & MUST
* NOT be converted to/from network-order.
*
* (b) Socket address structure addresses MUST be configured/converted from host-order
* to network-order.
*
* See also 'net_sock.h NETWORK SOCKET ADDRESS DATA TYPES Note #2'.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
int sendto ( int sock_id,
void *p_data,
int data_len,
int flags,
struct sockaddr *paddr_remote,
int addr_len)
{
int rtn_code;
NET_ERR err;
rtn_code = (int)NetSock_TxDataTo((NET_SOCK_ID ) sock_id,
(void *) p_data,
(CPU_INT16S ) data_len,
(CPU_INT16S ) flags,
(NET_SOCK_ADDR *) paddr_remote,
(NET_SOCK_ADDR_LEN) addr_len,
(NET_ERR *)&err);
return (rtn_code);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* send()
*
* Description : Send data through a socket.
*
* Argument(s) : sock_id Socket descriptor/handle identifier of socket to send data.
*
* p_data Pointer to application/socket data to send.
*
* data_len Length of application/socket data (in octets) [see Note #1].
*
* flags Flags to select send options (see Note #2); bit-field flags logically OR'd :
*
* 0 No socket flags selected.
* MSG_DONTWAIT Send socket data without blocking.
*
* Return(s) : Number of data octets sent, if NO errors.
*
* -1, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) (a) (1) Datagram-type sockets transmit & receive all data atomically -- i.e. every
* single, complete datagram transmitted MUST be received as a single, complete
* datagram. Thus, each call to transmit data MUST be transmitted in a single,
* complete datagram.
*
* (2) Since IP transmit fragmentation is NOT currently supported (see 'net_ip.h
* Note #1e'), if the socket's type is datagram & the requested transmit data
* length is greater than MTU, then the maximum number of octets up to MTU is
* transmitted but the remaining data octets are silently discarded & NO error
* is returned.
*
* (b) 'size' of 0 octets allowed.
*
* (2) Only some send() flag options are implemented. If other flag options are requested,
* send() returns an error so that flag options are NOT silently ignored.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
int send (int sock_id,
void *p_data,
int data_len,
int flags)
{
int rtn_code;
NET_ERR err;
rtn_code = (int)NetSock_TxData((NET_SOCK_ID ) sock_id,
(void *) p_data,
(CPU_INT16S ) data_len,
(CPU_INT16S ) flags,
(NET_ERR *)&err);
return (rtn_code);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* inet_addr()
*
* Description : Convert an IPv4 address in ASCII dotted-decimal notation to a network protocol IPv4 address
* in network-order.
*
* Argument(s) : paddr Pointer to an ASCII string that contains a dotted-decimal IPv4 address (see Note #2).
*
* Return(s) : Network-order IPv4 address represented by ASCII string, if NO errors.
*
* -1, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) RFC #1983 states that "dotted decimal notation ... refers [to] IP addresses of the
* form A.B.C.D; where each letter represents, in decimal, one byte of a four byte IP
* address".
*
* In other words, the dotted-decimal notation separates four decimal octet values by
* the dot, or period, character ('.'). Each decimal value represents one octet of
* the IP address starting with the most significant octet in network order.
*
* IP Address Examples :
*
* DOTTED DECIMAL NOTATION HEXADECIMAL EQUIVALENT
*
* 127.0.0.1 = 0x7F000001
* 192.168.1.64 = 0xC0A80140
* 255.255.255.0 = 0xFFFFFF00
* --- - -- --
* ^ ^ ^ ^
* | | | |
* MSO LSO MSO LSO
*
* where
*
* MSO Most Significant Octet in Dotted Decimal IP Address
* LSO Least Significant Octet in Dotted Decimal IP Address
*
* (2) The dotted-decimal ASCII string MUST :
*
* (a) Include ONLY decimal values & the dot, or period, character ('.') ; ALL other
* characters trapped as invalid, including any leading or trailing characters.
*
* (b) (1) Include EXACTLY four decimal values ...
* (2) ... separated ...
* (3) ... by EXACTLY three dot characters.
*
* (c) Ensure that each decimal value does NOT exceed the maximum octet value (i.e. 255).
*
* (d) Ensure that each decimal value does NOT include leading zeros.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
#if (NET_SOCK_CFG_FAMILY == NET_SOCK_FAMILY_IP_V4)
in_addr_t inet_addr (char *paddr)
{
in_addr_t addr;
NET_ERR err;
addr = (in_addr_t)NetASCII_Str_to_IP((CPU_CHAR *) paddr,
(NET_ERR *)&err);
if (err != NET_ASCII_ERR_NONE) {
addr = (in_addr_t)NET_BSD_ERR_DFLT;
}
addr = NET_UTIL_HOST_TO_NET_32(addr);
return (addr);
}
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* inet_ntoa()
*
* Description : Convert a network protocol IPv4 address into a dotted-decimal notation ASCII string.
*
* Argument(s) : addr IPv4 address.
*
* Return(s) : Pointer to ASCII string of converted IPv4 address (see Note #2), if NO errors.
*
* Pointer to NULL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) RFC #1983 states that "dotted decimal notation ... refers [to] IP addresses of the
* form A.B.C.D; where each letter represents, in decimal, one byte of a four byte IP
* address".
*
* In other words, the dotted-decimal notation separates four decimal octet values by
* the dot, or period, character ('.'). Each decimal value represents one octet of
* the IP address starting with the most significant octet in network order.
*
* IP Address Examples :
*
* DOTTED DECIMAL NOTATION HEXADECIMAL EQUIVALENT
*
* 127.0.0.1 = 0x7F000001
* 192.168.1.64 = 0xC0A80140
* 255.255.255.0 = 0xFFFFFF00
* --- - -- --
* ^ ^ ^ ^
* | | | |
* MSO LSO MSO LSO
*
* where
*
* MSO Most Significant Octet in Dotted Decimal IP Address
* LSO Least Significant Octet in Dotted Decimal IP Address
*
* (2) Since the character string is returned in a single, global character string array,
* this conversion function is NOT re-entrant.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
#if (NET_SOCK_CFG_FAMILY == NET_SOCK_FAMILY_IP_V4)
char *inet_ntoa (struct in_addr addr)
{
NET_IP_ADDR addr_ip;
NET_ERR err;
addr_ip = addr.s_addr;
addr_ip = NET_UTIL_NET_TO_HOST_32(addr_ip);
NetASCII_IP_to_Str((NET_IP_ADDR) addr_ip,
(CPU_CHAR *)&NetBSD_IP_to_Str_Array[0],
(CPU_BOOLEAN) DEF_NO,
(NET_ERR *)&err);
if (err != NET_ASCII_ERR_NONE) {
return ((char *)0);
}
return ((char *)&NetBSD_IP_to_Str_Array[0]);
}
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* STANDARD BSD 4.x FUNCTIONS END
*
* Note(s) : (1) See 'STANDARD BSD 4.x FUNCTIONS Note #1'.
*********************************************************************************************************
*/
#endif /* End of BSD fncts (see Note #1). */
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'MODULE Note #1' & 'net_bsd.h MODULE Note #1'.
*********************************************************************************************************
*/
#endif /* End of BSD module include (see Note #1). */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -