📄 net_ip.c
字号:
NetIP_FragReasmTimeout_tick = tick;
CPU_CRITICAL_EXIT();
return (DEF_OK);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIP_GetAddrThisHost()
*
* Description : Get this host's IP address.
*
* Argument(s) : none.
*
* Return(s) : This host's IP address in host-order.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
NET_IP_ADDR NetIP_GetAddrThisHost (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
NET_IP_ADDR addr;
CPU_CRITICAL_ENTER();
addr = NetIP_AddrThisHost;
CPU_CRITICAL_EXIT();
return (addr);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIP_GetAddrDfltGateway()
*
* Description : Get this host's default gateway IP address.
*
* Argument(s) : none.
*
* Return(s) : This host's default gateway IP address in host-order.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
NET_IP_ADDR NetIP_GetAddrDfltGateway (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
NET_IP_ADDR addr;
CPU_CRITICAL_ENTER();
addr = NetIP_AddrDfltGateway;
CPU_CRITICAL_EXIT();
return (addr);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIP_GetAddrStrThisHost()
*
* Description : Get this host's IP address as an ASCII string.
*
* Argument(s) : paddr Pointer to an ASCII character array that will receive the return ASCII string
* from this function (see Note #1).
*
* Return(s) : Pointer to this host's IP address string, 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) The size of the ASCII character array that will receive the return ASCII string MUST be
* greater than or equal to NET_ASCII_LEN_MAX_ADDR_IP.
*
* See also 'net_ascii.c NetASCII_IP_to_Str() Note #2'.
*********************************************************************************************************
*/
CPU_CHAR *NetIP_GetAddrStrThisHost (CPU_CHAR *paddr)
{
NET_IP_ADDR addr;
NET_ERR err;
addr = NetIP_GetAddrThisHost(); /* Get this host's IP addr. */
NetASCII_IP_to_Str(addr, paddr, DEF_NO, &err); /* Conv IP addr to IP addr str. */
if (err != NET_ASCII_ERR_NONE) { /* On any str err, ... */
*paddr = (CPU_CHAR )0; /* ... rtn NULL addr ... */
return ((CPU_CHAR *)0); /* ... & rtn NULL. */
}
return (paddr);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIP_GetAddrStrDfltGateway()
*
* Description : Get this host's default gateway IP address as an ASCII string.
*
* Argument(s) : paddr Pointer to an ASCII character array that will receive the return ASCII string
* from this function (see Note #1).
*
* Return(s) : Pointer to this host's default gateway IP address string, 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) The size of the ASCII character array that will receive the return ASCII string MUST be
* greater than or equal to NET_ASCII_LEN_MAX_ADDR_IP.
*
* See also 'net_ascii.c NetASCII_IP_to_Str() Note #2'.
*********************************************************************************************************
*/
CPU_CHAR *NetIP_GetAddrStrDfltGateway (CPU_CHAR *paddr)
{
NET_IP_ADDR addr;
NET_ERR err;
addr = NetIP_GetAddrDfltGateway(); /* Get this host's dflt gateway IP addr. */
NetASCII_IP_to_Str(addr, paddr, DEF_NO, &err); /* Conv IP addr to IP addr str. */
if (err != NET_ASCII_ERR_NONE) { /* On any str err, ... */
*paddr = (CPU_CHAR )0; /* ... rtn NULL addr ... */
return ((CPU_CHAR *)0); /* ... & rtn NULL. */
}
return (paddr);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIP_IsValidAddrHost()
*
* Description : (1) Validate an IP host address which MUST NOT be one of the following :
*
* (a) This Host RFC #1122, Section 3.2.1.3.(a)
* (b) Limited Broadcast RFC #1122, Section 3.2.1.3.(c)
* (c) Localhost RFC #1122, Section 3.2.1.3.(g)
* (d) Specified Host RFC #1122, Section 3.2.1.3.(b)
* (e) Directed Broadcast RFC #1122, Section 3.2.1.3.(d)
*
* (2) ONLY validates typical IP host addresses, since 'This Host' & 'Specified Host' IP host
* addresses are ONLY valid during a host's initialization (see Notes #1a & #1d). This
* function CANNOT be used to validate host addresses if any 'This Host' or 'Specified Host'
* host addresses are passed.
*
*
* Argument(s) : addr_host IP host address to validate.
*
* Return(s) : DEF_YES, if IP host address valid.
*
* DEF_NO, otherwise.
*
* Caller(s) : various.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : (3) See 'net_ip.h IP ADDRESS DEFINES Notes #2, #3, & #4' for supported IP addresses.
*********************************************************************************************************
*/
/*$PAGE*/
CPU_BOOLEAN NetIP_IsValidAddrHost (NET_IP_ADDR addr_host)
{
CPU_BOOLEAN valid;
valid = DEF_YES;
/* -------------- VALIDATE HOST ADDR -------------- */
/* Chk invalid 'This Host' (see Note #1a). */
if (addr_host == NET_IP_ADDR_THIS_HOST) {
valid = DEF_NO;
/* Chk invalid limited broadcast (see Note #1b). */
} else if (addr_host == NET_IP_ADDR_BROADCAST) {
valid = DEF_NO;
/* Chk invalid localhost (see Note #1c). */
} else if ((addr_host & NET_IP_ADDR_LOCAL_HOST_MASK) == NET_IP_ADDR_LOCAL_HOST) {
valid = DEF_NO;
} else if ((addr_host & NET_IP_ADDR_CLASS_A_MASK) == NET_IP_ADDR_CLASS_A) {
/* Chk invalid Class-A specified (see Note #1d). */
if ((addr_host & NET_IP_ADDR_CLASS_A_MASK_HOST) ==
(NET_IP_ADDR_THIS_HOST & NET_IP_ADDR_CLASS_A_MASK_HOST)) {
valid = DEF_NO;
}
/* Chk invalid Class-A broadcast (see Note #1e). */
if ((addr_host & NET_IP_ADDR_CLASS_A_MASK_HOST) ==
(NET_IP_ADDR_BROADCAST & NET_IP_ADDR_CLASS_A_MASK_HOST)) {
valid = DEF_NO;
}
} else if ((addr_host & NET_IP_ADDR_CLASS_B_MASK) == NET_IP_ADDR_CLASS_B) {
/* Chk invalid Class-B specified (see Note #1d). */
if ((addr_host & NET_IP_ADDR_CLASS_B_MASK_HOST) ==
(NET_IP_ADDR_THIS_HOST & NET_IP_ADDR_CLASS_B_MASK_HOST)) {
valid = DEF_NO;
}
/* Chk invalid Class-B broadcast (see Note #1e). */
if ((addr_host & NET_IP_ADDR_CLASS_B_MASK_HOST) ==
(NET_IP_ADDR_BROADCAST & NET_IP_ADDR_CLASS_B_MASK_HOST)) {
valid = DEF_NO;
}
} else if ((addr_host & NET_IP_ADDR_CLASS_C_MASK) == NET_IP_ADDR_CLASS_C) {
/* Chk invalid Class-C specified (see Note #1d). */
if ((addr_host & NET_IP_ADDR_CLASS_C_MASK_HOST) ==
(NET_IP_ADDR_THIS_HOST & NET_IP_ADDR_CLASS_C_MASK_HOST)) {
valid = DEF_NO;
}
/* Chk invalid Class-C broadcast (see Note #1e). */
if ((addr_host & NET_IP_ADDR_CLASS_C_MASK_HOST) ==
(NET_IP_ADDR_BROADCAST & NET_IP_ADDR_CLASS_C_MASK_HOST)) {
valid = DEF_NO;
}
} else { /* Invalid addr class (see Note #3). */
valid = DEF_NO;
}
return (valid);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIP_IsValidAddrThisHost()
*
* Description : (1) Validate this host's IP address which MUST NOT be one of the following :
*
* (a) This Host RFC #1122, Section 3.2.1.3.(a)
* (b) Limited Broadcast RFC #1122, Section 3.2.1.3.(c)
* (c) Localhost RFC #1122, Section 3.2.1.3.(g)
* (d) Specified Host RFC #1122, Section 3.2.1.3.(b)
* (e) Directed Broadcast RFC #1122, Section 3.2.1.3.(d)
* (f) Subnet Broadcast RFC #1122, Section 3.2.1.3.(e)
*
* (2) ONLY validates this host's IP address, since 'This Host' & 'Specified Host' IP host
* addresses are ONLY valid during a host's initialization (see Notes #1a & #1d). This
* function CANNOT be used to validate host addresses if any 'This Host' or 'Specified Host'
* host addresses are passed.
*
*
* Argument(s) : addr_host IP host address to validate.
*
* addr_subnet_mask IP subnet mask.
*
* Return(s) : DEF_YES, if this host's IP address valid.
*
* DEF_NO, otherwise.
*
* Caller(s) : NetIP_CfgAddrThisHost().
*
* This function is an INTERNAL network protocol suite function & SHOULD NOT be called by
* application function(s).
*
* Note(s) : (3) See 'net_ip.h IP ADDRESS DEFINES Notes #2, #3, & #4' for supported IP addresses.
*********************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -