Changeset 988 for vendor/current/source3/utils/log2pcaphex.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/utils/log2pcaphex.c
r740 r988 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Utility to extract pcap files from samba (log level 10) log files … … 75 75 /* tcpdump file format */ 76 76 struct tcpdump_file_header { 77 uint32 magic;78 uint16 major;79 uint16 minor;80 int32 zone;81 uint32 sigfigs;82 uint32 snaplen;83 uint32 linktype;77 uint32_t magic; 78 uint16_t major; 79 uint16_t minor; 80 int32_t zone; 81 uint32_t sigfigs; 82 uint32_t snaplen; 83 uint32_t linktype; 84 84 }; 85 85 86 86 struct tcpdump_packet { 87 87 struct timeval ts; 88 uint32 caplen;89 uint32 len;88 uint32_t caplen; 89 uint32_t len; 90 90 }; 91 91 92 92 typedef struct { 93 uint8 ver_hdrlen;94 uint8 dscp;95 uint16 packet_length;96 uint16 identification;97 uint8 flags;98 uint8 fragment;99 uint8 ttl;100 uint8 protocol;101 uint16 hdr_checksum;102 uint32 src_addr;103 uint32 dest_addr;93 uint8_t ver_hdrlen; 94 uint8_t dscp; 95 uint16_t packet_length; 96 uint16_t identification; 97 uint8_t flags; 98 uint8_t fragment; 99 uint8_t ttl; 100 uint8_t protocol; 101 uint16_t hdr_checksum; 102 uint32_t src_addr; 103 uint32_t dest_addr; 104 104 } hdr_ip_t; 105 105 … … 107 107 108 108 typedef struct { 109 uint16 source_port;110 uint16 dest_port;111 uint32 seq_num;112 uint32 ack_num;113 uint8 hdr_length;114 uint8 flags;115 uint16 window;116 uint16 checksum;117 uint16 urg;109 uint16_t source_port; 110 uint16_t dest_port; 111 uint32_t seq_num; 112 uint32_t ack_num; 113 uint8_t hdr_length; 114 uint8_t flags; 115 uint16_t window; 116 uint16_t checksum; 117 uint16_t urg; 118 118 } hdr_tcp_t; 119 119 … … 155 155 fprintf(out, "%02x ", data[i]); 156 156 } 157 158 157 cur = i; 159 158 fprintf(out, "\n"); … … 163 162 static void print_netbios_packet(FILE *out, unsigned char *data, long length, 164 163 long actual_length) 165 { 164 { 166 165 unsigned char *newdata; long offset = 0; 167 166 long newlen; 168 167 169 168 newlen = length+sizeof(HDR_IP)+sizeof(HDR_TCP); 170 169 newdata = (unsigned char *)malloc(newlen); … … 177 176 memcpy(newdata+offset, &HDR_TCP, sizeof(HDR_TCP));offset+=sizeof(HDR_TCP); 178 177 memcpy(newdata+offset,data,length); 179 178 180 179 print_pcap_packet(out, newdata, newlen, actual_length+offset); 181 180 free(newdata); … … 297 296 } 298 297 299 int main (int argc,char **argv)298 int main(int argc, const char **argv) 300 299 { 301 300 const char *infile, *outfile; … … 313 312 POPT_TABLEEND 314 313 }; 315 316 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,314 315 pc = poptGetContext(NULL, argc, argv, long_options, 317 316 POPT_CONTEXT_KEEP_FIRST); 318 317 poptSetOtherOptionHelp(pc, "[<infile> [<outfile>]]"); 319 320 318 319 321 320 while((opt = poptGetNextOpt(pc)) != -1) { 322 321 switch (opt) { … … 335 334 } 336 335 } else in = stdin; 337 336 338 337 outfile = poptGetArg(pc); 339 338 340 339 if(outfile) { 341 340 out = fopen(outfile, "w+"); 342 if(!out) { 343 perror("fopen"); 341 if(!out) { 342 perror("fopen"); 344 343 fprintf(stderr, "Can't find %s, using stdout...\n", outfile); 345 344 return 1; … … 360 359 } else if(in_packet && strstr(buffer, "dump_data")) { 361 360 data_bytes_read = read_log_data(in, curpacket+data_offset, data_length); 362 } else { 363 if(in_packet){ 364 if(hexformat) print_hex_packet(out, curpacket, curpacket_len); 361 } else { 362 if(in_packet){ 363 if(hexformat) print_hex_packet(out, curpacket, curpacket_len); 365 364 else print_netbios_packet(out, curpacket, curpacket_len, data_bytes_read+data_offset); 366 free(curpacket); 365 free(curpacket); 367 366 } 368 367 in_packet = 0; 369 368 } 370 } 369 } 371 370 } 372 371
Note:
See TracChangeset
for help on using the changeset viewer.