Microchip® Advanced Software Framework

ip4_addr.c File Reference

This is the IPv4 address tools implementation.

#include "lwip/opt.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"

Macros

#define in_range(c, lo, up)   ((u8_t)c >= lo && (u8_t)c <= up)
 
#define isdigit(c)   in_range(c, '0', '9')
 
#define islower(c)   in_range(c, 'a', 'z')
 
#define isprint(c)   in_range(c, 0x20, 0x7f)
 
#define isspace(c)   (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
 
#define isxdigit(c)   (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
 

Functions

u8_t ip4_addr_isbroadcast (u32_t addr, const struct netif *netif)
 Determine if an address is a broadcast address on a network interface. More...
 
u8_t ip4_addr_netmask_valid (u32_t netmask)
 Checks if a netmask is valid (starting with ones, then only zeros) More...
 
u32_t ipaddr_addr (const char *cp)
 Ascii internet address interpretation routine. More...
 
int ipaddr_aton (const char *cp, ip_addr_t *addr)
 Check whether "cp" is a valid ascii representation of an Internet address and convert to a binary address. More...
 
char * ipaddr_ntoa (const ip_addr_t *addr)
 Convert numeric IP address into decimal dotted ASCII representation. More...
 
char * ipaddr_ntoa_r (const ip_addr_t *addr, char *buf, int buflen)
 Same as ipaddr_ntoa, but reentrant since a user-supplied buffer is used. More...
 

Variables

const ip_addr_t ip_addr_any = { IPADDR_ANY }
 
const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST }
 

#define in_range (   c,
  lo,
  up 
)    ((u8_t)c >= lo && (u8_t)c <= up)
#define isdigit (   c)    in_range(c, '0', '9')
#define islower (   c)    in_range(c, 'a', 'z')

Referenced by ipaddr_aton().

#define isprint (   c)    in_range(c, 0x20, 0x7f)
#define isspace (   c)    (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')

Referenced by ipaddr_aton().

#define isxdigit (   c)    (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))

Referenced by ipaddr_aton().

u8_t ip4_addr_isbroadcast ( u32_t  addr,
const struct netif netif 
)

Determine if an address is a broadcast address on a network interface.

Parameters
addraddress to be checked
netifthe network interface against which the address is checked
Returns
returns non-zero if the address is a broadcast address

References netif::flags, ip4_addr_get_u32, ip4_addr_set_u32, netif::ip_addr, ip_addr_netcmp, IPADDR_ANY, IPADDR_BROADCAST, NETIF_FLAG_BROADCAST, and netif::netmask.

u8_t ip4_addr_netmask_valid ( u32_t  netmask)

Checks if a netmask is valid (starting with ones, then only zeros)

Parameters
netmaskthe IPv4 netmask to check (in network byte order!)
Returns
1 if the netmask is valid, 0 if it is not

References lwip_htonl.

u32_t ipaddr_addr ( const char *  cp)

Ascii internet address interpretation routine.

The value returned is in network order.

Parameters
cpIP address in ascii representation (e.g. "127.0.0.1")
Returns
ip address in network order

References ip4_addr_get_u32, ipaddr_aton(), and IPADDR_NONE.

int ipaddr_aton ( const char *  cp,
ip_addr_t addr 
)

Check whether "cp" is a valid ascii representation of an Internet address and convert to a binary address.

Returns 1 if the address is valid, 0 if not. This replaces inet_addr, the return value from which cannot distinguish between failure and a local broadcast address.

Parameters
cpIP address in ascii representation (e.g. "127.0.0.1")
addrpointer to which to save the ip address in network order
Returns
1 if cp could be converted to addr, 0 on failure

References htonl, ip4_addr_set_u32, isdigit, islower, isspace, isxdigit, and LWIP_ASSERT.

Referenced by ipaddr_addr().

char* ipaddr_ntoa ( const ip_addr_t addr)

Convert numeric IP address into decimal dotted ASCII representation.

returns ptr to static buffer; not reentrant!

returns ptr to static buffer; not reentrant!

Parameters
addrip address in network order to convert
Returns
pointer to a global static (!) buffer that holds the ASCII representation of addr

References ipaddr_ntoa_r().

char* ipaddr_ntoa_r ( const ip_addr_t addr,
char *  buf,
int  buflen 
)

Same as ipaddr_ntoa, but reentrant since a user-supplied buffer is used.

Parameters
addrip address in network order to convert
buftarget buffer where the string is stored
buflenlength of buf
Returns
either pointer to buf which now holds the ASCII representation of addr or NULL if buf was too small

References ip4_addr_get_u32, and NULL.

Referenced by ipaddr_ntoa().

const ip_addr_t ip_addr_any = { IPADDR_ANY }
const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST }