1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* Copyright (C) 2000-2006 Boris Wesslowski */
/* $Id: lancom.c,v 1.4 2006/03/08 19:36:02 bw Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "main.h"
#include "utils.h"
extern struct options opt;
unsigned char lancom(char *input, int linenum)
{
char *sinputs=input, *sinpute;
int retval, day, hour, minute, second;
char smonth[3];
init_line();
xstrncpy(opt.line->interface, "-", SHORTLEN);
/* Read time */
sinpute = sinputs+15;
*sinpute = '\0';
retval = sscanf(sinputs, "%3s %2d %2d:%2d:%2d", smonth, &day, &hour, &minute, &second);
build_time(smonth, day, hour, minute, second);
/* Read loghost */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ' ');
*sinpute = '\0';
xstrncpy(opt.line->hostname, sinputs, sinpute - sinputs + 1);
/* Read chainlabel */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ' ');
*sinpute = '\0';
xstrncpy(opt.line->chainlabel, sinputs, sinpute - sinputs);
/* Skip "Dst:" */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ':');
sinpute++;
/* Read dest IP */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ':');
*sinpute = '\0';
if(convert_ip(sinputs, &opt.line->dhost) == IN_ADDR_ERROR) {
if(opt.verbose)
fprintf(stderr, "lancom parse error while reading dhost in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read dest port */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ' ');
retval = sscanf(sinputs, "%5d", &opt.line->dport);
if (retval == 0) {
if(opt.verbose)
fprintf(stderr, "lancom parse error while reading dport in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Skip the "Src:" */
sinputs = sinpute;
sinpute = strchr(sinputs, ':');
sinpute++;
/* Read source IP */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ':');
*sinpute = '\0';
if(convert_ip(sinputs, &opt.line->shost) == IN_ADDR_ERROR) {
if(opt.verbose)
fprintf(stderr, "lancom parse error while reading shost in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read source port */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ' ');
*sinpute = '\0';
retval = sscanf(sinputs, "%5d", &opt.line->sport);
if (retval == 0) {
if(opt.verbose)
fprintf(stderr, "lancom parse error while reading sport in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read protocol */
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, '(');
if (sinpute == NULL) {
if(opt.verbose)
fprintf(stderr, "lancom parse error while looking for protocol in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, ')');
*sinpute = '\0';
if(strncmp(sinputs, "TCP", 3) == 0) opt.line->protocol = 6;
else if(strncmp(sinputs, "UDP", 3) == 0) opt.line->protocol = 17;
else {
if(opt.verbose)
fprintf(stderr, "lancom parse error while reading proto in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read branch name */
sinpute++;
sinpute++;
sinpute++;
sinputs = sinpute;
sinpute = strchr(sinputs, '\0');
xstrncpy(opt.line->branchname, sinputs, sinpute - sinputs);
/* Set rest */
opt.line->flags = 0;
opt.line->count = 1;
return PARSE_OK;
}
|