gPTP Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
packet.hpp File Reference
#include "stdint.h"
Include dependency graph for packet.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  packet_addr_t
 

Macros

#define ETHER_ADDR_OCTETS   6
 
#define PACKET_HDR_LENGTH   14
 

Typedefs

typedef struct packet_handle * pfhandle_t
 

Enumerations

enum  packet_error_t {
  PACKET_NO_ERROR = 0, PACKET_NOMEMORY_ERROR, PACKET_BADBUFFER_ERROR, PACKET_XMIT_ERROR,
  PACKET_IFLOOKUP_ERROR, PACKET_IFNOTFOUND_ERROR, PACKET_CREATEMUTEX_ERROR, PACKET_GETMUTEX_ERROR,
  PACKET_RLSMUTEX_ERROR, PACKET_RECVTIMEOUT_ERROR, PACKET_RECVFAILED_ERROR, PACKET_BIND_ERROR
}
 

Functions

packet_error_t mallocPacketHandle (pfhandle_t *pfhandle_r)
 Allocate memory for the packet handle. More...
 
void freePacketHandle (pfhandle_t pfhandle)
 Close the packet handle. More...
 
packet_error_t openInterfaceByAddr (pfhandle_t pfhandle, packet_addr_t *addr, int timeout)
 Opens the interface by link layer address. Uses libpcap. More...
 
void closeInterface (pfhandle_t pfhandle)
 Close the interface. More...
 
packet_error_t sendFrame (pfhandle_t pfhandle, packet_addr_t *addr, uint16_t ethertype, uint8_t *payload, size_t length)
 Sends a frame through an interface using libpcap. More...
 
packet_error_t recvFrame (pfhandle_t pfhandle, packet_addr_t *addr, uint8_t *payload, size_t &length)
 Receives a frame. More...
 
packet_error_t packetBind (struct packet_handle *handle, uint16_t ethertype)
 Set filters for packet handler. More...
 

Macro Definition Documentation

#define ETHER_ADDR_OCTETS   6

Link layer number of octets

#define PACKET_HDR_LENGTH   14

Packet header length in bytes

Typedef Documentation

typedef struct packet_handle* pfhandle_t

Type to packet handle

Enumeration Type Documentation

Packet error enumeration. Possible values are:

  • PACKET_NO_ERROR;
  • PACKET_NOMEMORY_ERROR;
  • PACKET_BADBUFFER_ERROR;
  • PACKET_XMIT_ERROR;
  • PACKET_IFLOOKUP_ERROR;
  • PACKET_IFNOTFOUND_ERROR;
  • PACKET_CREATEMUTEX_ERROR;
  • PACKET_GETMUTEX_ERROR;
  • PACKET_RLSMUTEX_ERROR;
  • PACKET_RECVTIMEOUT_ERROR;
  • PACKET_RECVFAILED_ERROR;
  • PACKET_BIND_ERROR;

Function Documentation

void closeInterface ( pfhandle_t  pfhandle)

Close the interface.

Parameters
pfhandle[in] Packet interface handler
Returns
void
void freePacketHandle ( pfhandle_t  pfhandle)

Close the packet handle.

Parameters
pfhandle[in] Packet handler
Returns
void
packet_error_t mallocPacketHandle ( pfhandle_t pfhandle_r)

Allocate memory for the packet handle.

Parameters
pfhandle_r[inout] Packet handle type
Returns
void
packet_error_t openInterfaceByAddr ( pfhandle_t  pfhandle,
packet_addr_t addr,
int  timeout 
)

Opens the interface by link layer address. Uses libpcap.

Parameters
pfhandle[in] Packet interface handler
addrLink layer address
timeoutTimeout
Returns
Type packet_error_t with the error code
packet_error_t packetBind ( struct packet_handle *  handle,
uint16_t  ethertype 
)

Set filters for packet handler.

Parameters
handle[in] packet interface handler
ethertypeEthertype
Returns
packet_error_t error codes
packet_error_t recvFrame ( pfhandle_t  pfhandle,
packet_addr_t addr,
uint8_t *  payload,
size_t &  length 
)

Receives a frame.

Parameters
pfhandlePacket interface handler
addrLink layer address
payload[out] Data buffer
length[out] Data length
Returns
packet_error_t error codes
packet_error_t sendFrame ( pfhandle_t  pfhandle,
packet_addr_t addr,
uint16_t  ethertype,
uint8_t *  payload,
size_t  length 
)

Sends a frame through an interface using libpcap.

Parameters
pfhandlePacket Inteface handler
addr[in] Link layer address
ethertypeEthertype
payload[in] Data buffer
lengthData length
Returns
packet_error_t error codes