diff options
Diffstat (limited to 'src/vnet/unix/pcap2pg.c')
-rw-r--r-- | src/vnet/unix/pcap2pg.c | 115 |
1 files changed, 61 insertions, 54 deletions
diff --git a/src/vnet/unix/pcap2pg.c b/src/vnet/unix/pcap2pg.c index 217a61f4cb4..46d6bfcd0c7 100644 --- a/src/vnet/unix/pcap2pg.c +++ b/src/vnet/unix/pcap2pg.c @@ -28,12 +28,10 @@ pcap_main_t pcap_main; /** * @brief char * to seed a PG file */ -static char * pg_fmt = +static char *pg_fmt = "packet-generator new {\n" " name s%d\n" - " limit 1\n" - " size %d-%d\n" - " node ethernet-input\n"; + " limit 1\n" " size %d-%d\n" " node ethernet-input\n"; /** @@ -43,9 +41,10 @@ static char * pg_fmt = * @param i - int * @param *pkt - u8 */ -void stream_boilerplate (FILE *ofp, int i, u8 * pkt) +void +stream_boilerplate (FILE * ofp, int i, u8 * pkt) { - fformat(ofp, pg_fmt, i, vec_len(pkt), vec_len(pkt)); + fformat (ofp, pg_fmt, i, vec_len (pkt), vec_len (pkt)); } /** @@ -57,7 +56,8 @@ void stream_boilerplate (FILE *ofp, int i, u8 * pkt) * @return rc - int * */ -int pcap2pg (pcap_main_t * pm, FILE *ofp) +int +pcap2pg (pcap_main_t * pm, FILE * ofp) { int i, j; u8 *pkt; @@ -65,11 +65,11 @@ int pcap2pg (pcap_main_t * pm, FILE *ofp) for (i = 0; i < vec_len (pm->packets_read); i++) { int offset; - ethernet_header_t * h; + ethernet_header_t *h; u64 ethertype; pkt = pm->packets_read[i]; - h = (ethernet_header_t *)pkt; + h = (ethernet_header_t *) pkt; stream_boilerplate (ofp, i, pkt); @@ -83,36 +83,34 @@ int pcap2pg (pcap_main_t * pm, FILE *ofp) * This transforms captured 802.1q VLAN packets into * regular Ethernet packets. */ - if (ethertype == 0x8100 /* 802.1q vlan */) - { - u16 * vlan_ethertype = (u16 *)(h+1); - ethertype = clib_net_to_host_u16(vlan_ethertype[0]); - offset = 18; - } + if (ethertype == 0x8100 /* 802.1q vlan */ ) + { + u16 *vlan_ethertype = (u16 *) (h + 1); + ethertype = clib_net_to_host_u16 (vlan_ethertype[0]); + offset = 18; + } else - offset = 14; + offset = 14; fformat (ofp, - " 0x%04x: %02x%02x.%02x%02x.%02x%02x" - " -> %02x%02x.%02x%02x.%02x%02x\n", - ethertype, - h->src_address[0], - h->src_address[1], - h->src_address[2], - h->src_address[3], - h->src_address[4], - h->src_address[5], - h->dst_address[0], - h->dst_address[1], - h->dst_address[2], - h->dst_address[3], - h->dst_address[4], - h->dst_address[5]); + " 0x%04x: %02x%02x.%02x%02x.%02x%02x" + " -> %02x%02x.%02x%02x.%02x%02x\n", + ethertype, + h->src_address[0], + h->src_address[1], + h->src_address[2], + h->src_address[3], + h->src_address[4], + h->src_address[5], + h->dst_address[0], + h->dst_address[1], + h->dst_address[2], + h->dst_address[3], h->dst_address[4], h->dst_address[5]); fformat (ofp, " hex 0x"); for (j = offset; j < vec_len (pkt); j++) - fformat (ofp, "%02x", pkt[j]); + fformat (ofp, "%02x", pkt[j]); fformat (ofp, " }\n"); fformat (ofp, "}\n\n"); @@ -124,37 +122,38 @@ int pcap2pg (pcap_main_t * pm, FILE *ofp) * @brief pcap2pg. * usage: pcap2pg -i <input-file> [-o <output-file>] */ -int main (int argc, char **argv) +int +main (int argc, char **argv) { unformat_input_t input; - pcap_main_t * pm = &pcap_main; - u8 * input_file = 0, * output_file = 0; - FILE * ofp; - clib_error_t * error; + pcap_main_t *pm = &pcap_main; + u8 *input_file = 0, *output_file = 0; + FILE *ofp; + clib_error_t *error; unformat_init_command_line (&input, argv); while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) { - if (unformat(&input, "-i %s", &input_file) - || unformat (&input, "input %s", &input_file)) - ; + if (unformat (&input, "-i %s", &input_file) + || unformat (&input, "input %s", &input_file)) + ; else if (unformat (&input, "-o %s", &output_file) - || unformat (&input, "output %s", &output_file)) - ; - else - { - usage: - fformat(stderr, - "usage: pcap2pg -i <input-file> [-o <output-file>]\n"); - exit (1); - } + || unformat (&input, "output %s", &output_file)) + ; + else + { + usage: + fformat (stderr, + "usage: pcap2pg -i <input-file> [-o <output-file>]\n"); + exit (1); + } } if (input_file == 0) goto usage; - - pm->file_name = (char *)input_file; + + pm->file_name = (char *) input_file; error = pcap_read (pm); if (error) @@ -165,18 +164,26 @@ int main (int argc, char **argv) if (output_file) { - ofp = fopen ((char *)output_file, "rw"); + ofp = fopen ((char *) output_file, "rw"); if (ofp == NULL) - clib_unix_warning ("Couldn't create '%s'", output_file); + clib_unix_warning ("Couldn't create '%s'", output_file); exit (1); } else { ofp = stdout; } - + pcap2pg (pm, ofp); fclose (ofp); exit (0); } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |