Agora  1.2.0
Agora project
eth_common.h File Reference

Common definitons for Ethernet-based transports. More...

#include <arpa/inet.h>
#include <ifaddrs.h>
#include <linux/if_packet.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <cassert>
#include <sstream>
#include <string>
#include "utils.h"
Include dependency graph for eth_common.h:

Go to the source code of this file.

Classes

struct  eth_routing_info_t
 
struct  eth_hdr_t
 
struct  ipv4_hdr_t
 
struct  udp_hdr_t
 

Functions

static std::string mac_to_string (const uint8_t *mac)
 
static uint32_t ipv4_from_str (const char *ip)
 Get the network-byte-order IPv4 address from a human-readable IP string. More...
 
static std::string ipv4_to_string (uint32_t ipv4_addr)
 Convert a network-byte-order IPv4 address to a human-readable IP string. More...
 
struct eth_hdr_t __attribute__ ((packed))
 
std::string to_string () const
 
static std::string frame_header_to_string (const uint8_t *buf)
 
static void gen_eth_header (eth_hdr_t *eth_header, const uint8_t *src_mac, const uint8_t *dst_mac)
 Fill in Ethernet header eth_header using the source and destination MAC. More...
 
static void gen_ipv4_header (ipv4_hdr_t *ipv4_hdr, uint32_t src_ip, uint32_t dst_ip, uint16_t data_size)
 
static void gen_udp_header (udp_hdr_t *udp_hdr, uint16_t src_port, uint16_t dst_port, uint16_t data_size)
 
static uint32_t get_interface_ipv4_addr (const std::string &interface)
 Return the IPv4 address of a kernel-visible interface in host-byte order. More...
 
static void fill_interface_mac (const std::string &interface, uint8_t *mac)
 Fill the MAC address of kernel-visible interface. More...
 

Variables

static constexpr uint16_t kIPEtherType = 0x800
 
static constexpr uint16_t kIPHdrProtocol = 0x11
 
uint8_t dst_mac [6]
 
uint8_t src_mac [6]
 
uint16_t eth_type
 
uint8_t ihl
 
uint8_t version
 
uint8_t ecn
 
uint8_t dscp
 
uint16_t tot_len
 
uint16_t id
 
uint16_t frag_off
 
uint8_t ttl
 
uint8_t protocol
 
uint16_t check
 
uint32_t src_ip
 
uint32_t dst_ip
 
uint16_t src_port
 
uint16_t dst_port
 
uint16_t len
 
static constexpr size_t kInetHdrsTotSize
 

Detailed Description

Common definitons for Ethernet-based transports.

Function Documentation

◆ __attribute__()

struct eth_hdr_t __attribute__ ( (packed)  )

◆ fill_interface_mac()

static void fill_interface_mac ( const std::string &  interface,
uint8_t *  mac 
)
inlinestatic

Fill the MAC address of kernel-visible interface.

Here is the call graph for this function:

◆ frame_header_to_string()

static std::string frame_header_to_string ( const uint8_t *  buf)
inlinestatic

Return a string representation of the Ethernet + IPv4 + UDP frame headers starting at buf

Here is the call graph for this function:

◆ gen_eth_header()

static void gen_eth_header ( eth_hdr_t eth_header,
const uint8_t *  src_mac,
const uint8_t *  dst_mac 
)
inlinestatic

Fill in Ethernet header eth_header using the source and destination MAC.

◆ gen_ipv4_header()

static void gen_ipv4_header ( ipv4_hdr_t ipv4_hdr,
uint32_t  src_ip,
uint32_t  dst_ip,
uint16_t  data_size 
)
inlinestatic

Format the IPv4 header for a UDP packet. All value arguments are in host-byte order. data_size is the data payload size in the UDP packet.

◆ gen_udp_header()

static void gen_udp_header ( udp_hdr_t udp_hdr,
uint16_t  src_port,
uint16_t  dst_port,
uint16_t  data_size 
)
inlinestatic

Format the UDP header for a UDP packet. All value arguments are in host-byte order. data_size is the data payload size in the UDP packet.

◆ get_interface_ipv4_addr()

static uint32_t get_interface_ipv4_addr ( const std::string &  interface)
inlinestatic

Return the IPv4 address of a kernel-visible interface in host-byte order.

Here is the call graph for this function:

◆ ipv4_from_str()

static uint32_t ipv4_from_str ( const char *  ip)
inlinestatic

Get the network-byte-order IPv4 address from a human-readable IP string.

Here is the call graph for this function:

◆ ipv4_to_string()

static std::string ipv4_to_string ( uint32_t  ipv4_addr)
inlinestatic

Convert a network-byte-order IPv4 address to a human-readable IP string.

Here is the caller graph for this function:

◆ mac_to_string()

static std::string mac_to_string ( const uint8_t *  mac)
inlinestatic
Here is the caller graph for this function:

◆ to_string()

std::string to_string ( ) const

Variable Documentation

◆ check

uint16_t check

◆ dscp

uint8_t dscp

◆ dst_ip

uint32_t dst_ip

◆ dst_mac

uint8_t dst_mac[6]

◆ dst_port

uint16_t dst_port

◆ ecn

uint8_t ecn

◆ eth_type

uint16_t eth_type

◆ frag_off

uint16_t frag_off

◆ id

uint16_t id

◆ ihl

uint8_t ihl

◆ kInetHdrsTotSize

constexpr size_t kInetHdrsTotSize
staticconstexpr
Initial value:
=
sizeof(eth_hdr_t) + sizeof(ipv4_hdr_t) + sizeof(udp_hdr_t)

◆ kIPEtherType

constexpr uint16_t kIPEtherType = 0x800
staticconstexpr

◆ kIPHdrProtocol

constexpr uint16_t kIPHdrProtocol = 0x11
staticconstexpr

◆ len

uint16_t len

◆ protocol

uint8_t protocol

◆ src_ip

uint32_t src_ip

◆ src_mac

uint8_t src_mac[6]

◆ src_port

uint16_t src_port

◆ tot_len

uint16_t tot_len

◆ ttl

uint8_t ttl

◆ version

uint8_t version
eth_hdr_t
Definition: eth_common.h:86
udp_hdr_t
Definition: eth_common.h:128
ipv4_hdr_t
Definition: eth_common.h:100