34 #ifndef EMANEUTILSNETUTILS_HEADER_ 35 #define EMANEUTILSNETUTILS_HEADER_ 41 #include <arpa/inet.h> 87 return ((vhl >> 4) & 0x0F);
99 return ((vhl & 0x0F) << 2);
128 return (((ver & 0x0F) << 2) | (clas >> 6));
248 addr_to_string(
const std::uint8_t * addr,
size_t addrlen,
const char *delim,
char *buf,
size_t buflen)
252 for(
size_t i = 0; i < addrlen; ++i)
254 if(i < (addrlen - 1))
256 pos += snprintf(buf + pos, buflen - pos,
"%02X%s", addr[i] & 0xFF, delim);
260 pos += snprintf(buf + pos, buflen - pos,
"%02X", addr[i] & 0xFF);
319 return (ntohs(ip->
u16Ipv6len) + IPV6_HEADER_LEN);
494 addr_to_string((std::uint8_t*) addr, ETH_ALEN,
":", buf,
sizeof(buf));
691 static std::uint8_t MulticastMacAddr[3] = {0x01, 0x00, 0x5E};
694 static std::uint8_t BroadcastMacAddr[
ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
697 if(memcmp(addr->
bytes.
buff, MulticastMacAddr, 3) == 0)
699 return ntohs(0xFFFF);
702 else if(memcmp(addr->
bytes.
buff, BroadcastMacAddr, 6) == 0)
704 return ntohs(0xFFFF);
725 static std::uint8_t MulticastMacAddr[2] = {0x33, 0x33};
728 static std::uint8_t BroadcastMacAddr[
ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
731 if(memcmp(addr->
bytes.
buff, MulticastMacAddr, 2) == 0)
733 return ntohs(0xFFFF);
736 else if(memcmp(addr->
bytes.
buff, BroadcastMacAddr, 6) == 0)
738 return ntohs(0xFFFF);
757 std::uint8_t len = 0;
758 std::uint8_t *u8ptr = (std::uint8_t *) prefix;
766 if (len < IPV6_MAX_BIT_LEN)
768 std::uint8_t byte = *u8ptr;
792 inet_cksum (
const void * buf,
int buflen, std::uint16_t prev = 0)
794 std::uint32_t sum = 0;
795 std::uint16_t *w = (std::uint16_t *) buf;
804 std::uint8_t *byte = (std::uint8_t *) w;
809 sum = (sum >> 16) + (sum & 0xFFFF);
810 return (sum + (sum >> 16));
851 std::stringstream ss;
853 ss.precision(precision);
855 const float fFrequency = val;
857 if(fFrequency < 1e+3)
859 ss << fFrequency <<
" Hz";
861 else if (fFrequency < 1e+6)
863 ss << (fFrequency / 1e+3) <<
" KHz";
865 else if (fFrequency < 1e+9)
867 ss << (fFrequency / 1e+6) <<
" MHz";
869 else if (fFrequency < 1e+12)
871 ss << (fFrequency / 1e+9) <<
" GHz";
875 ss << (fFrequency / 1e+12) <<
" THz";
881 inline std::vector<std::string>
getTokens(
const std::string & sInput,
const char * pzDelimeter)
883 char *pzToken = NULL;
887 std::string str = sInput;
889 std::vector<std::string> strVector;
891 while ((pzToken = strtok (iTokenCount == 0 ? &str[0] : NULL, pzDelimeter)) != NULL)
895 strVector.push_back(pzToken);
903 #endif // EMANEUTILSNETUTILS_HEADER_ const std::uint16_t ETH_P_ARP
Ethernet arp protocol.
std::uint8_t Ipv6src[IPV6_ADDR_LEN]
const std::uint16_t ETH_P_IPV6
Ethernet ipv6 protocol.
std::uint32_t get_dstprotoaddr(const EtherArpHeader *arp)
const std::uint16_t IPV6_MAX_BIT_LEN
ipv6 max addr len
struct EtherAddrWords words
const EtherAddr * get_dsthwaddr(const EtherArpHeader *arp)
std::vector< std::string > getTokens(const std::string &sInput, const char *pzDelimeter)
std::uint16_t get_len(const Ip4Header *ip)
struct EtherAddrBytes bytes
const std::uint16_t IP_MAX_PACKET
Max ip packet len.
Definition of the ethernet frame address as an array of 6 bytes.
std::uint16_t get_code(const EtherArpHeader *arp)
struct EtherAddrWords words
const std::uint16_t UDP_HEADER_LEN
udp header len
std::uint16_t get_protocol(const EtherHeader *eth)
std::uint8_t get_ip_dscp(std::uint8_t tos)
std::string formatFrequency(const std::uint64_t val, const int precision=6)
returns a sting with the formatted value and suffix
std::uint8_t get_hwaddrlen(const EtherArpHeader *arp)
std::uint8_t buff[ETH_ALEN]
std::uint16_t get_hwtype(const EtherArpHeader *arp)
const std::uint16_t ETHARP_HEADER_LEN
Ethernet Arp header length.
struct EtherAddrBytes bytes
const std::uint16_t IPV4_ADDR_LEN
ipv4 addr len
std::uint8_t get_hdrlen(const Ip4Header *ip)
std::uint8_t get_ip_version(std::uint8_t vhl)
const EtherAddr * get_dstaddr(const EtherHeader *eth)
std::uint16_t ethaddr4_to_id(const EtherAddr *addr)
const EtherAddr * get_srcaddr(const EtherHeader *eth)
std::uint32_t get_srcprotoaddr(const EtherArpHeader *arp)
std::uint16_t inet_cksum(const void *buf, int buflen, std::uint16_t prev=0)
const std::uint16_t ETH_ARPOP_REPLY
Ethernet arp reply.
Definition of the ethernet frame address as an array of 6 bytes or set of 3 words.
const EtherAddr * get_srchwaddr(const EtherArpHeader *arp)
const std::uint8_t IP6_ICMP_NEIGH_ADVERT
IPv6 ICMP Neighbor Advertisement.
std::uint8_t get_ip_hdrlen(std::uint8_t vhl)
const std::uint16_t IPV4_HEADER_LEN
ipv4 header len without options
const std::uint8_t IP_PROTO_UDP
ip udp protocol
std::uint16_t ethaddr6_to_id(const EtherAddr *addr)
const std::uint16_t ETH_ARPOP_REQUEST
Ethernet arp request.
const std::uint16_t ETH_ALEN
Ethernet hardware address length.
const std::uint16_t IPV6_ADDR_LEN
ipv6 addr len
Definition of the ethernet frame address as a set of 3 words.
void addr_to_string(const std::uint8_t *addr, size_t addrlen, const char *delim, char *buf, size_t buflen)
const std::uint16_t ARPHRD_ETHER
Ethernet hardware type.
std::string ethaddr_to_string(const EtherAddr *addr)
const std::uint8_t IPV6_P_ICMP
IPv6 ICMP Protocol.
std::uint8_t get_protoaddrlen(const EtherArpHeader *arp)
struct EMANE::Utils::UdpHeader __attribute__((packed))
std::uint8_t get_dscp(const Ip4Header *ip)
const std::uint16_t ETH_HEADER_LEN
Ethernet header length.
std::uint8_t Ipv6dst[IPV6_ADDR_LEN]
std::uint8_t buff[ETH_ALEN]
const std::uint8_t IP6_ICMP_NEIGH_SOLICIT
IPv6 ICMP Neighbor Soliciation.
const std::uint16_t ETH_P_IPV4
Ethernet ipv4 protocol.
const std::uint16_t IPV6_HEADER_LEN
ipv6 header len
std::uint8_t get_version(const Ip4Header *ip)
std::uint8_t get_prefixlen(const in6_addr *prefix)