From 273c37d1c1a41b5edeb9f559dae7c934cfaf0904 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Aug 2003 00:00:22 +0000 Subject: Makefile.in (This used to be commit e8dc799ffbc4e622eb6adf374bbafc34724c24ce) --- source3/utils/log2pcaphex.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 source3/utils/log2pcaphex.c (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c new file mode 100644 index 0000000000..790c699c55 --- /dev/null +++ b/source3/utils/log2pcaphex.c @@ -0,0 +1,164 @@ +/* +Unix SMB/CIFS implementation. +Utility to extract pcap files from samba (log level 10) log files + +Copyright (C) Jelmer Vernooij 2003 +Thanks to Tim Potter for the genial idea + +Example use: log2pcaphex < samba-log-file | text2pcap -T 139,139 - foo.pcap + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include + + +#define itoa(a) ((a) < 0xa?'0'+(a):'A' + (a-0xa)) + +void print_packet(FILE *out, char *data, long length) +{ +long i,cur = 0;int tmp; +while(cur < length) { + fprintf(out, "%06X ", cur); + for(i = cur; i < length && i < cur + 16; i++) { + fprintf(out, "%02x ", (unsigned char)data[i]); + } + + cur = i; + fprintf(out, "\n"); +} +} + +char *curpacket = NULL; +long curpacket_len = 0; + +long read_log_msg(FILE *in, char **_buffer, long *buffersize) +{ + char *buffer; + int tmp; long i; + assert(fscanf(in, " size=%d\n", buffersize)); + *buffersize+=4; /* for netbios */ + buffer = malloc(*buffersize); + memset(buffer, 0, *buffersize); + /* NetBIOS */ + buffer[0] = 0x00; + buffer[1] = 0x00; + memcpy(buffer+2, &buffersize, 2); + buffer[4] = 0xFF; + buffer[5] = 'S'; + buffer[6] = 'M'; + buffer[7] = 'B'; + assert(fscanf(in, " smb_com=0x%x\n", &tmp)); buffer[smb_com] = tmp; + assert(fscanf(in, " smb_rcls=%d\n", &tmp)); buffer[smb_rcls] = tmp; + assert(fscanf(in, " smb_reh=%d\n", &tmp)); buffer[smb_reh] = tmp; + assert(fscanf(in, " smb_err=%d\n", &tmp)); memcpy(buffer+smb_err, &tmp, 2); + assert(fscanf(in, " smb_flg=%d\n", &tmp)); buffer[smb_flg] = tmp; + assert(fscanf(in, " smb_flg2=%d\n", &tmp)); memcpy(buffer+smb_flg2, &tmp, 2); + assert(fscanf(in, " smb_tid=%d\n", &tmp)); memcpy(buffer+smb_tid, &tmp, 2); + assert(fscanf(in, " smb_pid=%d\n", &tmp)); memcpy(buffer+smb_pid, &tmp, 2); + assert(fscanf(in, " smb_uid=%d\n", &tmp)); memcpy(buffer+smb_uid, &tmp, 2); + assert(fscanf(in, " smb_mid=%d\n", &tmp)); memcpy(buffer+smb_mid, &tmp, 2); + assert(fscanf(in, " smt_wct=%d\n", &tmp)); buffer[smb_wct] = tmp; + for(i = 0; i < buffer[smb_wct]; i++) { + assert(fscanf(in, " smb_vwv[%*2d]=%*5d (0x%X)\n", &tmp)); + memcpy(buffer+smb_vwv+i*2, &tmp, 2); + } + + assert(fscanf(in, " smb_bcc=%d\n", &tmp)); memcpy(buffer+smb_vwv+(1+buffer[smb_wct])*2, &tmp, 2); + *_buffer = buffer; + return tmp; +} + +void read_log_data(FILE *in, char *buffer, long *buffersize, long data_offset) +{ + int addr, b[16]; long i,j; + for(i = *buffersize-data_offset; i < *buffersize; i++) { + fscanf(in, " [%x] %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", &addr, &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &b[10], &b[11], &b[12], &b[13], &b[14], &b[15]); + for(j = i; j < 16 && j < *buffersize; j++) buffer[j] = b[j-i]; + } +} + +int main (int argc, char **argv) +{ + const char *infile, *outfile; + FILE *out, *in; + int opt; + int c; + poptContext pc; + char buffer[4096]; + long data_offset; + int in_packet = 0; + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_TABLEEND + }; + + pc = poptGetContext(NULL, argc, (const char **) argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + poptSetOtherOptionHelp(pc, "[ []]"); + + + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + } + } + + poptGetArg(pc); /* Drop argv[0], the program name */ + + infile = poptGetArg(pc); + + if(infile) { + in = fopen(infile, "r"); + if(!in) { + perror("fopen"); + return 1; + } + } else in = stdin; + + outfile = poptGetArg(pc); + + if(outfile) { + out = fopen(outfile, "w+"); + if(!out) { + perror("fopen"); + fprintf(stderr, "Can't find %s, using stdout...\n", outfile); + } + } + + if(!outfile) out = stdout; + + while(!feof(in)) { + + fgets(buffer, sizeof(buffer), in); + if(buffer[0] == '[') { /* Header */ + if(strstr(buffer, "show_msg")) { + in_packet++; + if(in_packet == 1)continue; + data_offset = read_log_msg(in, &curpacket, &curpacket_len); + } else if(in_packet && strstr(buffer, "dump_data")) { + read_log_data(in, curpacket, &curpacket_len, data_offset); + } else { + if(in_packet){ + print_packet(out, curpacket, curpacket_len); + free(curpacket); + } + in_packet = 0; + } + } + } + + return 0; +} -- cgit From 6c396ea5772c26edf8a6b1b5bc295e3675e10e06 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Aug 2003 00:04:20 +0000 Subject: Add utility that takes a samba log file (at least level 5 for headers and 10 for data contents as well) and creates a packet trace readable by ethereal. What does not work yet: - SMB data contents (log level 5) - SMB data contents beyond the 512 byte range (log level 99 or something?) (This used to be commit 95b1d4933b0de63613fe041c273d413d86909b4b) --- source3/utils/log2pcaphex.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 790c699c55..ba5082da1e 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -1,25 +1,25 @@ /* -Unix SMB/CIFS implementation. -Utility to extract pcap files from samba (log level 10) log files + Unix SMB/CIFS implementation. + Utility to extract pcap files from samba (log level 10) log files -Copyright (C) Jelmer Vernooij 2003 -Thanks to Tim Potter for the genial idea + Copyright (C) Jelmer Vernooij 2003 + Thanks to Tim Potter for the genial idea -Example use: log2pcaphex < samba-log-file | text2pcap -T 139,139 - foo.pcap + Example use: log2pcaphex < samba-log-file | text2pcap -T 139,139 - foo.pcap -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" -- cgit From c8061de1ed533327eb9fb6cc83b11a66699bf958 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Aug 2003 01:30:10 +0000 Subject: Get packet contents correct as well. (This used to be commit b4499c8aab44e25cb4406498018bde0bc4ed4ca9) --- source3/utils/log2pcaphex.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index ba5082da1e..f2f51dee85 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -45,7 +45,7 @@ while(cur < length) { char *curpacket = NULL; long curpacket_len = 0; -long read_log_msg(FILE *in, char **_buffer, long *buffersize) +void read_log_msg(FILE *in, char **_buffer, long *buffersize, long *data_offset, long *data_length) { char *buffer; int tmp; long i; @@ -77,17 +77,24 @@ long read_log_msg(FILE *in, char **_buffer, long *buffersize) memcpy(buffer+smb_vwv+i*2, &tmp, 2); } - assert(fscanf(in, " smb_bcc=%d\n", &tmp)); memcpy(buffer+smb_vwv+(1+buffer[smb_wct])*2, &tmp, 2); + *data_offset = smb_vwv+buffer[smb_wct]*2; + assert(fscanf(in, " smb_bcc=%d\n", data_length)); buffer[(*data_offset)] = *data_length; + (*data_offset)+=2; *_buffer = buffer; - return tmp; } -void read_log_data(FILE *in, char *buffer, long *buffersize, long data_offset) +void read_log_data(FILE *in, char *buffer, long data_length) { - int addr, b[16]; long i,j; - for(i = *buffersize-data_offset; i < *buffersize; i++) { - fscanf(in, " [%x] %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", &addr, &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &b[10], &b[11], &b[12], &b[13], &b[14], &b[15]); - for(j = i; j < 16 && j < *buffersize; j++) buffer[j] = b[j-i]; + long i, addr; char real[2][16]; + for(i = 0; i < data_length; i++) { + if(i % 16 == 0){ + if(i != 0) { /* Read data after each line */ + assert(fscanf(in, "%8s %8s", real[0], real[1]) == 2); + } + assert(fscanf(in, " [%X]", &addr)); + assert(addr == i); + } + assert(fscanf(in, "%2X", &buffer[i])); } } @@ -99,7 +106,7 @@ int main (int argc, char **argv) int c; poptContext pc; char buffer[4096]; - long data_offset; + long data_offset, data_length; int in_packet = 0; struct poptOption long_options[] = { POPT_AUTOHELP @@ -141,15 +148,14 @@ int main (int argc, char **argv) if(!outfile) out = stdout; while(!feof(in)) { - fgets(buffer, sizeof(buffer), in); if(buffer[0] == '[') { /* Header */ if(strstr(buffer, "show_msg")) { in_packet++; if(in_packet == 1)continue; - data_offset = read_log_msg(in, &curpacket, &curpacket_len); + read_log_msg(in, &curpacket, &curpacket_len, &data_offset, &data_length); } else if(in_packet && strstr(buffer, "dump_data")) { - read_log_data(in, curpacket, &curpacket_len, data_offset); + read_log_data(in, curpacket+data_offset, data_length); } else { if(in_packet){ print_packet(out, curpacket, curpacket_len); -- cgit From 7753ed9acf117851e53cb1c489ec475ad531fd47 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Aug 2003 02:18:20 +0000 Subject: Fix some memory issues. It is now possible to convert extract packet data from a samba log file and view it in ethereal, including the DCE/RPC, RAP, etc calls that are contained in a packet, just like you would with a real network sniff! (This used to be commit 6a76750dc4d8b539b7571ac4939c003b6ffa86a9) --- source3/utils/log2pcaphex.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index f2f51dee85..d284fa5c54 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -25,16 +25,17 @@ #include "includes.h" #include +int quiet = 0; #define itoa(a) ((a) < 0xa?'0'+(a):'A' + (a-0xa)) -void print_packet(FILE *out, char *data, long length) +void print_packet(FILE *out, unsigned char *data, long length) { long i,cur = 0;int tmp; while(cur < length) { fprintf(out, "%06X ", cur); for(i = cur; i < length && i < cur + 16; i++) { - fprintf(out, "%02x ", (unsigned char)data[i]); + fprintf(out, "%02x ", data[i]); } cur = i; @@ -42,12 +43,12 @@ while(cur < length) { } } -char *curpacket = NULL; +unsigned char *curpacket = NULL; long curpacket_len = 0; -void read_log_msg(FILE *in, char **_buffer, long *buffersize, long *data_offset, long *data_length) +void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *data_offset, long *data_length) { - char *buffer; + unsigned char *buffer; int tmp; long i; assert(fscanf(in, " size=%d\n", buffersize)); *buffersize+=4; /* for netbios */ @@ -83,18 +84,27 @@ void read_log_msg(FILE *in, char **_buffer, long *buffersize, long *data_offset, *_buffer = buffer; } -void read_log_data(FILE *in, char *buffer, long data_length) +void read_log_data(FILE *in, unsigned char *buffer, long data_length) { - long i, addr; char real[2][16]; + long i, addr; char real[2][16]; int ret; + unsigned char tmp; for(i = 0; i < data_length; i++) { if(i % 16 == 0){ if(i != 0) { /* Read data after each line */ assert(fscanf(in, "%8s %8s", real[0], real[1]) == 2); } - assert(fscanf(in, " [%X]", &addr)); + ret = fscanf(in, " [%03X]", &addr); + if(!ret) { + if(!quiet)fprintf(stderr, "Only first %d bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i); + return; + } assert(addr == i); } - assert(fscanf(in, "%2X", &buffer[i])); + if(!fscanf(in, "%02X", &tmp)) { + if(!quiet)fprintf(stderr, "Only first %d bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i-1); + return; + } + buffer[i] = tmp; } } @@ -110,6 +120,7 @@ int main (int argc, char **argv) int in_packet = 0; struct poptOption long_options[] = { POPT_AUTOHELP + { "quiet", 'q', POPT_ARG_NONE, &quiet, 0, "Be quiet, don't output warnings" }, POPT_TABLEEND }; -- cgit From 22535011e271412bd01fdc081f6ab7e8fcbadb0e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Aug 2003 05:31:46 +0000 Subject: Add ability to output native pcap files without the requirement for text2pcap. IP and TCP checksums are not calculated, but that should not matter. (This used to be commit aa96f780015c031e0c5a0e8773f192502c10c919) --- source3/utils/log2pcaphex.c | 146 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 131 insertions(+), 15 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index d284fa5c54..4e44161ebe 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -5,7 +5,13 @@ Copyright (C) Jelmer Vernooij 2003 Thanks to Tim Potter for the genial idea - Example use: log2pcaphex < samba-log-file | text2pcap -T 139,139 - foo.pcap + Portions (from capconvert.c) (C) Andrew Tridgell 1997 + Portions (from text2pcap.c) (C) Ashok Narayanan 2001 + + Example use with -h parameter: + log2pcaphex < samba-log-file | text2pcap -T 139,139 - foo.pcap + + TODO: Have correct IP and TCP checksums. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,21 +32,124 @@ #include int quiet = 0; +int hexformat = 0; #define itoa(a) ((a) < 0xa?'0'+(a):'A' + (a-0xa)) -void print_packet(FILE *out, unsigned char *data, long length) +#include +#include +#include +#include +#include +#include + +#define TCPDUMP_MAGIC 0xa1b2c3d4 + +/* tcpdump file format */ +struct tcpdump_file_header { + uint32 magic; + uint16 major; + uint16 minor; + int32 zone; + uint32 sigfigs; + uint32 snaplen; + uint32 linktype; +}; + +struct tcpdump_packet { + struct timeval ts; + uint32 caplen; + uint32 len; +}; + +typedef struct { + uint8 ver_hdrlen; + uint8 dscp; + uint16 packet_length; + uint16 identification; + uint8 flags; + uint8 fragment; + uint8 ttl; + uint8 protocol; + uint16 hdr_checksum; + uint32 src_addr; + uint32 dest_addr; +} hdr_ip_t; + +static hdr_ip_t HDR_IP = {0x45, 0, 0, 0x3412, 0, 0, 0xff, 6, 0, 0x01010101, 0x02020202}; + +typedef struct { + uint16 source_port; + uint16 dest_port; + uint32 seq_num; + uint32 ack_num; + uint8 hdr_length; + uint8 flags; + uint16 window; + uint16 checksum; + uint16 urg; +} hdr_tcp_t; + +static hdr_tcp_t HDR_TCP = {139, 139, 0, 0, 0x50, 0, 0, 0, 0}; + +void print_pcap_header(FILE *out) { -long i,cur = 0;int tmp; -while(cur < length) { - fprintf(out, "%06X ", cur); - for(i = cur; i < length && i < cur + 16; i++) { - fprintf(out, "%02x ", data[i]); - } + struct tcpdump_file_header h; + h.magic = TCPDUMP_MAGIC; + h.major = 2; + h.minor = 4; + h.zone = 0; + h.sigfigs = 0; + h.snaplen = 102400; /* As long packets as possible */ + h.linktype = 101; /* Raw IP */ + fwrite(&h, sizeof(struct tcpdump_file_header), 1, out); +} + +void print_pcap_packet(FILE *out, unsigned char *data, long length, long caplen) +{ + static int i = 0; + struct tcpdump_packet p; + i++; + p.ts.tv_usec = 0; + p.ts.tv_sec = 0; + p.caplen = caplen; + p.len = length; + fwrite(&p, sizeof(struct tcpdump_packet), 1, out); + fwrite(data, sizeof(unsigned char), caplen, out); +} + +void print_hex_packet(FILE *out, unsigned char *data, long length) +{ + long i,cur = 0;int tmp; + while(cur < length) { + fprintf(out, "%06X ", cur); + for(i = cur; i < length && i < cur + 16; i++) { + fprintf(out, "%02x ", data[i]); + } - cur = i; - fprintf(out, "\n"); + cur = i; + fprintf(out, "\n"); + } } + +void print_netbios_packet(FILE *out, unsigned char *data, long length, long actual_length) +{ + unsigned char *newdata; long offset = 0; + long newlen; + + newlen = length+sizeof(HDR_IP)+sizeof(HDR_TCP); + newdata = malloc(newlen); + + HDR_IP.packet_length = htons(newlen); + HDR_TCP.window = htons(0x2000); + HDR_TCP.source_port = HDR_TCP.dest_port = htons(139); + + memcpy(newdata+offset, &HDR_IP, sizeof(HDR_IP));offset+=sizeof(HDR_IP); + memcpy(newdata+offset, &HDR_TCP, sizeof(HDR_TCP));offset+=sizeof(HDR_TCP); + memcpy(newdata+offset,data,length); + + print_pcap_packet(out, newdata, newlen, actual_length+offset); + free(newdata); } unsigned char *curpacket = NULL; @@ -84,7 +193,7 @@ void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *dat *_buffer = buffer; } -void read_log_data(FILE *in, unsigned char *buffer, long data_length) +long read_log_data(FILE *in, unsigned char *buffer, long data_length) { long i, addr; char real[2][16]; int ret; unsigned char tmp; @@ -96,16 +205,17 @@ void read_log_data(FILE *in, unsigned char *buffer, long data_length) ret = fscanf(in, " [%03X]", &addr); if(!ret) { if(!quiet)fprintf(stderr, "Only first %d bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i); - return; + return i-1; } assert(addr == i); } if(!fscanf(in, "%02X", &tmp)) { if(!quiet)fprintf(stderr, "Only first %d bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i-1); - return; + return i-1; } buffer[i] = tmp; } + return data_length; } int main (int argc, char **argv) @@ -117,10 +227,13 @@ int main (int argc, char **argv) poptContext pc; char buffer[4096]; long data_offset, data_length; + long data_bytes_read; int in_packet = 0; + int i; struct poptOption long_options[] = { POPT_AUTOHELP { "quiet", 'q', POPT_ARG_NONE, &quiet, 0, "Be quiet, don't output warnings" }, + { "hex", 'h', POPT_ARG_NONE, &hexformat, 0, "Output format readable by text2pcap" }, POPT_TABLEEND }; @@ -158,6 +271,8 @@ int main (int argc, char **argv) if(!outfile) out = stdout; + if(!hexformat)print_pcap_header(out); + while(!feof(in)) { fgets(buffer, sizeof(buffer), in); if(buffer[0] == '[') { /* Header */ @@ -166,10 +281,11 @@ int main (int argc, char **argv) if(in_packet == 1)continue; read_log_msg(in, &curpacket, &curpacket_len, &data_offset, &data_length); } else if(in_packet && strstr(buffer, "dump_data")) { - read_log_data(in, curpacket+data_offset, data_length); + data_bytes_read = read_log_data(in, curpacket+data_offset, data_length); } else { if(in_packet){ - print_packet(out, curpacket, curpacket_len); + if(hexformat) { print_hex_packet(out, curpacket, curpacket_len); return; } + else print_netbios_packet(out, curpacket, curpacket_len, data_bytes_read+data_offset); free(curpacket); } in_packet = 0; -- cgit From c574bf0ced36bf94646a3d324c0d74c8820bc6fe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Aug 2003 16:13:59 +0000 Subject: Print more than 1 packet in hex mode (This used to be commit 28f1d7b201932eb3864af3d71ec862670898822c) --- source3/utils/log2pcaphex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 4e44161ebe..b3a34281a8 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -284,7 +284,7 @@ int main (int argc, char **argv) data_bytes_read = read_log_data(in, curpacket+data_offset, data_length); } else { if(in_packet){ - if(hexformat) { print_hex_packet(out, curpacket, curpacket_len); return; } + if(hexformat) print_hex_packet(out, curpacket, curpacket_len); else print_netbios_packet(out, curpacket, curpacket_len, data_bytes_read+data_offset); free(curpacket); } -- cgit From 48cb8f8d5f41045bf405047fbb5db6a29935a342 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 29 Aug 2003 01:33:00 +0000 Subject: Fix some compiler warnings. (This used to be commit f566de0541373fab97caa6b0f574f79e68ae74dc) --- source3/utils/log2pcaphex.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index b3a34281a8..7c429c326b 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -120,9 +120,9 @@ void print_pcap_packet(FILE *out, unsigned char *data, long length, long caplen) void print_hex_packet(FILE *out, unsigned char *data, long length) { - long i,cur = 0;int tmp; + long i,cur = 0; while(cur < length) { - fprintf(out, "%06X ", cur); + fprintf(out, "%06lX ", cur); for(i = cur; i < length && i < cur + 16; i++) { fprintf(out, "%02x ", data[i]); } @@ -159,7 +159,7 @@ void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *dat { unsigned char *buffer; int tmp; long i; - assert(fscanf(in, " size=%d\n", buffersize)); + assert(fscanf(in, " size=%ld\n", buffersize)); *buffersize+=4; /* for netbios */ buffer = malloc(*buffersize); memset(buffer, 0, *buffersize); @@ -188,7 +188,7 @@ void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *dat } *data_offset = smb_vwv+buffer[smb_wct]*2; - assert(fscanf(in, " smb_bcc=%d\n", data_length)); buffer[(*data_offset)] = *data_length; + assert(fscanf(in, " smb_bcc=%ld\n", data_length)); buffer[(*data_offset)] = *data_length; (*data_offset)+=2; *_buffer = buffer; } @@ -202,15 +202,15 @@ long read_log_data(FILE *in, unsigned char *buffer, long data_length) if(i != 0) { /* Read data after each line */ assert(fscanf(in, "%8s %8s", real[0], real[1]) == 2); } - ret = fscanf(in, " [%03X]", &addr); + ret = fscanf(in, " [%03lX]", &addr); if(!ret) { - if(!quiet)fprintf(stderr, "Only first %d bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i); + if(!quiet)fprintf(stderr, "Only first %ld bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i); return i-1; } assert(addr == i); } - if(!fscanf(in, "%02X", &tmp)) { - if(!quiet)fprintf(stderr, "Only first %d bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i-1); + if(!fscanf(in, "%02lX", &tmp)) { + if(!quiet)fprintf(stderr, "Only first %ld bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i-1); return i-1; } buffer[i] = tmp; @@ -223,13 +223,11 @@ int main (int argc, char **argv) const char *infile, *outfile; FILE *out, *in; int opt; - int c; poptContext pc; char buffer[4096]; long data_offset, data_length; long data_bytes_read; int in_packet = 0; - int i; struct poptOption long_options[] = { POPT_AUTOHELP { "quiet", 'q', POPT_ARG_NONE, &quiet, 0, "Be quiet, don't output warnings" }, -- cgit From 0548123153643e00a4a91280aca2d031218f7292 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 31 Aug 2003 23:58:55 +0000 Subject: We don't need to #include memory.h here. It's a BSD'ism and just includes string.h anyways. (This used to be commit 71034cede83b5605b25a4d3b640086294244c239) --- source3/utils/log2pcaphex.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 7c429c326b..4804b99338 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -38,7 +38,6 @@ int hexformat = 0; #include #include -#include #include #include #include -- cgit From 55739e9f860a2a8f27a99fc2f79905a8ed143fee Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 7 May 2005 06:59:00 +0000 Subject: r6640: Attempt to fix 'make everything' with the paranoid malloc checker. Volker (This used to be commit 3db2799822da3711b47b60ba13daa07205ced45f) --- source3/utils/log2pcaphex.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 4804b99338..d07dc2a211 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -29,6 +29,11 @@ */ #include "includes.h" + +/* We don't care about the paranoid malloc checker in this standalone + program */ +#undef malloc + #include int quiet = 0; -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/utils/log2pcaphex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index d07dc2a211..24412cbe85 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -200,7 +200,7 @@ void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *dat long read_log_data(FILE *in, unsigned char *buffer, long data_length) { long i, addr; char real[2][16]; int ret; - unsigned char tmp; + unsigned int tmp; for(i = 0; i < data_length; i++) { if(i % 16 == 0){ if(i != 0) { /* Read data after each line */ @@ -213,7 +213,7 @@ long read_log_data(FILE *in, unsigned char *buffer, long data_length) } assert(addr == i); } - if(!fscanf(in, "%02lX", &tmp)) { + if(!fscanf(in, "%02X", &tmp)) { if(!quiet)fprintf(stderr, "Only first %ld bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i-1); return i-1; } @@ -230,7 +230,7 @@ int main (int argc, char **argv) poptContext pc; char buffer[4096]; long data_offset, data_length; - long data_bytes_read; + long data_bytes_read = 0; int in_packet = 0; struct poptOption long_options[] = { POPT_AUTOHELP -- cgit From 0691ed55cade8093213db38555edb536ee0c557d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 17 Aug 2006 11:54:23 +0000 Subject: r17584: Some C++ Warnings (This used to be commit f6194cf4b263454bbdf180a7d014ffc3498df497) --- source3/utils/log2pcaphex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 24412cbe85..aa68cf09c9 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -142,7 +142,7 @@ void print_netbios_packet(FILE *out, unsigned char *data, long length, long actu long newlen; newlen = length+sizeof(HDR_IP)+sizeof(HDR_TCP); - newdata = malloc(newlen); + newdata = (unsigned char *)malloc(newlen); HDR_IP.packet_length = htons(newlen); HDR_TCP.window = htons(0x2000); @@ -165,7 +165,7 @@ void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *dat int tmp; long i; assert(fscanf(in, " size=%ld\n", buffersize)); *buffersize+=4; /* for netbios */ - buffer = malloc(*buffersize); + buffer = (unsigned char *)malloc(*buffersize); memset(buffer, 0, *buffersize); /* NetBIOS */ buffer[0] = 0x00; -- cgit From 55ed1d59455566d90a03e7123fbf7a05a4bd4539 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 19 Dec 2006 20:16:52 +0000 Subject: r20261: merge 20260 from samba_3_0_24 clean up a bunch of no previous prototype warnings (This used to be commit c60687db112405262adf26dbf267804b04074e67) --- source3/utils/log2pcaphex.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index aa68cf09c9..b7a595f754 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -96,7 +96,7 @@ typedef struct { static hdr_tcp_t HDR_TCP = {139, 139, 0, 0, 0x50, 0, 0, 0, 0}; -void print_pcap_header(FILE *out) +static void print_pcap_header(FILE *out) { struct tcpdump_file_header h; h.magic = TCPDUMP_MAGIC; @@ -109,7 +109,7 @@ void print_pcap_header(FILE *out) fwrite(&h, sizeof(struct tcpdump_file_header), 1, out); } -void print_pcap_packet(FILE *out, unsigned char *data, long length, long caplen) +static void print_pcap_packet(FILE *out, unsigned char *data, long length, long caplen) { static int i = 0; struct tcpdump_packet p; @@ -122,7 +122,7 @@ void print_pcap_packet(FILE *out, unsigned char *data, long length, long caplen) fwrite(data, sizeof(unsigned char), caplen, out); } -void print_hex_packet(FILE *out, unsigned char *data, long length) +static void print_hex_packet(FILE *out, unsigned char *data, long length) { long i,cur = 0; while(cur < length) { @@ -136,7 +136,7 @@ void print_hex_packet(FILE *out, unsigned char *data, long length) } } -void print_netbios_packet(FILE *out, unsigned char *data, long length, long actual_length) +static void print_netbios_packet(FILE *out, unsigned char *data, long length, long actual_length) { unsigned char *newdata; long offset = 0; long newlen; @@ -159,7 +159,7 @@ void print_netbios_packet(FILE *out, unsigned char *data, long length, long actu unsigned char *curpacket = NULL; long curpacket_len = 0; -void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *data_offset, long *data_length) +static void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *data_offset, long *data_length) { unsigned char *buffer; int tmp; long i; @@ -197,7 +197,7 @@ void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *dat *_buffer = buffer; } -long read_log_data(FILE *in, unsigned char *buffer, long data_length) +static long read_log_data(FILE *in, unsigned char *buffer, long data_length) { long i, addr; char real[2][16]; int ret; unsigned int tmp; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/log2pcaphex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index b7a595f754..0498380ec2 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -15,7 +15,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/log2pcaphex.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 0498380ec2..daebb56a88 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -24,8 +24,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 602271632a7f31463341e68ef96b58333d9c6715 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 25 Jul 2007 13:05:54 +0000 Subject: r24044: Fix an uninitialized variable warning (This used to be commit 69326a56e7fe2681eef3d58a9107765496756de4) --- source3/utils/log2pcaphex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index daebb56a88..6f07c4f543 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -228,7 +228,7 @@ int main (int argc, char **argv) int opt; poptContext pc; char buffer[4096]; - long data_offset, data_length; + long data_offset = 0, data_length; long data_bytes_read = 0; int in_packet = 0; struct poptOption long_options[] = { -- cgit From 9a85533914119fb995fb61555c9f6e0018d4d181 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Oct 2007 11:38:36 -0700 Subject: Fix the popt / bool issues. Some places we used BOOL where we meant int. Fix this. Thanks to metze for pointing this out. Jeremy. (This used to be commit 793a9d24a163cb6cf5a3a0aa5ae30e9f8cf4744a) --- source3/utils/log2pcaphex.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source3/utils/log2pcaphex.c') diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c index 6f07c4f543..20cc40ca59 100644 --- a/source3/utils/log2pcaphex.c +++ b/source3/utils/log2pcaphex.c @@ -35,8 +35,8 @@ #include -int quiet = 0; -int hexformat = 0; +bool quiet = 0; +bool hexformat = 0; #define itoa(a) ((a) < 0xa?'0'+(a):'A' + (a-0xa)) @@ -233,8 +233,8 @@ int main (int argc, char **argv) int in_packet = 0; struct poptOption long_options[] = { POPT_AUTOHELP - { "quiet", 'q', POPT_ARG_NONE, &quiet, 0, "Be quiet, don't output warnings" }, - { "hex", 'h', POPT_ARG_NONE, &hexformat, 0, "Output format readable by text2pcap" }, + { "quiet", 'q', POPT_ARG_NONE, NULL, 'q', "Be quiet, don't output warnings" }, + { "hex", 'h', POPT_ARG_NONE, NULL, 'h', "Output format readable by text2pcap" }, POPT_TABLEEND }; @@ -245,6 +245,12 @@ int main (int argc, char **argv) while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { + case 'q': + quiet = true; + break; + case 'h': + hexformat = true; + break; } } -- cgit