libnet
libnet的結構眾多,幾乎都是封包表頭,這裡無法一一列出(因為很佔空間),只會把主要需要的列出。
地址相關
/*
* IPv6 address
*/
struct libnet_in6_addr
{
union
{
uint8_t __u6_addr8[16];
uint16_t __u6_addr16[8];
uint32_t __u6_addr32[4];
} __u6_addr; /* 128-bit IP6 address */
};
#define libnet_s6_addr __u6_addr.__u6_addr8
- 說明:IPv6網路順序地址結構。
- 成員:
- __u6_addr:一個聯合體(union),基本上就是一個128 bits長度的欄位資料。
libnet核心相關
/*
* Libnet context
* Opaque structure. Nothing in here should ever been touched first hand by
* the applications programmer.
*/
struct libnet_context
{
#if ((__WIN32__) && !(__CYGWIN__))
SOCKET fd;
LPADAPTER lpAdapter;
#else
int fd; /* file descriptor of packet device */
#endif
int injection_type; /* one of: */
#define LIBNET_NONE 0xf8 /* no injection type, only construct packets */
#define LIBNET_LINK 0x00 /* link-layer interface */
#define LIBNET_RAW4 0x01 /* raw socket interface (ipv4) */
#define LIBNET_RAW6 0x02 /* raw socket interface (ipv6) */
/* the following should actually set a flag in the flags variable above */
#define LIBNET_LINK_ADV 0x08 /* advanced mode link-layer */
#define LIBNET_RAW4_ADV 0x09 /* advanced mode raw socket (ipv4) */
#define LIBNET_RAW6_ADV 0x0a /* advanced mode raw socket (ipv6) */
#define LIBNET_ADV_MASK 0x08 /* mask to determine adv mode */
/* _blocks is the highest level, and _end is closest to link-level */
libnet_pblock_t *protocol_blocks; /* protocol headers / data */
libnet_pblock_t *pblock_end; /* last node in list */
uint32_t n_pblocks; /* number of pblocks */
int link_type; /* link-layer type, a DLT_ value. */
/* These are the only values used by libnet (see libnet_build_arp and
* libnet_build_link). Other values are assigned by the various
* libnet_link_*.c OS support functions, but are not yet used or supported,
* they are effectively dead code. <pcap.h> claims these two are invariant
* across operating systems... hopefully it is correct!
*/
#ifndef DLT_EN10MB
# define DLT_EN10MB 1 /* Ethernet (10Mb) */
#endif
#ifndef DLT_IEEE802
# define DLT_IEEE802 6 /* IEEE 802 Networks */
#endif
int link_offset; /* link-layer header size */
int aligner; /* used to align packets */
char *device; /* device name */
struct libnet_stats stats; /* statistics */
libnet_ptag_t ptag_state; /* state holder for pblock tag */
char label[LIBNET_LABEL_SIZE]; /* textual label for cq interface */
char err_buf[LIBNET_ERRBUF_SIZE]; /* error buffer */
uint32_t total_size; /* total size */
};
typedef struct libnet_context libnet_t;
- 說明:這個結構體就是
libnet_t
,我們不能直接使用結構體內的成員,必須透過libnet提供的其他函數操作。
/*
* Libnet context queue structure
* Opaque structure. Nothing in here should ever been touched first hand by
* the applications programmer.
*/
typedef struct _libnet_context_queue libnet_cq_t;
struct _libnet_context_queue
{
libnet_t *context; /* pointer to libnet context */
libnet_cq_t *next; /* next node in the list */
libnet_cq_t *prev; /* previous node in the list */
};
struct _libnet_context_queue_descriptor
{
uint32_t node; /* number of nodes in the list */
uint32_t cq_lock; /* lock status */
libnet_cq_t *current; /* current context */
};
typedef struct _libnet_context_queue_descriptor libnet_cqd_t;
- 說明:這個結構體就是libnet handle鏈結串列,必須透過libnet提供的其他函數操作。
/* port list chain structure */
typedef struct libnet_port_list_chain libnet_plist_t;
struct libnet_port_list_chain
{
uint16_t node; /* node number */
uint16_t bport; /* beggining port */
uint16_t eport; /* terminating port */
uint8_t id; /* global array offset */
libnet_plist_t *next; /* next node in the list */
};
- 說明:這個結構體就是
libnet_plist_t
,我們不能直接使用結構體內的成員,必須透過libnet提供的其他函數操作。
/* libnet statistics structure */
struct libnet_stats
{
#if (!defined(__WIN32__) || (__CYGWIN__))
uint64_t packets_sent; /* packets sent */
uint64_t packet_errors; /* packets errors */
uint64_t bytes_written; /* bytes written */
#else
__int64 packets_sent; /* packets sent */
__int64 packet_errors; /* packets errors */
__int64 bytes_written; /* bytes written */
#endif
};
- 說明:libnet handle送出封包狀態結構,需要搭配函數
libnet_stats()
使用。 - 成員:
- packets_sent:封包總共送出幾個。
- packet_errors:幾個封包再送出時發生錯誤。
- bytes_written:封包總共送出多少bytes。