📄 net_bsd.c
字号:
*
* 0, if socket connection closed (see Note #3b).
*
* -1, otherwise (see Note #3a2A).
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : (1) (a) (1) (A) Datagram-type sockets send & receive all data atomically -- i.e. every single,
* complete datagram sent MUST be received as a single, complete datagram.
* Thus, each call to send data MUST be transmitted in a single, complete datagram.
*
* (B) (1) IEEE Std 1003.1, 2004 Edition, Section 'send() : DESCRIPTION' states that
* "if the message is too long to pass through the underlying protocol, send()
* shall fail and no data shall be transmitted".
*
* (2) Since IP transmit fragmentation is NOT currently supported (see 'net_ip.h
* Note #1e'), if the socket's type is datagram & the requested send data
* length is greater than the socket/transport layer MTU, then NO data is
* sent & NET_SOCK_ERR_INVALID_DATA_SIZE error is returned.
*
* (2) (A) (1) Stream-type sockets send & receive all data octets in one or more non-
* distinct packets. In other words, the application data is NOT bounded
* by any specific packet(s); rather, it is contiguous & sequenced from
* one packet to the next.
*
* (2) Thus, if the socket's type is stream & the socket's send data queue(s) are
* NOT large enough for the send data, the send data queue(s) are maximally
* filled with send data & the remaining data octets are discarded but may be
* re-sent by later application-socket sends.
*
* (3) Therefore, NO stream-type socket send data length should be "too long to
* pass through the underlying protocol" & cause the socket send to "fail ...
* [with] no data ... transmitted" (see Note #1a1B1).
*
* (B) Thus, it is typical -- but NOT absolutely required -- that a single application
* task ONLY send or request to send data to a stream-type socket.
*
* (b) 'data_len' of 0 octets NOT allowed.
*
* See also 'net_sock.c NetSock_TxDataHandler() Note #3'.
*$PAGE*
* (2) Only some socket send flag options are implemented. If other flag options are requested,
* socket send handler function(s) abort & return appropriate error codes so that requested
* flag options are NOT silently ignored.
*
* (3) (a) IEEE Std 1003.1, 2004 Edition, Section 'send() : RETURN VALUE' states that :
*
* (1) "Upon successful completion, send() shall return the number of bytes sent."
*
* (A) Section 'send() : DESCRIPTION' elaborates that "successful completion
* of a call to sendto() does not guarantee delivery of the message".
*
* (B) Thus, applications SHOULD verify the actual returned number of data
* octets transmitted &/or prepared for transmission.
*
* (2) (A) "Otherwise, -1 shall be returned" ...
* (1) Section 'send() : DESCRIPTION' elaborates that "a return value of
* -1 indicates only locally-detected errors".
*
* (B) "and 'errno' set to indicate the error."
*
* (b) ???? Although NO socket send() specification states to return '0' when the socket's
* connection is closed, it seems reasonable to return '0' since it is possible for the
* socket connection to be close()'d or shutdown() by the remote host.
*
* See also 'net_sock.c NetSock_TxDataHandler() Note #6'.
*********************************************************************************************************
*/
#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.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* 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.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* 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) IEEE Std 1003.1, 2004 Edition, Section 'inet_ntoa() : DESCRIPTION' states that
* "inet_ntoa() ... need not be reentrant ... [and] is not required to be thread-safe".
*
* 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)
{
in_addr_t 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 + -