} hdr_ip_t;
static hdr_ip_t HDR_IP = {0x45, 0, 0, 0x3412, 0, 0, 0xff, 6, 0, 0x01010101, 0x02020202};
typedef struct {
} hdr_ip_t;
static hdr_ip_t HDR_IP = {0x45, 0, 0, 0x3412, 0, 0, 0xff, 6, 0, 0x01010101, 0x02020202};
typedef struct {
} hdr_tcp_t;
static hdr_tcp_t HDR_TCP = {139, 139, 0, 0, 0x50, 0, 0, 0, 0};
} hdr_tcp_t;
static hdr_tcp_t HDR_TCP = {139, 139, 0, 0, 0x50, 0, 0, 0, 0};
fwrite(&h, sizeof(struct tcpdump_file_header), 1, 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)
fwrite(data, sizeof(unsigned char), caplen, out);
}
fwrite(data, sizeof(unsigned char), caplen, out);
}
for(i = cur; i < length && i < cur + 16; i++) {
fprintf(out, "%02x ", data[i]);
}
for(i = cur; i < length && i < cur + 16; i++) {
fprintf(out, "%02x ", data[i]);
}
-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)
+{
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);
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);
}
print_pcap_packet(out, newdata, newlen, actual_length+offset);
free(newdata);
}
-void read_log_msg(FILE *in, unsigned char **_buffer, unsigned short *buffersize, long *data_offset, long *data_length)
+static void read_log_msg(FILE *in, unsigned char **_buffer,
+ unsigned short *buffersize, long *data_offset,
+ long *data_length)
memset(buffer, 0, *buffersize+4);
/* NetBIOS Session Service */
buffer[0] = 0x00;
memset(buffer, 0, *buffersize+4);
/* NetBIOS Session Service */
buffer[0] = 0x00;
* [040] 00 34 00 2E 00 30 00 00 00 49 00 53 00 49 00 4C .4...0.. .I.S.I.L
* [050] 00 4F 00 4E 00 00 00 .O.N...
*/
* [040] 00 34 00 2E 00 30 00 00 00 49 00 53 00 49 00 4C .4...0.. .I.S.I.L
* [050] 00 4F 00 4E 00 00 00 .O.N...
*/
"Only first %ld bytes are logged, packet trace will "
"be incomplete\n", line_num, i-1);
while ((tmp = getc(in)) != '\n');
"Only first %ld bytes are logged, packet trace will "
"be incomplete\n", line_num, i-1);
while ((tmp = getc(in)) != '\n');
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
};
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
};
-
- pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
+
+ pc = poptGetContext(NULL, argc, argv, long_options,
POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "[<infile> [<outfile>]]");
POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "[<infile> [<outfile>]]");
outfile = poptGetArg(pc);
if(outfile) {
out = fopen(outfile, "w+");
outfile = poptGetArg(pc);
if(outfile) {
out = fopen(outfile, "w+");
fprintf(stderr, "Can't find %s, using stdout...\n", outfile);
fprintf(stderr, "Can't find %s, using stdout...\n", outfile);
- fgets(buffer, sizeof(buffer), in); line_num++;
+ char *p;
+ p = fgets(buffer, sizeof(buffer), in);
+ if (p == NULL) {
+ fprintf(stderr, "error reading from input file\n");
+ break;
+ }
+ line_num++;
if(buffer[0] == '[') { /* Header */
if(strstr(buffer, "show_msg")) {
in_packet++;
if(buffer[0] == '[') { /* Header */
if(strstr(buffer, "show_msg")) {
in_packet++;
read_log_msg(in, &curpacket, &curpacket_len, &data_offset, &data_length);
} else if(in_packet && strstr(buffer, "dump_data")) {
data_bytes_read = read_log_data(in, curpacket+data_offset, data_length);
read_log_msg(in, &curpacket, &curpacket_len, &data_offset, &data_length);
} else if(in_packet && strstr(buffer, "dump_data")) {
data_bytes_read = read_log_data(in, curpacket+data_offset, data_length);
else print_netbios_packet(out, curpacket, curpacket_len, data_bytes_read+data_offset);
else print_netbios_packet(out, curpacket, curpacket_len, data_bytes_read+data_offset);