Loading...
Searching...
No Matches
ip4_addr.h File Reference
`#include "lwip/opt.h"`
`#include "lwip/def.h"`

## Data Structures

struct | ip4_addr

## Macros

#define | IPADDR_NONE ((u32_t)0xffffffffUL)
#define | IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
#define | IPADDR_ANY ((u32_t)0x00000000UL)
#define | IPADDR_BROADCAST ((u32_t)0xffffffffUL)
#define | IP4_ADDR(ipaddr, a, b, c, d)
#define | ip4_addr_copy(dest, src)
#define | ip4_addr_set(dest, src)
#define | ip4_addr_set_zero(ipaddr)
#define | ip4_addr_set_any(ipaddr)
#define | ip4_addr_set_loopback(ipaddr)
#define | ip4_addr_isloopback(ipaddr)
#define | ip4_addr_set_hton(dest, src)
#define | ip4_addr_set_u32(dest_ipaddr, src_u32)
#define | ip4_addr_get_u32(src_ipaddr)
#define | ip4_addr_get_network(target, host, netmask)
#define | ip4_addr_netcmp(addr1, addr2, mask)
#define | ip4_addr_net_eq(addr1, addr2, mask)
#define | ip4_addr_cmp(addr1, addr2)
#define | ip_ntoa(ipaddr)

## Typedefs

typedef struct ip4_addr | ip4_addr_t

## Functions

u8_t | ip4_addr_isbroadcast_u32 (u32_t addr, const struct netif *netif)
u8_t | ip4_addr_netmask_valid (u32_t netmask)
u32_t | ipaddr_addr (const char *cp)
int | ip4addr_aton (const char *cp, ip4_addr_t *addr)
char * | ip4addr_ntoa (const ip4_addr_t *addr)
char * | ip4addr_ntoa_r (const ip4_addr_t *addr, char *buf, int buflen)

## Detailed Description

IPv4 address API

## Macro Definition Documentation

## IP4_ADDR

#define IP4_ADDR | ( |  | ipaddr,
|  |  | a,
|  |  | b,
|  |  | c,
|  |  | d )

Value:
(ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
LWIP_MAKEU32
#define LWIP_MAKEU32(a, b, c, d)
Definition def.h:72

Set an IP address given by the four byte-parts

## ip4_addr_cmp

#define ip4_addr_cmp | ( |  | addr1,
|  |  | addr2 )

Value:
ip4_addr_eq(addr1, addr2)

Deprecated
  Renamed to ip4_addr_eq

## ip4_addr_copy

#define ip4_addr_copy | ( |  | dest,
|  |  | src )

Value:
((dest).addr = (src).addr)

Copy IP address - faster than ip4_addr_set: no NULL check

## ip4_addr_get_network

#define ip4_addr_get_network | ( |  | target,
|  |  | host,
|  |  | netmask )

Value:
do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)

Get the network address by combining host address with netmask

## ip4_addr_get_u32

#define ip4_addr_get_u32 | ( |  | src_ipaddr | ) |

Value:
((src_ipaddr)->addr)

IPv4 only: get the IP address as an u32_t

## ip4_addr_isloopback

#define ip4_addr_isloopback | ( |  | ipaddr | ) |

Value:
(((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))

Check if an address is in the loopback region

## ip4_addr_net_eq

#define ip4_addr_net_eq | ( |  | addr1,
|  |  | addr2,
|  |  | mask )

Value:
(((addr1)->addr & \
(mask)->addr) == \
((addr2)->addr & \
(mask)->addr))

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

## ip4_addr_netcmp

#define ip4_addr_netcmp | ( |  | addr1,
|  |  | addr2,
|  |  | mask )

Value:
ip4_addr_net_eq(addr1, addr2, mask)
ip4_addr_net_eq
#define ip4_addr_net_eq(addr1, addr2, mask)
Definition ip4_addr.h:146

Determine if two address are on the same network.

Deprecated
  Renamed to ip4_addr_net_eq

## ip4_addr_set

#define ip4_addr_set | ( |  | dest,
|  |  | src )

Value:
((dest)->addr = \
((src) == NULL ? 0 : \
(src)->addr))

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

## ip4_addr_set_any

#define ip4_addr_set_any | ( |  | ipaddr | ) |

Value:
((ipaddr)->addr = IPADDR_ANY)
IPADDR_ANY
#define IPADDR_ANY
Definition ip4_addr.h:67

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

## ip4_addr_set_hton

#define ip4_addr_set_hton | ( |  | dest,
|  |  | src )

Value:
((dest)->addr = \
((src) == NULL ? 0:\
lwip_htonl((src)->addr)))

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

## ip4_addr_set_loopback

#define ip4_addr_set_loopback | ( |  | ipaddr | ) |

Value:
((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
IPADDR_LOOPBACK
#define IPADDR_LOOPBACK
Definition ip4_addr.h:65

Set address to loopback address

## ip4_addr_set_u32

#define ip4_addr_set_u32 | ( |  | dest_ipaddr,
|  |  | src_u32 )

Value:
((dest_ipaddr)->addr = (src_u32))

IPv4 only: set the IP address given as an u32_t

## ip4_addr_set_zero

#define ip4_addr_set_zero | ( |  | ipaddr | ) |

Value:
((ipaddr)->addr = 0)

Set complete address to zero

## ip_ntoa

#define ip_ntoa | ( |  | ipaddr | ) |

Value:
ipaddr_ntoa(ipaddr)

For backwards compatibility

## IPADDR_ANY

#define IPADDR_ANY ((u32_t)0x00000000UL)

0.0.0.0

## IPADDR_BROADCAST

#define IPADDR_BROADCAST ((u32_t)0xffffffffUL)

255.255.255.255

## IPADDR_LOOPBACK

#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)

127.0.0.1

## IPADDR_NONE

#define IPADDR_NONE ((u32_t)0xffffffffUL)

255.255.255.255

## Typedef Documentation

## ip4_addr_t

typedef struct ip4_addr ip4_addr_t

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

## Function Documentation

## ip4_addr_isbroadcast_u32()

u8_t ip4_addr_isbroadcast_u32 | ( | u32_t | addr,
|  | const struct netif * | netif )

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

Parameters

  addr | address to be checked
  netif | the network interface against which the address is checked

Returns
  returns non-zero if the address is a broadcast address

## ip4_addr_netmask_valid()

u8_t ip4_addr_netmask_valid | ( | u32_t | netmask | ) |

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

Parameters

  netmask | the IPv4 netmask to check (in network byte order!)

Returns
  1 if the netmask is valid, 0 if it is not

## ip4addr_aton()

int ip4addr_aton | ( | const char * | cp,
|  | ip4_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

  cp | IP address in ascii representation (e.g. "127.0.0.1")
  addr | pointer to which to save the ip address in network order

Returns
  1 if cp could be converted to addr, 0 on failure

## ip4addr_ntoa()

char * ip4addr_ntoa | ( | const ip4_addr_t * | addr | ) |

returns ptr to static buffer; not reentrant!

Convert numeric IP address into decimal dotted ASCII representation. returns ptr to static buffer; not reentrant!

Parameters

  addr | ip address in network order to convert

Returns
  pointer to a global static (!) buffer that holds the ASCII representation of addr

## ip4addr_ntoa_r()

char * ip4addr_ntoa_r | ( | const ip4_addr_t * | addr,
|  | char * | buf,
|  | int | buflen )

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

Parameters

  addr | ip address in network order to convert
  buf | target buffer where the string is stored
  buflen | length of buf

Returns
  either pointer to buf which now holds the ASCII representation of addr or NULL if buf was too small

## ipaddr_addr()

u32_t ipaddr_addr | ( | const char * | cp | ) |

Ascii internet address interpretation routine. The value returned is in network order.

Parameters

  cp | IP address in ascii representation (e.g. "127.0.0.1")

Returns
  ip address in network order