DTS Application Library
0.2.3
Application library containing referenced objects and interfaces to common libraries
|
Helper functions for various calculations. More...
Files | |
file | iputil.c |
IPv4 And IPv6 Utiliies. | |
Data Structures | |
struct | pseudohdr |
IPv4 header structur to cast a packet too. More... | |
Functions | |
int | score_ipv4 (struct sockaddr_in *sa4, char *ipaddr, int iplen) |
Return a score for a IPv4 addrress. More... | |
void | ipv4tcpchecksum (uint8_t *pkt) |
Update the TCP checksum of a IPv4 packet. More... | |
void | ipv4udpchecksum (uint8_t *pkt) |
Update the UDP checksum of a IPv4 packet. More... | |
void | ipv4icmpchecksum (uint8_t *pkt) |
Set the checksup of a IPv4 ICMP packet. More... | |
void | ipv4checksum (uint8_t *pkt) |
Set the checksup of a IPv4 Packet. More... | |
int | packetchecksumv4 (uint8_t *pkt) |
Update the checksum of a IPv4 packet. More... | |
const char * | cidrtosn (int bitlen, char *buf, int size) |
Return the dotted quad notation subnet mask from a CIDR. More... | |
const char * | getnetaddr (const char *ipaddr, int cidr, char *buf, int size) |
Return the network address. More... | |
const char * | getfirstaddr (const char *ipaddr, int cidr, char *buf, int size) |
Get the first usable address. More... | |
const char * | getbcaddr (const char *ipaddr, int cidr, char *buf, int size) |
Return broadcast address. More... | |
const char * | getlastaddr (const char *ipaddr, int cidr, char *buf, int size) |
Get the last usable address. More... | |
uint32_t | cidrcnt (int bitlen) |
Return the number of IP addresses in a given bitmask. More... | |
int | reservedip (const char *ipaddr) |
Check IP against list of reserved IP's. More... | |
int | check_ipv4 (const char *ip, int cidr, const char *test) |
Check if a IP address is in a network. More... | |
Helper functions for various calculations.
int check_ipv4 | ( | const char * | ip, |
int | cidr, | ||
const char * | test | ||
) |
uint32_t cidrcnt | ( | int | bitlen | ) |
Return the number of IP addresses in a given bitmask.
bitlen | Subnet bits (CIDR). |
const char* cidrtosn | ( | int | bitlen, |
char * | buf, | ||
int | size | ||
) |
Return the dotted quad notation subnet mask from a CIDR.
bitlen | Subnet length bits. |
buf | Buffer to copy the subnet address too. |
size | Size of buffer. |
const char* getbcaddr | ( | const char * | ipaddr, |
int | cidr, | ||
char * | buf, | ||
int | size | ||
) |
const char* getfirstaddr | ( | const char * | ipaddr, |
int | cidr, | ||
char * | buf, | ||
int | size | ||
) |
Get the first usable address.
ipaddr | Network address. |
cidr | Bits in the subnet mask. |
buf | Buffer that the result is placed in. |
size | Length of buffer. |
Definition at line 286 of file iputil.c.
const char* getlastaddr | ( | const char * | ipaddr, |
int | cidr, | ||
char * | buf, | ||
int | size | ||
) |
Get the last usable address.
ipaddr | Network address. |
cidr | Bits in the subnet mask. |
buf | Buffer that the result is placed in. |
size | Length of buffer. |
Definition at line 347 of file iputil.c.
const char* getnetaddr | ( | const char * | ipaddr, |
int | cidr, | ||
char * | buf, | ||
int | size | ||
) |
Return the network address.
ipaddr | Ipaddr to calculate for |
cidr | Length of the subnet bitmask. |
buf | Buffer that the result is placed in. |
size | Length of buffer. |
Definition at line 254 of file iputil.c.
void ipv4checksum | ( | uint8_t * | pkt | ) |
Set the checksup of a IPv4 Packet.
pkt | Packet to update. |
Definition at line 154 of file iputil.c.
References checksum().
Referenced by packetchecksumv4().
void ipv4icmpchecksum | ( | uint8_t * | pkt | ) |
Set the checksup of a IPv4 ICMP packet.
pkt | ICMP Packet to update. |
Definition at line 143 of file iputil.c.
References checksum().
Referenced by packetchecksumv4().
void ipv4tcpchecksum | ( | uint8_t * | pkt | ) |
Update the TCP checksum of a IPv4 packet.
pkt | Packet to update TCP checksum. |
Definition at line 101 of file iputil.c.
References checksum(), checksum_add(), pseudohdr::daddr, pseudohdr::len, pseudohdr::proto, pseudohdr::saddr, and pseudohdr::zero.
Referenced by packetchecksumv4().
void ipv4udpchecksum | ( | uint8_t * | pkt | ) |
Update the UDP checksum of a IPv4 packet.
pkt | Packet to update UDP checksum. |
Definition at line 122 of file iputil.c.
References checksum(), checksum_add(), pseudohdr::daddr, pseudohdr::len, pseudohdr::proto, pseudohdr::saddr, and pseudohdr::zero.
Referenced by packetchecksumv4().
int packetchecksumv4 | ( | uint8_t * | pkt | ) |
Update the checksum of a IPv4 packet.
pkt | Packet buffer to update check. |
Definition at line 165 of file iputil.c.
References ipv4checksum(), ipv4icmpchecksum(), ipv4tcpchecksum(), and ipv4udpchecksum().
Referenced by packetchecksum().
int reservedip | ( | const char * | ipaddr | ) |
Check IP against list of reserved IP's.
ipaddr | IP addr to check. |
Definition at line 384 of file iputil.c.
Referenced by score_ipv4().
int score_ipv4 | ( | struct sockaddr_in * | sa4, |
char * | ipaddr, | ||
int | iplen | ||
) |
Return a score for a IPv4 addrress.
sa4 | Socket addr to check. |
ipaddr | Buffer to place IP address. |
iplen | Length of IP buffer. |
Definition at line 718 of file interface.c.
References inet_ntop(), IPV4_SCORE_RESERVED, IPV4_SCORE_ROUTABLE, IPV4_SCORE_ZEROCONF, and reservedip().
Referenced by get_ifinfo(), and get_ifipaddr().