Microchip® Advanced Software Framework

ip4_addr.h File Reference
#include "lwip/opt.h"
#include "lwip/def.h"

Data Structures

struct  ip_addr
 
struct  ip_addr2
 
struct  ip_addr_packed
 

Macros

#define IP4_ADDR(ipaddr, a, b, c, d)
 Set an IP address given by the four byte-parts. More...
 
#define ip4_addr1(ipaddr)   (((u8_t*)(ipaddr))[0])
 
#define ip4_addr1_16(ipaddr)   ((u16_t)ip4_addr1(ipaddr))
 
#define ip4_addr2(ipaddr)   (((u8_t*)(ipaddr))[1])
 
#define ip4_addr2_16(ipaddr)   ((u16_t)ip4_addr2(ipaddr))
 
#define ip4_addr3(ipaddr)   (((u8_t*)(ipaddr))[2])
 
#define ip4_addr3_16(ipaddr)   ((u16_t)ip4_addr3(ipaddr))
 
#define ip4_addr4(ipaddr)   (((u8_t*)(ipaddr))[3])
 
#define ip4_addr4_16(ipaddr)   ((u16_t)ip4_addr4(ipaddr))
 
#define ip4_addr_get_u32(src_ipaddr)   ((src_ipaddr)->addr)
 IPv4 only: get the IP address as an u32_t. More...
 
#define ip4_addr_set_u32(dest_ipaddr, src_u32)   ((dest_ipaddr)->addr = (src_u32))
 IPv4 only: set the IP address given as an u32_t. More...
 
#define IP4ADDR_STRLEN_MAX   16
 
#define IP_ADDR_ANY   ((ip_addr_t *)&ip_addr_any)
 IP_ADDR_ can be used as a fixed IP address for the wildcard and the broadcast address. More...
 
#define IP_ADDR_BROADCAST   ((ip_addr_t *)&ip_addr_broadcast)
 
#define ip_addr_cmp(addr1, addr2)   ((addr1)->addr == (addr2)->addr)
 
#define ip_addr_copy(dest, src)   ((dest).addr = (src).addr)
 Copy IP address - faster than ip_addr_set: no NULL check. More...
 
#define ip_addr_debug_print(debug, ipaddr)
 
#define ip_addr_get_network(target, host, netmask)   ((target)->addr = ((host)->addr) & ((netmask)->addr))
 Get the network address by combining host address with netmask. More...
 
#define ip_addr_isany(addr1)   ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
 
#define ip_addr_isbroadcast(ipaddr, netif)   ip4_addr_isbroadcast((ipaddr)->addr, (netif))
 
#define ip_addr_islinklocal(addr1)   (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
 
#define ip_addr_ismulticast(addr1)   (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
 
#define ip_addr_netcmp(addr1, addr2, mask)
 Determine if two address are on the same network. More...
 
#define ip_addr_netmask_valid(netmask)   ip4_addr_netmask_valid((netmask)->addr)
 
#define ip_addr_set(dest, src)
 Safely copy one IP address to another (src may be NULL) More...
 
#define ip_addr_set_any(ipaddr)   ((ipaddr)->addr = IPADDR_ANY)
 Set address to IPADDR_ANY (no need for htonl()) More...
 
#define ip_addr_set_hton(dest, src)
 Safely copy one IP address to another and change byte order from host- to network-order. More...
 
#define ip_addr_set_loopback(ipaddr)   ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
 Set address to loopback address. More...
 
#define ip_addr_set_zero(ipaddr)   ((ipaddr)->addr = 0)
 Set complete address to zero. More...
 
#define IP_BADCLASS(a)   (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
 
#define IP_CLASSA(a)   ((((u32_t)(a)) & 0x80000000UL) == 0)
 
#define IP_CLASSA_HOST   (0xffffffff & ~IP_CLASSA_NET)
 
#define IP_CLASSA_MAX   128
 
#define IP_CLASSA_NET   0xff000000
 
#define IP_CLASSA_NSHIFT   24
 
#define IP_CLASSB(a)   ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
 
#define IP_CLASSB_HOST   (0xffffffff & ~IP_CLASSB_NET)
 
#define IP_CLASSB_MAX   65536
 
#define IP_CLASSB_NET   0xffff0000
 
#define IP_CLASSB_NSHIFT   16
 
#define IP_CLASSC(a)   ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
 
#define IP_CLASSC_HOST   (0xffffffff & ~IP_CLASSC_NET)
 
#define IP_CLASSC_NET   0xffffff00
 
#define IP_CLASSC_NSHIFT   8
 
#define IP_CLASSD(a)   (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
 
#define IP_CLASSD_HOST   0x0fffffff /* routing needn't know. */
 
#define IP_CLASSD_NET   0xf0000000 /* These ones aren't really */
 
#define IP_CLASSD_NSHIFT   28 /* net and host fields, but */
 
#define IP_EXPERIMENTAL(a)   (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
 
#define IP_LOOPBACKNET   127 /* official! */
 
#define IP_MULTICAST(a)   IP_CLASSD(a)
 
#define ip_ntoa(ipaddr)   ipaddr_ntoa(ipaddr)
 For backwards compatibility. More...
 
#define IPADDR2_COPY(dest, src)   SMEMCPY(dest, src, sizeof(ip_addr_t))
 MEMCPY-like copying of IP addresses where addresses are known to be 16-bit-aligned if the port is correctly configured (so a port could define this to copying 2 u16_t's) - no NULL-pointer-checking needed. More...
 
#define IPADDR_ANY   ((u32_t)0x00000000UL)
 0.0.0.0 More...
 
#define IPADDR_BROADCAST   ((u32_t)0xffffffffUL)
 255.255.255.255 More...
 
#define IPADDR_LOOPBACK   ((u32_t)0x7f000001UL)
 127.0.0.1 More...
 
#define IPADDR_NONE   ((u32_t)0xffffffffUL)
 255.255.255.255 More...
 
#define IPADDR_STRLEN_MAX   IP4ADDR_STRLEN_MAX
 

Typedefs

typedef struct ip_addr_packed ip_addr_p_t
 
typedef typedefPACK_STRUCT_END
struct ip_addr 
ip_addr_t
 ip_addr_t uses a struct for convenience only, so that the same defines can operate both on ip_addr_t as well as on ip_addr_p_t. More...
 

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)
 returns ptr to static buffer; not reentrant! 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
 
const ip_addr_t ip_addr_broadcast
 
PACK_STRUCT_BEGIN struct
ip_addr_packed 
PACK_STRUCT_STRUCT
 

#define IP4_ADDR (   ipaddr,
  a,
  b,
  c,
 
)
Value:
(ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \
((u32_t)((b) & 0xff) << 16) | \
((u32_t)((c) & 0xff) << 8) | \
(u32_t)((d) & 0xff)
uint32_t u32_t
Definition: sam/include/arch/cc.h:48
struct sockaddr_in addr
Definition: common/components/wifi/winc3400/simple_roaming_udp_client_example/main.c:153

Set an IP address given by the four byte-parts.

Referenced by _tiny_ip4_addr(), ethernet_configure_interface(), ip_input(), netif_init(), and wifi_cb().

#define ip4_addr1 (   ipaddr)    (((u8_t*)(ipaddr))[0])
#define ip4_addr1_16 (   ipaddr)    ((u16_t)ip4_addr1(ipaddr))
#define ip4_addr2 (   ipaddr)    (((u8_t*)(ipaddr))[1])
#define ip4_addr2_16 (   ipaddr)    ((u16_t)ip4_addr2(ipaddr))
#define ip4_addr3 (   ipaddr)    (((u8_t*)(ipaddr))[2])
#define ip4_addr3_16 (   ipaddr)    ((u16_t)ip4_addr3(ipaddr))
#define ip4_addr4 (   ipaddr)    (((u8_t*)(ipaddr))[3])
#define ip4_addr4_16 (   ipaddr)    ((u16_t)ip4_addr4(ipaddr))
#define ip4_addr_get_u32 (   src_ipaddr)    ((src_ipaddr)->addr)

IPv4 only: get the IP address as an u32_t.

Referenced by inet_chksum_pseudo(), inet_chksum_pseudo_partial(), ip4_addr_isbroadcast(), ip_input(), ipaddr_addr(), and ipaddr_ntoa_r().

#define ip4_addr_set_u32 (   dest_ipaddr,
  src_u32 
)    ((dest_ipaddr)->addr = (src_u32))

IPv4 only: set the IP address given as an u32_t.

Referenced by ip4_addr_isbroadcast(), and ipaddr_aton().

#define IP4ADDR_STRLEN_MAX   16
#define IP_ADDR_ANY   ((ip_addr_t *)&ip_addr_any)

IP_ADDR_ can be used as a fixed IP address for the wildcard and the broadcast address.

Referenced by httpd_init().

#define IP_ADDR_BROADCAST   ((ip_addr_t *)&ip_addr_broadcast)
#define ip_addr_cmp (   addr1,
  addr2 
)    ((addr1)->addr == (addr2)->addr)

Referenced by ip_input(), and netif_set_ipaddr().

#define ip_addr_copy (   dest,
  src 
)    ((dest).addr = (src).addr)

Copy IP address - faster than ip_addr_set: no NULL check.

Referenced by ip_input().

#define ip_addr_debug_print (   debug,
  ipaddr 
)
Value:
LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, \
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0))
#define ip4_addr4_16(ipaddr)
Definition: ip4_addr.h:229
#define LWIP_DEBUGF(debug, message)
Definition: src/include/lwip/debug.h:95
#define ip4_addr1_16(ipaddr)
Definition: ip4_addr.h:226
#define U16_F
Definition: sam/include/arch/cc.h:53
#define ip4_addr2_16(ipaddr)
Definition: ip4_addr.h:227
#define NULL
Definition: wilc/bsp/include/nm_bsp.h:70
#define ip4_addr3_16(ipaddr)
Definition: ip4_addr.h:228

Referenced by netif_add().

#define ip_addr_get_network (   target,
  host,
  netmask 
)    ((target)->addr = ((host)->addr) & ((netmask)->addr))

Get the network address by combining host address with netmask.

#define ip_addr_isany (   addr1)    ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
#define ip_addr_isbroadcast (   ipaddr,
  netif 
)    ip4_addr_isbroadcast((ipaddr)->addr, (netif))

Referenced by ip_input().

#define ip_addr_islinklocal (   addr1)    (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))

Referenced by netif_set_ipaddr().

#define ip_addr_ismulticast (   addr1)    (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))

Referenced by ip_input().

#define ip_addr_netcmp (   addr1,
  addr2,
  mask 
)
Value:
(((addr1)->addr & \
(mask)->addr) == \
((addr2)->addr & \
(mask)->addr))
struct sockaddr_in addr
Definition: common/components/wifi/winc3400/simple_roaming_udp_client_example/main.c:153

Determine if two address are on the same network.

  • addr1 IP address 1
  • addr2 IP address 2
  • mask network identifier mask
    Returns
    !0 if the network identifiers of both address match

Referenced by ip4_addr_isbroadcast(), and ip_route().

#define ip_addr_netmask_valid (   netmask)    ip4_addr_netmask_valid((netmask)->addr)
#define ip_addr_set (   dest,
  src 
)
Value:
((dest)->addr = \
((src) == NULL ? 0 : \
(src)->addr))
struct sockaddr_in addr
Definition: common/components/wifi/winc3400/simple_roaming_udp_client_example/main.c:153
#define NULL
Definition: wilc/bsp/include/nm_bsp.h:70

Safely copy one IP address to another (src may be NULL)

Referenced by netif_set_gw(), netif_set_ipaddr(), and netif_set_netmask().

#define ip_addr_set_any (   ipaddr)    ((ipaddr)->addr = IPADDR_ANY)

Set address to IPADDR_ANY (no need for htonl())

Referenced by ip_input().

#define ip_addr_set_hton (   dest,
  src 
)
Value:
((dest)->addr = \
((src) == NULL ? 0:\
htonl((src)->addr)))
#define htonl(x)
Definition: src/include/lwip/def.h:79
struct sockaddr_in addr
Definition: common/components/wifi/winc3400/simple_roaming_udp_client_example/main.c:153
#define NULL
Definition: wilc/bsp/include/nm_bsp.h:70

Safely copy one IP address to another and change byte order from host- to network-order.

#define ip_addr_set_loopback (   ipaddr)    ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))

Set address to loopback address.

#define ip_addr_set_zero (   ipaddr)    ((ipaddr)->addr = 0)

Set complete address to zero.

Referenced by netif_add().

#define IP_BADCLASS (   a)    (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
#define IP_CLASSA (   a)    ((((u32_t)(a)) & 0x80000000UL) == 0)
#define IP_CLASSA_HOST   (0xffffffff & ~IP_CLASSA_NET)
#define IP_CLASSA_MAX   128
#define IP_CLASSA_NET   0xff000000
#define IP_CLASSA_NSHIFT   24
#define IP_CLASSB (   a)    ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
#define IP_CLASSB_HOST   (0xffffffff & ~IP_CLASSB_NET)
#define IP_CLASSB_MAX   65536
#define IP_CLASSB_NET   0xffff0000
#define IP_CLASSB_NSHIFT   16
#define IP_CLASSC (   a)    ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
#define IP_CLASSC_HOST   (0xffffffff & ~IP_CLASSC_NET)
#define IP_CLASSC_NET   0xffffff00
#define IP_CLASSC_NSHIFT   8
#define IP_CLASSD (   a)    (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
#define IP_CLASSD_HOST   0x0fffffff /* routing needn't know. */
#define IP_CLASSD_NET   0xf0000000 /* These ones aren't really */
#define IP_CLASSD_NSHIFT   28 /* net and host fields, but */
#define IP_EXPERIMENTAL (   a)    (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
#define IP_LOOPBACKNET   127 /* official! */
#define IP_MULTICAST (   a)    IP_CLASSD(a)
#define ip_ntoa (   ipaddr)    ipaddr_ntoa(ipaddr)

For backwards compatibility.

#define IPADDR2_COPY (   dest,
  src 
)    SMEMCPY(dest, src, sizeof(ip_addr_t))

MEMCPY-like copying of IP addresses where addresses are known to be 16-bit-aligned if the port is correctly configured (so a port could define this to copying 2 u16_t's) - no NULL-pointer-checking needed.

#define IPADDR_ANY   ((u32_t)0x00000000UL)

0.0.0.0

Referenced by ip4_addr_isbroadcast().

#define IPADDR_BROADCAST   ((u32_t)0xffffffffUL)

255.255.255.255

Referenced by ip4_addr_isbroadcast().

#define IPADDR_LOOPBACK   ((u32_t)0x7f000001UL)

127.0.0.1

#define IPADDR_NONE   ((u32_t)0xffffffffUL)

255.255.255.255

Referenced by ipaddr_addr().

#define IPADDR_STRLEN_MAX   IP4ADDR_STRLEN_MAX

typedef struct ip_addr_packed ip_addr_p_t
typedef typedefPACK_STRUCT_END struct ip_addr ip_addr_t

ip_addr_t uses a struct for convenience only, so that the same defines can operate both on ip_addr_t as well as on ip_addr_p_t.

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)

returns ptr to static buffer; not reentrant!

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().

Referenced by iperf_tcp_client_task(), iperf_tcp_send(), iperf_tcp_server(), and iperf_tcp_task().

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
const ip_addr_t ip_addr_broadcast
PACK_STRUCT_BEGIN struct ip_addr2 PACK_STRUCT_STRUCT