|
29 | 29 | #include <stddef.h>
|
30 | 30 | #include <netinet/udp.h>
|
31 | 31 | #include <netinet/tcp.h>
|
| 32 | +#include <sys/socket.h> |
| 33 | +#include <arpa/inet.h> |
32 | 34 |
|
33 | 35 | #include <chaste/types/types.h>
|
34 |
| -#include <chaste/data_structs/vector/vector_std.h> |
35 | 36 | #include <chaste/options/options.h>
|
36 | 37 | #include <chaste/log/log.h>
|
37 | 38 | #include <chaste/parsing/numeric_parser.h>
|
| 39 | +#include <chaste/utils/util.h> |
38 | 40 |
|
39 |
| -#include "data_structs/pthread_vec.h" |
40 |
| -#include "data_structs/eiostream_vec.h" |
41 | 41 | #include "data_structs/pcap-structures.h"
|
| 42 | +#include "data_structs/vlan_ethhdr.h" |
42 | 43 |
|
43 | 44 | #include "data_structs/expcap.h"
|
44 | 45 | #include "checksum.h"
|
@@ -83,14 +84,6 @@ typedef struct {
|
83 | 84 | uint64_t pkt_idx;
|
84 | 85 | } buff_t;
|
85 | 86 |
|
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 |
| - |
94 | 87 | struct port_hdr {
|
95 | 88 | uint16_t src;
|
96 | 89 | uint16_t dst;
|
@@ -509,16 +502,21 @@ int main(int argc, char** argv)
|
509 | 502 | struct vlan_ethhdr old_vlan_hdr = {0};
|
510 | 503 | struct vlan_ethhdr new_vlan_hdr = {0};
|
511 | 504 | 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){ |
513 | 508 | ch_log_fatal("Failed to parse VLAN tag: %s\n", options.vlan);
|
514 | 509 | }
|
515 | 510 | filter.bits.vlan = 1;
|
516 | 511 |
|
| 512 | + old_vlan_hdr.h_vlan_TCI = old_vlan_TCI; |
| 513 | + new_vlan_hdr.h_vlan_TCI = new_vlan_TCI; |
| 514 | + |
517 | 515 | /* 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); |
519 | 517 |
|
520 | 518 | /* 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); |
522 | 520 | new_vlan_hdr.h_vlan_encapsulated_proto = htobe16(ETH_P_IP);
|
523 | 521 | }
|
524 | 522 |
|
|
0 commit comments