libtins
4.0
|
Network utils namespace. More...
Classes | |
struct | InterfaceCollector |
struct | is_pdu |
struct | RadioTapFlags |
class | RadioTapParser |
Allows parsing RadioTap options. More... | |
class | RadioTapWriter |
Writes RadioTap options into a buffer. More... | |
struct | Route6Entry |
struct | RouteEntry |
Functions | |
TINS_API uint32_t | do_checksum (const uint8_t *start, const uint8_t *end) |
Does the 16 bits sum of all 2 bytes elements between start and end. More... | |
TINS_API uint16_t | sum_range (const uint8_t *start, const uint8_t *end) |
Computes the 16 bit sum of the input buffer. More... | |
TINS_API uint32_t | pseudoheader_checksum (IPv4Address source_ip, IPv4Address dest_ip, uint16_t len, uint16_t flag) |
Performs the pseudo header checksum used in TCP and UDP PDUs. More... | |
TINS_API uint32_t | pseudoheader_checksum (IPv6Address source_ip, IPv6Address dest_ip, uint16_t len, uint16_t flag) |
Performs the pseudo header checksum used in TCP and UDP PDUs. More... | |
TINS_API uint32_t | crc32 (const uint8_t *data, uint32_t data_size) |
Returns the 32 bit crc of the given buffer. More... | |
TINS_API uint16_t | channel_to_mhz (uint16_t channel) |
Converts a channel number to its mhz representation. More... | |
TINS_API uint16_t | mhz_to_channel (uint16_t mhz) |
Converts mhz units to the appropriate channel number. More... | |
TINS_API std::string | to_string (PDU::PDUType pduType) |
Converts a PDUType to a string. More... | |
PDU & | dereference_until_pdu (PDU &pdu) |
template<typename T > | |
Internals::enable_if<!is_pdu< T >::value, PDU & >::type | dereference_until_pdu (T &value) |
Dereferences the parameter until a PDU is found. More... | |
TINS_API IPv4Address | resolve_domain (const std::string &to_resolve) |
Resolves a domain name and returns its corresponding ip address. More... | |
TINS_API IPv6Address | resolve_domain6 (const std::string &to_resolve) |
Resolves a domain name and returns its corresponding ip address. More... | |
TINS_API HWAddress< 6 > | resolve_hwaddr (const NetworkInterface &iface, IPv4Address ip, PacketSender &sender) |
Resolves the hardware address for a given ip. More... | |
TINS_API HWAddress< 6 > | resolve_hwaddr (IPv4Address ip, PacketSender &sender) |
Resolves the hardware address for a given ip. More... | |
template<typename ForwardIterator > | |
void | route_entries (ForwardIterator output) |
Retrieves entries in the routing table. More... | |
template<typename ForwardIterator > | |
void | route6_entries (ForwardIterator output) |
Retrieves entries in the routing table. More... | |
TINS_API std::vector< RouteEntry > | route_entries () |
Retrieves entries in the routing table. More... | |
TINS_API std::vector< Route6Entry > | route6_entries () |
Retrieves entries in the routing table. More... | |
TINS_API std::set< std::string > | network_interfaces () |
List all network interfaces. More... | |
TINS_API bool | gateway_from_ip (IPv4Address ip, IPv4Address &gw_addr) |
Finds the gateway's IP address for the given IP address. More... | |
TINS_API bool | gateway_from_ip (IPv6Address ip, IPv6Address &gw_addr) |
Finds the gateway's IP address for the given IP address. More... | |
template<size_t buffer_size, typename AddressType > | |
uint32_t | generic_pseudoheader_checksum (const AddressType &source_ip, const AddressType &dest_ip, uint16_t len, uint16_t flag) |
void | align_buffer (const uint8_t *buffer_start, const uint8_t *&buffer, uint32_t size, size_t n) |
uint32_t | calculate_padding (uint32_t alignment, uint32_t offset) |
uint32_t | get_bit (uint32_t value) |
IPv4Address | resolve_domain (const string &to_resolve) |
IPv6Address | resolve_domain6 (const string &to_resolve) |
bool | from_hex (const string &str, uint32_t &result) |
bool | from_hex (const string &str, string &result) |
void | skip_line (istream &input) |
Variables | |
TINS_BEGIN_PACK struct Tins::Utils::RadioTapFlags | TINS_END_PACK |
Network utils namespace.
This namespace provides utils to convert between integer IP addresses and dotted notation strings, "net to host" integer conversions, interface listing, etc.
uint16_t Tins::Utils::channel_to_mhz | ( | uint16_t | channel | ) |
Converts a channel number to its mhz representation.
channel | The channel number. |
uint32_t Tins::Utils::crc32 | ( | const uint8_t * | data, |
uint32_t | data_size | ||
) |
Returns the 32 bit crc of the given buffer.
data | The input buffer. |
data_size | The size of the input buffer. |
uint32_t Tins::Utils::do_checksum | ( | const uint8_t * | start, |
const uint8_t * | end | ||
) |
Does the 16 bits sum of all 2 bytes elements between start and end.
This is the checksum used by IP, UDP and TCP. If there's and odd number of bytes, the last one is padded and added to the checksum.
start | The pointer to the start of the buffer. |
end | The pointer to the end of the buffer(excluding the last element). |
bool Tins::Utils::gateway_from_ip | ( | IPv4Address | ip, |
IPv4Address & | gw_addr | ||
) |
bool Tins::Utils::gateway_from_ip | ( | IPv6Address | ip, |
IPv6Address & | gw_addr | ||
) |
uint16_t Tins::Utils::mhz_to_channel | ( | uint16_t | mhz | ) |
Converts mhz units to the appropriate channel number.
mhz | The mhz units to be converted. |
set< string > Tins::Utils::network_interfaces | ( | ) |
List all network interfaces.
Returns a set of strings, each of them representing the name of a network interface. These names can be used as the input interface for Utils::interface_ip, Utils::interface_hwaddr, etc.
uint32_t Tins::Utils::pseudoheader_checksum | ( | IPv4Address | source_ip, |
IPv4Address | dest_ip, | ||
uint16_t | len, | ||
uint16_t | flag | ||
) |
uint32_t Tins::Utils::pseudoheader_checksum | ( | IPv6Address | source_ip, |
IPv6Address | dest_ip, | ||
uint16_t | len, | ||
uint16_t | flag | ||
) |
TINS_API IPv4Address Tins::Utils::resolve_domain | ( | const std::string & | to_resolve | ) |
Resolves a domain name and returns its corresponding ip address.
If an ip address is given, its integer representation is returned. Otherwise, the domain name is resolved and its ip address is returned.
to_resolve | The domain name/ip address to resolve. |
TINS_API IPv6Address Tins::Utils::resolve_domain6 | ( | const std::string & | to_resolve | ) |
Resolves a domain name and returns its corresponding ip address.
If an ip address is given, its integer representation is returned. Otherwise, the domain name is resolved and its ip address is returned.
to_resolve | The domain name/ip address to resolve. |
HWAddress< 6 > Tins::Utils::resolve_hwaddr | ( | const NetworkInterface & | iface, |
IPv4Address | ip, | ||
PacketSender & | sender | ||
) |
Resolves the hardware address for a given ip.
If the address can't be resolved, a std::runtime_error exception is thrown.
iface | The interface in which the packet will be sent. |
ip | The ip to resolve, in integer format. |
sender | The sender to use to send and receive the ARP requests. |
HWAddress< 6 > Tins::Utils::resolve_hwaddr | ( | IPv4Address | ip, |
PacketSender & | sender | ||
) |
Resolves the hardware address for a given ip.
If the address can't be resolved, a std::runtime_error exception is thrown.
This method sends and receives the packet through PacketSender::default_interface.
ip | The ip to resolve, in integer format. |
sender | The sender to use to send and receive the ARP requests. |
void Tins::Utils::route6_entries | ( | ForwardIterator | output | ) |
Retrieves entries in the routing table.
output ForwardIterator in which entries will be stored.
vector< Route6Entry > Tins::Utils::route6_entries | ( | ) |
Retrieves entries in the routing table.
void Tins::Utils::route_entries | ( | ForwardIterator | output | ) |
Retrieves entries in the routing table.
output ForwardIterator in which entries will be stored.
vector< RouteEntry > Tins::Utils::route_entries | ( | ) |
Retrieves entries in the routing table.
uint16_t Tins::Utils::sum_range | ( | const uint8_t * | start, |
const uint8_t * | end | ||
) |
Computes the 16 bit sum of the input buffer.
If there's and odd number of bytes in the buffer, the last one is padded and added to the checksum.
start | The pointer to the start of the buffer. |
end | The pointer to the end of the buffer(excluding the last element). |
string Tins::Utils::to_string | ( | PDU::PDUType | pduType | ) |
Converts a PDUType to a string.
pduType | The PDUType to be converted. |