diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2003-08-15 02:18:20 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2003-08-15 02:18:20 +0000 |
commit | 7753ed9acf117851e53cb1c489ec475ad531fd47 (patch) | |
tree | 964741792af0099ae916806cd2025f08c1831377 /source3 | |
parent | d294d4b98f6555d72323b60d3cc0918bd08f7905 (diff) | |
download | samba-7753ed9acf117851e53cb1c489ec475ad531fd47.tar.gz samba-7753ed9acf117851e53cb1c489ec475ad531fd47.tar.bz2 samba-7753ed9acf117851e53cb1c489ec475ad531fd47.zip |
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)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/utils/log2pcaphex.c | 29 |
1 files changed, 20 insertions, 9 deletions
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 <assert.h> +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 }; |