editcap: add sll and sll2 headers + offsetof
add sll and sll2 header structs to enable the usage of offsetof into the structs. mainly to make it clear on where to read and set data.
This commit is contained in:
parent
3e2c04fe78
commit
49b639e5ba
57
editcap.c
57
editcap.c
|
@ -23,6 +23,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
@ -543,36 +544,69 @@ set_rel_time(char *optarg_str_p)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LINUX_SLL_OFFSETP 14
|
#define SLL_ADDRLEN 8 /* length of address field */
|
||||||
|
struct sll_header {
|
||||||
|
uint16_t sll_pkttype; /* packet type */
|
||||||
|
uint16_t sll_hatype; /* link-layer address type */
|
||||||
|
uint16_t sll_halen; /* link-layer address length */
|
||||||
|
uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */
|
||||||
|
uint16_t sll_protocol; /* protocol */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sll2_header {
|
||||||
|
uint16_t sll2_protocol; /* protocol */
|
||||||
|
uint16_t sll2_reserved_mbz; /* reserved - must be zero */
|
||||||
|
uint32_t sll2_if_index; /* 1-based interface index */
|
||||||
|
uint16_t sll2_hatype; /* link-layer address type */
|
||||||
|
uint8_t sll2_pkttype; /* packet type */
|
||||||
|
uint8_t sll2_halen; /* link-layer address length */
|
||||||
|
uint8_t sll2_addr[SLL_ADDRLEN]; /* link-layer address */
|
||||||
|
};
|
||||||
|
|
||||||
#define VLAN_SIZE 4
|
#define VLAN_SIZE 4
|
||||||
static void
|
static void
|
||||||
sll_remove_vlan_info(guint8* fd, guint32* len) {
|
sll_remove_vlan_info(guint8* fd, guint32* len) {
|
||||||
if (pntoh16(fd + LINUX_SLL_OFFSETP) == ETHERTYPE_VLAN) {
|
if (pntoh16(fd + offsetof(struct sll_header, sll_protocol)) == ETHERTYPE_VLAN) {
|
||||||
int rest_len;
|
int rest_len;
|
||||||
/* point to start of vlan */
|
/* point to start of vlan */
|
||||||
fd = fd + LINUX_SLL_OFFSETP;
|
fd = fd + offsetof(struct sll_header, sll_protocol);
|
||||||
/* bytes to read after vlan info */
|
/* bytes to read after vlan info */
|
||||||
rest_len = *len - (LINUX_SLL_OFFSETP + VLAN_SIZE);
|
rest_len = *len - (offsetof(struct sll_header, sll_protocol) + VLAN_SIZE);
|
||||||
/* remove vlan info from packet */
|
/* remove vlan info from packet */
|
||||||
memmove(fd, fd + VLAN_SIZE, rest_len);
|
memmove(fd, fd + VLAN_SIZE, rest_len);
|
||||||
*len -= 4;
|
*len -= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LINUX_SLL_OFFSETLL 4
|
|
||||||
#define SLL_ADDRLEN 8 /* length of address field */
|
|
||||||
static void
|
static void
|
||||||
sll_set_unused_info(guint8* fd) {
|
sll_set_unused_info(guint8* fd) {
|
||||||
guint32 ha_len;
|
guint32 ha_len;
|
||||||
ha_len = pntoh16(fd + LINUX_SLL_OFFSETLL);
|
ha_len = pntoh16(fd + offsetof(struct sll_header, sll_halen));
|
||||||
|
|
||||||
if (ha_len < SLL_ADDRLEN) {
|
if (ha_len < SLL_ADDRLEN) {
|
||||||
int unused;
|
int unused;
|
||||||
unused = SLL_ADDRLEN - ha_len;
|
unused = SLL_ADDRLEN - ha_len;
|
||||||
/* point to start of LL address offset plus addr len 2 bytes */
|
/* point to end of sll_ddr */
|
||||||
fd = fd + LINUX_SLL_OFFSETLL + 2;
|
fd = fd + offsetof(struct sll_header, sll_addr) + ha_len;
|
||||||
/* set zeros in the unused data */
|
/* set zeros in the unused data */
|
||||||
memset(fd + ha_len, 0, unused);
|
memset(fd, 0, unused);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sll2_set_unused_info(guint8* fd) {
|
||||||
|
guint32 ha_len;
|
||||||
|
ha_len = *(fd + offsetof(struct sll2_header, sll2_halen));
|
||||||
|
|
||||||
|
if (ha_len < SLL_ADDRLEN) {
|
||||||
|
int unused;
|
||||||
|
unused = SLL_ADDRLEN - ha_len;
|
||||||
|
/* point to end of sll2_addr */
|
||||||
|
fd = fd + offsetof(struct sll2_header, sll2_addr) + ha_len;
|
||||||
|
/* set zeros in the unused data */
|
||||||
|
memset(fd, 0, unused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,6 +628,9 @@ set_unused_info(const wtap_packet_header *phdr, guint8* fd) {
|
||||||
case WTAP_ENCAP_SLL:
|
case WTAP_ENCAP_SLL:
|
||||||
sll_set_unused_info(fd);
|
sll_set_unused_info(fd);
|
||||||
break;
|
break;
|
||||||
|
case WTAP_ENCAP_SLL2:
|
||||||
|
sll2_set_unused_info(fd);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
/* no support for current pkt_encap */
|
/* no support for current pkt_encap */
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue