A Discrete-Event Network Simulator
API
Macros | Functions | Variables
tap-creator.cc File Reference
#include <unistd.h>
#include <stdint.h>
#include <string>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <cerrno>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <net/route.h>
#include <netinet/in.h>
#include "tap-encode-decode.h"

Go to the source code of this file.

Macros

#define ABORT(msg, printErrno)
 
#define ABORT_IF(cond, msg, printErrno)
 
#define ASCII_a   (0x41)
 
#define ASCII_A   (0x61)
 
#define ASCII_COLON   (0x3a)
 
#define ASCII_DOT   (0x2e)
 
#define ASCII_z   (0x5a)
 
#define ASCII_Z   (0x7a)
 
#define ASCII_ZERO   (0x30)
 
#define ASCII_ZERO   (0x30)
 
#define LOG(msg)
 
#define TAP_MAGIC   95549
 

Functions

static uint32_t AsciiToIpv4 (const char *address)
 
static char AsciiToLowCase (char c)
 
static void AsciiToMac48 (const char *str, uint8_t addr[6])
 
static sockaddr CreateInetAddress (uint32_t networkOrder)
 
static int CreateTap (const char *dev, const char *gw, const char *ip, const char *mac, const char *mode, const char *netmask)
 
static void SendSocket (const char *path, int fd)
 

Variables

static int gVerbose = 0
 

Macro Definition Documentation

◆ ABORT

#define ABORT (   msg,
  printErrno 
)
Value:
std::cout << __FILE__ << ": fatal error at line " << __LINE__ << ": " << __FUNCTION__ << "(): " << msg << std::endl; \
if (printErrno) \
{ \
std::cout << " errno = " << errno << " (" << std::strerror (errno) << ")" << std::endl; \
} \
std::exit (-1);

Definition at line 50 of file tap-creator.cc.

◆ ABORT_IF

#define ABORT_IF (   cond,
  msg,
  printErrno 
)
Value:
if (cond) \
{ \
ABORT (msg, printErrno); \
}

Definition at line 58 of file tap-creator.cc.

Referenced by CreateTap(), and SendSocket().

◆ ASCII_a

#define ASCII_a   (0x41)

Definition at line 69 of file tap-creator.cc.

Referenced by AsciiToLowCase(), and AsciiToMac48().

◆ ASCII_A

#define ASCII_A   (0x61)

Definition at line 71 of file tap-creator.cc.

Referenced by AsciiToLowCase().

◆ ASCII_COLON

#define ASCII_COLON   (0x3a)

Definition at line 73 of file tap-creator.cc.

Referenced by AsciiToMac48().

◆ ASCII_DOT

#define ASCII_DOT   (0x2e)

Definition at line 67 of file tap-creator.cc.

Referenced by AsciiToIpv4().

◆ ASCII_z

#define ASCII_z   (0x5a)

Definition at line 70 of file tap-creator.cc.

Referenced by AsciiToLowCase().

◆ ASCII_Z

#define ASCII_Z   (0x7a)

Definition at line 72 of file tap-creator.cc.

Referenced by AsciiToLowCase().

◆ ASCII_ZERO [1/2]

#define ASCII_ZERO   (0x30)

Definition at line 74 of file tap-creator.cc.

Referenced by AsciiToIpv4(), and AsciiToMac48().

◆ ASCII_ZERO [2/2]

#define ASCII_ZERO   (0x30)

Definition at line 74 of file tap-creator.cc.

◆ LOG

#define LOG (   msg)
Value:
if (gVerbose) \
{ \
std::cout << __FUNCTION__ << "(): " << msg << std::endl; \
}
static int gVerbose
Definition: tap-creator.cc:42

Definition at line 44 of file tap-creator.cc.

Referenced by CreateTap(), and SendSocket().

◆ TAP_MAGIC

#define TAP_MAGIC   95549

Definition at line 40 of file tap-creator.cc.

Referenced by SendSocket().

Function Documentation

◆ AsciiToIpv4()

static uint32_t AsciiToIpv4 ( const char *  address)
static

Definition at line 89 of file tap-creator.cc.

References first::address, ASCII_DOT, and ASCII_ZERO.

Referenced by CreateTap().

◆ AsciiToLowCase()

static char AsciiToLowCase ( char  c)
static

Definition at line 77 of file tap-creator.cc.

References ASCII_a, ASCII_A, ASCII_z, and ASCII_Z.

Referenced by AsciiToMac48().

◆ AsciiToMac48()

static void AsciiToMac48 ( const char *  str,
uint8_t  addr[6] 
)
static

Definition at line 111 of file tap-creator.cc.

References ASCII_a, ASCII_COLON, ASCII_ZERO, and AsciiToLowCase().

Referenced by CreateTap().

◆ CreateInetAddress()

static sockaddr CreateInetAddress ( uint32_t  networkOrder)
static

Definition at line 142 of file tap-creator.cc.

Referenced by CreateTap().

◆ CreateTap()

static int CreateTap ( const char *  dev,
const char *  gw,
const char *  ip,
const char *  mac,
const char *  mode,
const char *  netmask 
)
static

Definition at line 277 of file tap-creator.cc.

References ABORT_IF, AsciiToIpv4(), AsciiToMac48(), CreateInetAddress(), LOG, and third::mac.

◆ SendSocket()

static void SendSocket ( const char *  path,
int  fd 
)
static

Definition at line 155 of file tap-creator.cc.

References ABORT_IF, LOG, TAP_MAGIC, and ns3::TapStringToBuffer().

Variable Documentation

◆ gVerbose

int gVerbose = 0
static

Definition at line 42 of file tap-creator.cc.