DTS Application Library  0.2.3
Application library containing referenced objects and interfaces to common libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
IPv4 and IPv6 functions

Helper functions for various calculations. More...

Modules

 IPv4 functions
 Helper functions for various calculations.
 
 IPv6 functions
 Helper functions for various calculations.
 

Files

file  iputil.c
 IPv4 And IPv6 Utiliies.
 

Enumerations

enum  ipversion { IP_PROTO_V4 = 4, IP_PROTO_V6 = 6 }
 IP Protocol numbers. More...
 

Functions

int packetchecksum (uint8_t *pkt)
 Generic IPv4 and IPv6 Checksum. More...
 
int inet_lookup (int family, const char *host, void *addr, socklen_t len)
 Perform DNS lookup on a host/ip retun the IP address. More...
 

Detailed Description

Helper functions for various calculations.

Enumeration Type Documentation

enum ipversion

IP Protocol numbers.

Enumerator
IP_PROTO_V4 
IP_PROTO_V6 

Definition at line 77 of file iputil.c.

77  {
78  IP_PROTO_V4 = 4,
79  IP_PROTO_V6 = 6
80 };

Function Documentation

int inet_lookup ( int  family,
const char *  host,
void *  addr,
socklen_t  len 
)

Perform DNS lookup on a host/ip retun the IP address.

Parameters
familyProtocol family either PF_INET or PF_INET6.
hostHostname or IP address to lookup.
addrA structure in_addr or in6_addr the result is returned in.
lenLength of the structure to place the result.
Returns
0 on failure ie addr is unaltered.

Definition at line 523 of file iputil.c.

Referenced by mcast_socket().

523  {
524  struct addrinfo hint, *result, *ainfo;
525  int ret = 0;
526 
527  memset(&hint, 0, sizeof(hint));
528  hint.ai_family = family;
529 
530  if (getaddrinfo(host, NULL, &hint, &result) || !result) {
531  return ret;
532  }
533 
534  for(ainfo = result; ainfo; ainfo = ainfo->ai_next) {
535  switch(ainfo->ai_family) {
536  case PF_INET:
537  if (len >= sizeof(struct in_addr)) {
538  struct sockaddr_in *sa4 = (struct sockaddr_in*)ainfo->ai_addr;
539  memcpy(addr, &sa4->sin_addr, len);
540  ret = 1;
541  }
542  break;
543  case PF_INET6:
544  if (len >= sizeof(struct in6_addr)) {
545  struct sockaddr_in6 *sa6 = (struct sockaddr_in6*)ainfo->ai_addr;
546  memcpy(addr, &sa6->sin6_addr, len);
547  ret = 1;
548  }
549  break;
550  }
551  if (ret) {
552  break;
553  }
554  }
555  freeaddrinfo(result);
556  return ret;
557 }
int packetchecksum ( uint8_t *  pkt)

Generic IPv4 and IPv6 Checksum.

Parameters
pktPacket buffer to check.
Returns
Checksum.

Definition at line 208 of file iputil.c.

References IP_PROTO_V4, IP_PROTO_V6, and packetchecksumv4().

208  {
209  struct iphdr *ip = (struct iphdr *)pkt;
210 
211  switch(ip->version) {
212  case IP_PROTO_V4:
213  return (packetchecksumv4(pkt));
214  break;
215  case IP_PROTO_V6:
216  break;
217  }
218  return (-1);
219 }
int packetchecksumv4(uint8_t *pkt)
Update the checksum of a IPv4 packet.
Definition: iputil.c:165