Generic IP Addresses


Data Structures

struct  ip_sockaddr_s
struct  in6_bytes_s

Defines

#define IP_ADDR_SIZE(ip)
#define IP_ADDR_IN(ip)   (&((((struct sockaddr_in*)(ip))->sin_addr)))
#define IP_ADDR_IN6(ip)   (&((((struct sockaddr_in6*)(ip))->sin6_addr)))
#define IP_ADDR_LLC(ip)   (&((ip)->sa_data[(2*sizeof(__ss_aligntype))-sizeof(sa_family_t)]))
#define IP_ADDR(ip)
#define IP_ADDR_AF(ip, af)
#define IP_STRLEN(ip)

Typedefs

typedef ip_sockaddr_s ip_addr_t
typedef in6_bytes_s in6_bytes_t

Functions

ip_addr_t ip_addr_v4 (register uint32_t)
uint32_t ip_v4_addr (register ip_addr_t *)
ip_addr_t ip_addr_in (register struct in_addr *)
in_addr ip_in_addr (register ip_addr_t *)
ip_addr_t ip_addr_sin (register struct sockaddr_in *)
sockaddr_in ip_sin_addr (register ip_addr_t *)
ip_addr_t ip_addr_in6 (register struct in6_addr *)
in6_addr ip_in6_addr (register ip_addr_t *)
ip_addr_t ip_addr_sin6 (register struct sockaddr_in6 *)
sockaddr_in6 ip_sin6_addr (register ip_addr_t *)
ip_addr_t ip_addr_in6bytes (register in6_bytes_t *)
in6_bytes_t ip_in6bytes_addr (register ip_addr_t *)
ip_addr_t ip_addr_text (register const char *)
char * ip_text_addr (register ip_addr_t *, register char *, register size_t)
char * ip_text (ip_addr_t ip, register char *, register size_t)
ip_addr_t ip_addr_binary (uint8_t *buf, uint8_t len)
ip_addr_t ip_v4_broadcast (ip_addr_t *, uint8_t prefix)
uint8_t ip_v4_netmask_to_prefix (ip_addr_t *netmask)
ip_addr_t ip_v4_prefix_to_netmask (uint8_t prefix)
ip_addr_t ip_mask (ip_addr_t *, uint8_t prefix)

Detailed Description

Generic IP address representation and conversion utilities.

Define Documentation

#define IP_ADDR ( ip   ) 

Value:

(  ((ip)->sa_family == AF_INET)    ? (void*) IP_ADDR_IN(ip) \
                         :(((ip)->sa_family == AF_INET6) ? (void*) IP_ADDR_IN6(ip) \
                           :(((ip)->sa_family == AF_LLC) ? (void*) IP_ADDR_LLC(ip) : 0 ) \
                          ) \
                      )
IP_ADDR macro: returns the address of the IP address field within the ip_addr_t structure pointed to by 'ip'.

Definition at line 97 of file ip_addr.h.

#define IP_ADDR_AF ( ip,
af   ) 

Value:

(  ((af) == AF_INET)    ? (void*) IP_ADDR_IN(ip) \
                               :(((af) == AF_INET6) ? (void*) IP_ADDR_IN6(ip) \
                                 :(((af) == AF_LLC) ? (void*) IP_ADDR_LLC(ip) : 0 ) \
                                ) \
                            )
IP_ADDR_AF macro: returns the address of the IP address of family 'af' field within the ip_addr_t structure pointed to by 'ip'.

Definition at line 107 of file ip_addr.h.

#define IP_ADDR_IN ( ip   )     (&((((struct sockaddr_in*)(ip))->sin_addr)))

IP_ADDR_IN macro: returns the address of the AF_INET IPv4 address field within the ip_addr_t structure pointed to by 'ip'.

Definition at line 79 of file ip_addr.h.

Referenced by ip_addr_binary(), ip_addr_in(), ip_addr_text(), ip_addr_v4(), ip_in_addr(), ip_mask(), ip_text_addr(), ip_v4_addr(), and ip_v4_broadcast().

#define IP_ADDR_IN6 ( ip   )     (&((((struct sockaddr_in6*)(ip))->sin6_addr)))

IP_ADDR_IN6 macro: returns the address of the AF_INET6 IPv6 address field within the ip_addr_t structure pointed to by 'ip'.

Definition at line 85 of file ip_addr.h.

Referenced by ip_addr_binary(), ip_addr_in6(), ip_addr_in6bytes(), ip_addr_text(), ip_in6_addr(), ip_in6bytes_addr(), ip_mask(), and ip_text_addr().

#define IP_ADDR_LLC ( ip   )     (&((ip)->sa_data[(2*sizeof(__ss_aligntype))-sizeof(sa_family_t)]))

IP_ADDR_LLC macro: returns the address of the AF_LLC Link Layer (ethernet) address field within the ip_addr_t structure pointed to by 'ip'.

Definition at line 91 of file ip_addr.h.

Referenced by ip_addr_binary(), and ip_text_addr().

#define IP_ADDR_SIZE ( ip   ) 

Value:

(  ((ip)->sa_family == AF_INET) ? sizeof(struct sockaddr_in) \
                              :(((ip)->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) \
                                :(((ip)->sa_family == AF_LLC) ? __LLC_SOCK_SIZE__ : 0) \
                               ) \
                           )
IP_ADDR_SIZE macro: returns the actual size of the ip_addr_t structure pointed to by 'ip'.

Definition at line 64 of file ip_addr.h.

#define IP_STRLEN ( ip   ) 

Value:

( ((ip)->sa_family == AF_INET) ? INET_ADDRSTRLEN : \
      ((ip)->sa_family == AF_INET6) ? INET6_ADDRSTRLEN : 0 )
IP_STRLEN macro: returns the maximum string length based on the address family of the ip_addr_t structure. Used in inet_ntop() calls.

Definition at line 117 of file ip_addr.h.


Typedef Documentation

typedef struct in6_bytes_s in6_bytes_t

struct in6_bytes_s: representation of an IPv6 address as an array of 16 bytes:

typedef struct ip_sockaddr_s ip_addr_t

IP addresses structure big enough for an IPv6 address by default (minimum size == sizeof(struct sockaddr_in6)). Compatible with all of struct sockaddr, struct sockaddr_in, and struct sockaddr_in6. If used to represent an IPv4 or IPv6 address, (&(s->sin_addr) == &(s->sin6_addr) == &(s->sa_pad)) . If used to represent an AF_LLC address (ethernet), &(((ip_addr_t*)s)->sa_data) == &(((struct sockaddr*)s)->sa_data).


Function Documentation

ip_addr_t ip_addr_binary ( uint8_t *  buf,
uint8_t  len 
)

ip_addr_binary ( buf, len ): returns the ip_addr_t representation of the len address bytes pointed to by buf; if len is not a recognized address length (the fixed length of an AF_INET, AF_INET6, or AF_LLC ethernet address), returns a null ip address with sa_family==0.

Definition at line 169 of file ip_addr.c.

References AF_LLC, IP_ADDR_IN, IP_ADDR_IN6, IP_ADDR_LLC, and ip_sockaddr_s::sa_family.

ip_addr_t ip_addr_in ( register struct in_addr *   ) 

ip_addr_in( in_addr ): returns the ip_addr_t representation of the struct in_addr AF_INET address argument.

Definition at line 47 of file ip_addr.c.

References IP_ADDR_IN, and ip_sockaddr_s::sa_data.

Referenced by dhcp4_nic_option_handler(), and dhcp4_process_lease().

ip_addr_t ip_addr_in6 ( register struct in6_addr *   ) 

ip_addr_in6( in6 ): returns the ip_addr_t representation of the struct in6_addr pointed to by in6 .

Definition at line 75 of file ip_addr.c.

References IP_ADDR_IN6, and ip_sockaddr_s::sa_data.

Referenced by dhcp6_process_lease().

ip_addr_t ip_addr_in6bytes ( register in6_bytes_t  ) 

ip_addr_in6bytes( in6bytes ): returns the ip_addr_t representation of the in6_bytes_t pointed to by in6_bytes

Definition at line 104 of file ip_addr.c.

References IP_ADDR_IN6, and ip_sockaddr_s::sa_data.

ip_addr_t ip_addr_sin ( register struct sockaddr_in *   ) 

ip_addr_sin( sin ): returns the ip_addr_t representation of the struct sockaddr_in pointer sin.

Definition at line 62 of file ip_addr.c.

ip_addr_t ip_addr_sin6 ( register struct sockaddr_in6 *   ) 

ip_addr_sin6( sin6 ): returns the ip_addr_t representation of the struct sockaddr_in6 pointed to by sin6.

Definition at line 91 of file ip_addr.c.

ip_addr_t ip_addr_text ( register const char *   ) 

ip_addr_text( str ): converts string str to an IP address represented by the returned ip_addr_t, if possible. If not possible, a null IP address (with sa_family == 0) is returned.

Definition at line 118 of file ip_addr.c.

References IP_ADDR_IN, and IP_ADDR_IN6.

ip_addr_t ip_addr_v4 ( register  uint32_t  ) 

ip_addr_v4(uint32_t int_ip): returns the ip_addr_t struct of the 32-bit AF_INET address int_ip, converting int_ip to network byte order.

Definition at line 32 of file ip_addr.c.

References IP_ADDR_IN, and ip_sockaddr_s::sa_data.

struct in6_addr ip_in6_addr ( register ip_addr_t  ) 

ip_in6_addr( ip ): returns the struct in6_addr representation of the ip_addr_t pointed to by ip.

Definition at line 84 of file ip_addr.c.

References IP_ADDR_IN6.

in6_bytes_t ip_in6bytes_addr ( register ip_addr_t  ) 

ip_in6bytes_addr( ip ): returns the in6_bytes_t representation of the ip_addr_t pointed to by ip.

Definition at line 113 of file ip_addr.c.

References IP_ADDR_IN6.

struct in_addr ip_in_addr ( register ip_addr_t  ) 

ip_in_addr(ip): returns the struct in_addr AF_INET address represented by the ip_addr_t pointed to by ip.

Definition at line 55 of file ip_addr.c.

References IP_ADDR_IN.

ip_addr_t ip_mask ( ip_addr_t ,
uint8_t  prefix 
)

ip_mask( ip, prefix ): returns the subnet address of the IPv4 or IPv6 address pointed to by ip with the given prefix.

Definition at line 226 of file ip_addr.c.

References IP_ADDR_IN, IP_ADDR_IN6, and ip_sockaddr_s::sa_family.

struct sockaddr_in6 ip_sin6_addr ( register ip_addr_t  ) 

ip_sin6_addr( ip ): returns the sockaddr_in6 representation of the ip_addr_t pointed to by ip.

Definition at line 98 of file ip_addr.c.

struct sockaddr_in ip_sin_addr ( register ip_addr_t  ) 

ip_sin_addr( ip ): returns the struct sockaddr_in representation of the ip_addr_t pointed to by ip.

Definition at line 69 of file ip_addr.c.

char* ip_text ( ip_addr_t  ip,
register char *  ,
register  size_t 
)

ip_text_addr( ip, buf, size ): converts the ip_addr_t ip to a string. If buf is 0 or size is less than the string length required, uses a static buffer; otherwise, buf is used to store the string.

Definition at line 164 of file ip_addr.c.

References ip_text_addr().

char* ip_text_addr ( register ip_addr_t ,
register char *  ,
register  size_t 
)

ip_text_addr( ip, buf, size ): converts the ip_addr_t pointed to by ip to a string. If buf is 0 or size is less than the string length required, uses a static buffer; otherwise, buf is used to store the string.

Definition at line 139 of file ip_addr.c.

References __LLC_SOCK_SIZE__, AF_LLC, IP_ADDR_IN, IP_ADDR_IN6, and IP_ADDR_LLC.

Referenced by dhcp4_nic_option_handler(), dhcp4_process_lease(), and ip_text().

uint32_t ip_v4_addr ( register ip_addr_t  ) 

ip_addr_v4(ip): returns the the 32 bit integer representation of the AF_INET address represented by ip_addr_t IP, in host byte order.

Definition at line 40 of file ip_addr.c.

References IP_ADDR_IN.

Referenced by dhcp4_nic_option_handler().

ip_addr_t ip_v4_broadcast ( ip_addr_t ,
uint8_t  prefix 
)

ip_v4_broadcast( ip, prefix ): returns the IPv4 broadcast address of the AF_INET IPv4 address pointed to by ip with the given prefix .

Definition at line 196 of file ip_addr.c.

References IP_ADDR_IN, and ip_sockaddr_s::sa_data.

Referenced by dhcp4_nic_option_handler().

uint8_t ip_v4_netmask_to_prefix ( ip_addr_t netmask  ) 

ip_v4_netmask_to_prefix( netmask ): returns the prefix length of all-one bits in the ip_addr_t pointed to by netmask.

Definition at line 208 of file ip_addr.c.

References ip_sockaddr_s::sa_family.

ip_addr_t ip_v4_prefix_to_netmask ( uint8_t  prefix  ) 

ip_v4_prefix_to_netmask( prefix ): returns the netmask address of prefix all-one bits .

Definition at line 216 of file ip_addr.c.

References ip_sockaddr_s::sa_family.


Generated on Mon Aug 14 17:25:56 2006 for libdhcp by  doxygen 1.4.7