PcapPlusPlus  Next
IpUtils.h File Reference
#include <stdint.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ws2tcpip.h>

Go to the source code of this file.

Namespaces

 pcpp
 The main namespace for the PcapPlusPlus lib.
 

Functions

const char * inet_ntop (int af, const void *src, char *dst, size_t size)
 
int inet_pton (int af, const char *src, void *dst)
 
in_addr * pcpp::internal::sockaddr2in_addr (sockaddr *sa)
 
in_addr * pcpp::internal::try_sockaddr2in_addr (sockaddr *sa)
 
in6_addr * pcpp::internal::sockaddr2in6_addr (sockaddr *sa)
 
in6_addr * pcpp::internal::try_sockaddr2in6_addr (sockaddr *sa)
 
void pcpp::internal::sockaddr2string (sockaddr const *sa, char *resultString, size_t resultBufLen)
 
uint32_t pcpp::internal::in_addr2int (in_addr inAddr)
 

Function Documentation

◆ in_addr2int()

uint32_t pcpp::internal::in_addr2int ( in_addr  inAddr)

Convert a in_addr format address to 32bit representation

Parameters
[in]inAddrAddress in in_addr format
Returns
Address in 32bit format

◆ inet_ntop()

const char* inet_ntop ( int  af,
const void *  src,
char *  dst,
size_t  size 
)

Convert a network format address to presentation format.

Parameters
[in]afAddress family, can be either AF_INET (IPv4) or AF_INET6 (IPv6)
[in]srcNetwork address structure, can be either in_addr (IPv4) or in6_addr (IPv6)
[out]dstNetwork address string representation
[in]size'dst' Maximum size
Returns
pointer to presentation format address ('dst'), or nullptr (see errno).

◆ inet_pton()

int inet_pton ( int  af,
const char *  src,
void *  dst 
)

Convert from presentation format (which usually means ASCII printable) to network format (which is usually some kind of binary format).

Parameters
[in]afAddress family, can be either AF_INET (IPv4) or AF_INET6 (IPv6)
[in]srcNetwork address string representation
[out]dstNetwork address structure result, can be either in_addr (IPv4) or in6_addr (IPv6)
Returns
1 if the address was valid for the specified address family; 0 if the address wasn't valid ('dst' is untouched in this case); -1 if some other error occurred ('dst' is untouched in this case, too)

◆ sockaddr2in6_addr()

in6_addr* pcpp::internal::sockaddr2in6_addr ( sockaddr *  sa)

Extract IPv6 address from sockaddr

Parameters
[in]sa- input sockaddr
Returns
Address in in6_addr format
Exceptions
std::invalid_argumentSockaddr family is not AF_INET6 or sockaddr is nullptr.

◆ sockaddr2in_addr()

in_addr* pcpp::internal::sockaddr2in_addr ( sockaddr *  sa)

Extract IPv4 address from sockaddr

Parameters
[in]sa- input sockaddr
Returns
Address in in_addr format
Exceptions
std::invalid_argumentSockaddr family is not AF_INET or sockaddr is nullptr.

◆ sockaddr2string()

void pcpp::internal::sockaddr2string ( sockaddr const *  sa,
char *  resultString,
size_t  resultBufLen 
)

Converts a sockaddr format address to its string representation

Parameters
[in]saAddress in sockaddr format
[out]resultStringString representation of the address
[in]resultBufLenLength of the result buffer.
Exceptions
std::invalid_argumentSockaddr family is not AF_INET or AF_INET6, sockaddr is nullptr or the result str buffer is insufficient.

◆ try_sockaddr2in6_addr()

in6_addr* pcpp::internal::try_sockaddr2in6_addr ( sockaddr *  sa)

Attempt to extract IPv6 address from sockaddr

Parameters
[in]sa- input sockaddr
Returns
Pointer to address in in6_addr format or nullptr if extraction fails.

◆ try_sockaddr2in_addr()

in_addr* pcpp::internal::try_sockaddr2in_addr ( sockaddr *  sa)

Attempt to extract IPv4 address from sockaddr

Parameters
[in]sa- input sockaddr
Returns
Pointer to address in in_addr format or nullptr if extraction fails.