Contiki-Inga 3.x
Macros | Functions
uIP conversion functions

These functions can be used for converting between different data formats used by uIP. More...

Macros

#define uip_ipaddr_to_quad(a)
 Convert an IP address to four bytes separated by commas. More...
 
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
 Construct an IP address from four bytes. More...
 
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
 Construct an IPv6 address from eight 16-bit words. More...
 
#define uip_ip6addr_u8(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8, addr9, addr10, addr11, addr12, addr13, addr14, addr15)
 Construct an IPv6 address from sixteen 8-bit words. More...
 
#define uip_ipaddr_copy(dest, src)   (*(dest) = *(src))
 Copy an IP address from one place to another. More...
 
#define uip_ip4addr_cmp(addr1, addr2)
 Compare two IP addresses. More...
 
#define uip_ipaddr_maskcmp(addr1, addr2, mask)
 Compare two IP addresses with netmasks. More...
 
#define uip_ipaddr_mask(dest, src, mask)
 Check if an address is a broadcast address for a network. More...
 
#define uip_ipaddr1(addr)
 Pick the first octet of an IP address. More...
 
#define uip_ipaddr2(addr)
 Pick the second octet of an IP address. More...
 
#define uip_ipaddr3(addr)
 Pick the third octet of an IP address. More...
 
#define uip_ipaddr4(addr)
 Pick the fourth octet of an IP address. More...
 
#define UIP_HTONS(n)
 Convert 16-bit quantity from host byte order to network byte order. More...
 
#define uiplib_ipaddrconv   uiplib_ip6addrconv
 Convert a textual representation of an IP address to a numerical representation. More...
 

Functions

CCIF uint16_t uip_htons (uint16_t val)
 Convert a 16-bit quantity from host byte order to network byte order. More...
 

Detailed Description

These functions can be used for converting between different data formats used by uIP.

Macro Definition Documentation

#define UIP_HTONS (   n)

Convert 16-bit quantity from host byte order to network byte order.

This macro is primarily used for converting constants from host byte order to network byte order. For converting variables to network byte order, use the uip_htons() function instead.

Examples:
example-program.c, and example-psock-server.c.

Definition at line 1236 of file uip.h.

Referenced by mac_ethernetToLowpan(), simple_udp_register(), simple_udp_send(), simple_udp_sendto(), simple_udp_sendto_port(), uip_arp_arpin(), uip_arp_out(), uip_fw_forward(), uip_htons(), and uip_process().

#define uip_ip4addr_cmp (   addr1,
  addr2 
)

Compare two IP addresses.

Compares two IP addresses.

Example:

uip_ipaddr_t ipaddr1, ipaddr2;
uip_ipaddr(&ipaddr1, 192,16,1,2);
if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
printf("They are the same");
}
Parameters
addr1The first IP address.
addr2The second IP address.

Definition at line 1053 of file uip.h.

#define uip_ip6addr (   addr,
  addr0,
  addr1,
  addr2,
  addr3,
  addr4,
  addr5,
  addr6,
  addr7 
)

Construct an IPv6 address from eight 16-bit words.

This function constructs an IPv6 address.

Definition at line 967 of file uip.h.

Referenced by main().

#define uip_ip6addr_u8 (   addr,
  addr0,
  addr1,
  addr2,
  addr3,
  addr4,
  addr5,
  addr6,
  addr7,
  addr8,
  addr9,
  addr10,
  addr11,
  addr12,
  addr13,
  addr14,
  addr15 
)

Construct an IPv6 address from sixteen 8-bit words.

This function constructs an IPv6 address.

Definition at line 985 of file uip.h.

#define uip_ipaddr (   addr,
  addr0,
  addr1,
  addr2,
  addr3 
)

Construct an IP address from four bytes.

This function constructs an IP address of the type that uIP handles internally from four bytes. The function is handy for specifying IP addresses to use with e.g. the uip_connect() function.

Example:

uip_ipaddr_t ipaddr;
struct uip_conn *c;
uip_ipaddr(&ipaddr, 192,168,1,2);
c = uip_connect(&ipaddr, UIP_HTONS(80));
Parameters
addrA pointer to a uip_ipaddr_t variable that will be filled in with the IP address.
addr0The first octet of the IP address.
addr1The second octet of the IP address.
addr2The third octet of the IP address.
addr3The forth octet of the IP address.

Definition at line 953 of file uip.h.

#define uip_ipaddr1 (   addr)

Pick the first octet of an IP address.

Picks out the first octet of an IP address.

Example:

uip_ipaddr_t ipaddr;
uint8_t octet;
uip_ipaddr(&ipaddr, 1,2,3,4);
octet = uip_ipaddr1(&ipaddr);

In the example above, the variable "octet" will contain the value 1.

Definition at line 1163 of file uip.h.

#define uip_ipaddr2 (   addr)

Pick the second octet of an IP address.

Picks out the second octet of an IP address.

Example:

uip_ipaddr_t ipaddr;
uint8_t octet;
uip_ipaddr(&ipaddr, 1,2,3,4);
octet = uip_ipaddr2(&ipaddr);

In the example above, the variable "octet" will contain the value 2.

Definition at line 1183 of file uip.h.

#define uip_ipaddr3 (   addr)

Pick the third octet of an IP address.

Picks out the third octet of an IP address.

Example:

uip_ipaddr_t ipaddr;
uint8_t octet;
uip_ipaddr(&ipaddr, 1,2,3,4);
octet = uip_ipaddr3(&ipaddr);

In the example above, the variable "octet" will contain the value 3.

Definition at line 1203 of file uip.h.

#define uip_ipaddr4 (   addr)

Pick the fourth octet of an IP address.

Picks out the fourth octet of an IP address.

Example:

uip_ipaddr_t ipaddr;
uint8_t octet;
uip_ipaddr(&ipaddr, 1,2,3,4);
octet = uip_ipaddr4(&ipaddr);

In the example above, the variable "octet" will contain the value 4.

Definition at line 1223 of file uip.h.

#define uip_ipaddr_copy (   dest,
  src 
)    (*(dest) = *(src))

Copy an IP address from one place to another.

Copies an IP address from one place to another.

Example:

uip_ipaddr_t ipaddr1, ipaddr2;
uip_ipaddr(&ipaddr1, 192,16,1,2);
uip_ipaddr_copy(&ipaddr2, &ipaddr1);
Parameters
destThe destination for the copy.
srcThe source from where to copy.

Definition at line 1024 of file uip.h.

Referenced by mac_ethernetToLowpan(), simple_udp_register(), uip_arp_arpin(), uip_arp_out(), uip_ds6_defrt_add(), uip_ds6_nbr_add(), uip_ds6_route_add(), uip_ds6_select_src(), uip_icmp6_echo_reply_input(), uip_icmp6_echo_request_input(), uip_icmp6_error_output(), uip_nd6_ns_input(), uip_nd6_ns_output(), uip_nd6_ra_input(), and uip_process().

#define uip_ipaddr_mask (   dest,
  src,
  mask 
)

Check if an address is a broadcast address for a network.

Checks if an address is the broadcast address for a network. The network is defined by an IP address that is on the network and the network's netmask.

Parameters
addrThe IP address.
netaddrThe network's IP address.
netmaskThe network's netmask. Mask out the network part of an IP address.

Masks out the network part of an IP address, given the address and the netmask.

Example:

uip_ipaddr_t ipaddr1, ipaddr2, netmask;
uip_ipaddr(&ipaddr1, 192,16,1,2);
uip_ipaddr(&netmask, 255,255,255,0);
uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);

In the example above, the variable "ipaddr2" will contain the IP address 192.168.1.0.

Parameters
destWhere the result is to be placed.
srcThe IP address.
maskThe netmask.

Definition at line 1140 of file uip.h.

#define uip_ipaddr_maskcmp (   addr1,
  addr2,
  mask 
)

Compare two IP addresses with netmasks.

Compares two IP addresses with netmasks. The masks are used to mask out the bits that are to be compared.

Example:

uip_ipaddr_t ipaddr1, ipaddr2, mask;
uip_ipaddr(&mask, 255,255,255,0);
uip_ipaddr(&ipaddr1, 192,16,1,2);
uip_ipaddr(&ipaddr2, 192,16,1,3);
if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
printf("They are the same");
}
Parameters
addr1The first IP address.
addr2The second IP address.
maskThe netmask.

Definition at line 1088 of file uip.h.

Referenced by uip_arp_out().

#define uip_ipaddr_to_quad (   a)

Convert an IP address to four bytes separated by commas.

Example:

uip_ipaddr_t ipaddr;
printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
Parameters
aA pointer to a uip_ipaddr_t.

Definition at line 925 of file uip.h.

#define uiplib_ipaddrconv   uiplib_ip6addrconv

Convert a textual representation of an IP address to a numerical representation.

This function takes a textual representation of an IP address in the form a.b.c.d for IPv4 or a:b:c:d:e:f:g:h for IPv6 and converts it into a numeric IP address representation that can be used by other uIP functions.

Parameters
addrstrA pointer to a string containing the IP address in textual form.
addrA pointer to a uip_ip4addr_t that will be filled in with the numerical representation of the address.
Return values
0If the IP address could not be parsed.
Non-zeroIf the IP address was parsed.

Definition at line 70 of file uiplib.h.

Function Documentation

CCIF uint16_t uip_htons ( uint16_t  val)

Convert a 16-bit quantity from host byte order to network byte order.

This function is primarily used for converting variables from host byte order to network byte order. For converting constants to network byte order, use the UIP_HTONS() macro instead.

Definition at line 2347 of file uip6.c.

References UIP_HTONS.

Referenced by mac_LowpanToEthernet(), roll_tm_icmp_input(), uip_chksum(), and uip_ipchksum().