Skip to content

Commit fdf4d55

Browse files
authored
Merge pull request #39 from space-jam-/fix-pcap_modify-compile-warning
fix GCC compile warning when accessing address of packed struct member
2 parents 849e826 + faafed2 commit fdf4d55

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

tools/data_structs/vlan_ethhdr.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdint.h>
2+
13
typedef struct vlan_ethhdr {
24
uint64_t h_dest : 48;
35
uint64_t h_source : 48;

tools/exact-pcap-modify.c

+12-14
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
#include <stddef.h>
3030
#include <netinet/udp.h>
3131
#include <netinet/tcp.h>
32+
#include <sys/socket.h>
33+
#include <arpa/inet.h>
3234

3335
#include <chaste/types/types.h>
34-
#include <chaste/data_structs/vector/vector_std.h>
3536
#include <chaste/options/options.h>
3637
#include <chaste/log/log.h>
3738
#include <chaste/parsing/numeric_parser.h>
39+
#include <chaste/utils/util.h>
3840

39-
#include "data_structs/pthread_vec.h"
40-
#include "data_structs/eiostream_vec.h"
4141
#include "data_structs/pcap-structures.h"
42+
#include "data_structs/vlan_ethhdr.h"
4243

4344
#include "data_structs/expcap.h"
4445
#include "checksum.h"
@@ -83,14 +84,6 @@ typedef struct {
8384
uint64_t pkt_idx;
8485
} buff_t;
8586

86-
struct vlan_ethhdr {
87-
unsigned char h_dest[ETH_ALEN];
88-
unsigned char h_source[ETH_ALEN];
89-
__be16 h_vlan_proto;
90-
__be16 h_vlan_TCI;
91-
__be16 h_vlan_encapsulated_proto;
92-
};
93-
9487
struct port_hdr {
9588
uint16_t src;
9689
uint16_t dst;
@@ -509,16 +502,21 @@ int main(int argc, char** argv)
509502
struct vlan_ethhdr old_vlan_hdr = {0};
510503
struct vlan_ethhdr new_vlan_hdr = {0};
511504
if(options.vlan){
512-
if (parse_vlan_opt(options.vlan, &old_vlan_hdr.h_vlan_TCI, &new_vlan_hdr.h_vlan_TCI) == -1){
505+
uint16_t old_vlan_TCI = 0;
506+
uint16_t new_vlan_TCI = 0;
507+
if (parse_vlan_opt(options.vlan, &old_vlan_TCI, &new_vlan_TCI) == -1){
513508
ch_log_fatal("Failed to parse VLAN tag: %s\n", options.vlan);
514509
}
515510
filter.bits.vlan = 1;
516511

512+
old_vlan_hdr.h_vlan_TCI = old_vlan_TCI;
513+
new_vlan_hdr.h_vlan_TCI = new_vlan_TCI;
514+
517515
/* If an old vlan tag was specified, proto is 8021q */
518-
old_vlan_hdr.h_vlan_proto = old_vlan_hdr.h_vlan_TCI ? htobe16(ETH_P_8021Q) : htobe16(ETH_P_IP);
516+
old_vlan_hdr.h_vlan_proto = old_vlan_TCI ? htobe16(ETH_P_8021Q) : htobe16(ETH_P_IP);
519517

520518
/* If a new vlan tag was specified, proto is 8021q, encapsulate IP */
521-
new_vlan_hdr.h_vlan_proto = new_vlan_hdr.h_vlan_TCI ? htobe16(ETH_P_8021Q) : htobe16(ETH_P_IP);
519+
new_vlan_hdr.h_vlan_proto = new_vlan_TCI ? htobe16(ETH_P_8021Q) : htobe16(ETH_P_IP);
522520
new_vlan_hdr.h_vlan_encapsulated_proto = htobe16(ETH_P_IP);
523521
}
524522

0 commit comments

Comments
 (0)