/[darkstattype]/trunk/darkstattype.c
ViewVC logotype

Diff of /trunk/darkstattype.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 10 by trond, 2014-03-21T15:40:57Z Revision 13 by trond, 2014-03-21T16:59:56Z
# Line 278  void decode_host_header_v1(void) Line 278  void decode_host_header_v1(void)
278    unsigned long bytesout;    unsigned long bytesout;
279    unsigned char protosdata;    unsigned char protosdata;
280    unsigned char tcpdata;    unsigned char tcpdata;
281    unsigned char udpdata;    unsigned char udpdata;
282    
283    unsigned char i;    unsigned char i;
284    
285    indent();    indent();
286    
287    ipv4address[0] = read8u();    ipv4address[0] = read8u();
288    ipv4address[1] = read8u();    ipv4address[1] = read8u();
289    ipv4address[2] = read8u();    ipv4address[2] = read8u();
290    ipv4address[3] = read8u();    ipv4address[3] = read8u();
291    
292    print_indentation();    print_indentation();
293    printf("IPv4 address %d.%d.%d.%d\n",    printf("IPv4 address %u.%u.%u.%u\n",
294           ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]);           ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]);
295    
296    macaddress[0] = read8u();    macaddress[0] = read8u();
297    macaddress[1] = read8u();    macaddress[1] = read8u();
298    macaddress[2] = read8u();    macaddress[2] = read8u();
299    macaddress[3] = read8u();    macaddress[3] = read8u();
300    macaddress[4] = read8u();    macaddress[4] = read8u();
301    macaddress[5] = read8u();    macaddress[5] = read8u();
302    
303    print_indentation();    print_indentation();
304    printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);    printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);
305    
306    hostnamelen = read8u();    hostnamelen = read8u();
307    
308    print_indentation();    print_indentation();
309    printf("Hostname length %d\n", hostnamelen);    printf("Hostname length %u\n", hostnamelen);
310    
311    for (i = 0; i < hostnamelen; i++) {    for (i = 0; i < hostnamelen; i++) {
312      hostname[i] = read8u();      hostname[i] = read8u();
313    } // for    } // for
314    hostname[i] = '\0';    hostname[i] = '\0';
315    
316    print_indentation();    print_indentation();
317    printf("Hostname %s\n", hostname);    printf("Hostname %s\n", hostname);
318    
319    bytesin = read64u();    bytesin = read64u();
320    
321    print_indentation();    print_indentation();
322    printf("Bytes in %lu\n", bytesin);    printf("Bytes in %lu\n", bytesin);
323    
324    bytesout = read64u();    bytesout = read64u();
# Line 361  void decode_host_header_v2(void) Line 361  void decode_host_header_v2(void)
361    unsigned long bytesout;    unsigned long bytesout;
362    unsigned char protosdata;    unsigned char protosdata;
363    unsigned char tcpdata;    unsigned char tcpdata;
364    unsigned char udpdata;    unsigned char udpdata;
365    
366    unsigned char i;    unsigned char i;
367    
368    indent();    indent();
369    
370    ipv4address[0] = read8u();    ipv4address[0] = read8u();
371    ipv4address[1] = read8u();    ipv4address[1] = read8u();
372    ipv4address[2] = read8u();    ipv4address[2] = read8u();
373    ipv4address[3] = read8u();    ipv4address[3] = read8u();
374    
375    print_indentation();    print_indentation();
376    printf("IPv4 address %d.%d.%d.%d\n",    printf("IPv4 address %u.%u.%u.%u\n",
377           ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]);           ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]);
378    
379    if (follow_specification == true) {    if (follow_specification == true) {
380      macaddress[0] = read8u();      macaddress[0] = read8u();
381      macaddress[1] = read8u();      macaddress[1] = read8u();
382      macaddress[2] = read8u();      macaddress[2] = read8u();
383      macaddress[3] = read8u();      macaddress[3] = read8u();
384      macaddress[4] = read8u();      macaddress[4] = read8u();
385      macaddress[5] = read8u();      macaddress[5] = read8u();
386    
387      print_indentation();      print_indentation();
388      printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);      printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);
389    
390      lastseen = read64s();      lastseen = read64s();
391    
# Line 404  void decode_host_header_v2(void) Line 404  void decode_host_header_v2(void)
404    
405      macaddress[0] = read8u();      macaddress[0] = read8u();
406      macaddress[1] = read8u();      macaddress[1] = read8u();
407      macaddress[2] = read8u();      macaddress[2] = read8u();
408      macaddress[3] = read8u();      macaddress[3] = read8u();
409      macaddress[4] = read8u();      macaddress[4] = read8u();
410      macaddress[5] = read8u();      macaddress[5] = read8u();
411    
412      print_indentation();      print_indentation();
413      printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);      printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);
414    } // else    } // else
415    
416    hostnamelen = read8u();    hostnamelen = read8u();
417    
418    print_indentation();    print_indentation();
419    printf("Hostname length %d\n", hostnamelen);    printf("Hostname length %u\n", hostnamelen);
420    
421    for (i = 0; i < hostnamelen; i++) {    for (i = 0; i < hostnamelen; i++) {
422      hostname[i] = read8u();      hostname[i] = read8u();
423    } // for    } // for
424    hostname[i] = '\0';    hostname[i] = '\0';
425    
426    print_indentation();    print_indentation();
427    printf("Hostname %s\n", hostname);    printf("Hostname %s\n", hostname);
428    
429    bytesin = read64u();    bytesin = read64u();
430    
431    print_indentation();    print_indentation();
432    printf("Bytes in %lu\n", bytesin);    printf("Bytes in %lu\n", bytesin);
433    
434    bytesout = read64u();    bytesout = read64u();
# Line 450  void decode_host_header_v3(void) Line 450  void decode_host_header_v3(void)
450    
451    decode_tcp_data();    decode_tcp_data();
452    
453    if ( (udpdata = read8u()) != 'U') { // missing udp data    if ( (udpdata = read8u()) != 'U') { // missing udp data
454      fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata);      fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata);
455      exit(EXIT_FAILURE);      exit(EXIT_FAILURE);
456    } // if    } // if
457    
458    decode_udp_data();    decode_udp_data();
459    
460    exdent();    exdent();
461  } // decode_host_header_v2  } // decode_host_header_v2
462    
463  void decode_host_header_v3(void)  void decode_host_header_v3(void)
464  {  {
465    unsigned char addressfamily;    unsigned char  addressfamily;
466    unsigned char ipv4address[4];    unsigned char  ipv4address[4];
467    unsigned char ipv6address[16];    unsigned short ipv6address[8];
468    unsigned char macaddress[6];    unsigned char  macaddress[6];
469      signed long lastseen;      signed long  lastseen;
470    unsigned char hostnamelen;    unsigned char  hostnamelen;
471    unsigned char hostname[256];    unsigned char  hostname[256];
472    unsigned long bytesin;    unsigned long  bytesin;
473    unsigned long bytesout;    unsigned long  bytesout;
474    unsigned char protosdata;    unsigned char  protosdata;
475    unsigned char tcpdata;    unsigned char  tcpdata;
476    unsigned char udpdata;    unsigned char  udpdata;
477    
478    unsigned char i;    unsigned char  i;
479    
480    indent();    indent();
481    
482    if ( (addressfamily = read8u()) == 0x04) { // IPv4 address    if ( (addressfamily = read8u()) == 0x04) { // IPv4 address
483      print_indentation();      print_indentation();
484      printf("IPv4 address family (0x%02x)\n", addressfamily);      printf("IPv4 address family (0x%02x)\n", addressfamily);
485    
486      ipv4address[0] = read8u();      ipv4address[0] = read8u();
487      ipv4address[1] = read8u();      ipv4address[1] = read8u();
488      ipv4address[2] = read8u();      ipv4address[2] = read8u();
489      ipv4address[3] = read8u();      ipv4address[3] = read8u();
490    
491      print_indentation();      print_indentation();
492      printf("IPv4 address %d.%d.%d.%d\n",      printf("IPv4 address %u.%u.%u.%u\n",
493             ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]);             ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]);
494    } // if    } // if
495    else if (addressfamily == 0x06) { // IPv6 address    else if (addressfamily == 0x06) { // IPv6 address
496      print_indentation();      print_indentation();
497      printf("IPv6 address family (0x%02x)\n", addressfamily);      printf("IPv6 address family (0x%02x)\n", addressfamily);
498    
499      ipv6address[ 0] = read8u();      ipv6address[0] = read16u();
500      ipv6address[ 1] = read8u();      ipv6address[1] = read16u();
501      ipv6address[ 2] = read8u();      ipv6address[2] = read16u();
502      ipv6address[ 3] = read8u();      ipv6address[3] = read16u();
503      ipv6address[ 4] = read8u();      ipv6address[4] = read16u();
504      ipv6address[ 5] = read8u();      ipv6address[5] = read16u();
505      ipv6address[ 6] = read8u();      ipv6address[6] = read16u();
506      ipv6address[ 7] = read8u();      ipv6address[7] = read16u();
     ipv6address[ 8] = read8u();  
     ipv6address[ 9] = read8u();  
     ipv6address[10] = read8u();  
     ipv6address[11] = read8u();  
     ipv6address[12] = read8u();  
     ipv6address[13] = read8u();  
     ipv6address[14] = read8u();  
     ipv6address[15] = read8u();  
507    
508      print_indentation();      print_indentation();
509      printf("IPv6 address %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",      printf("IPv6 address %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
510             ipv6address[ 0],             ipv6address[0],
511             ipv6address[ 1],             ipv6address[1],
512             ipv6address[ 2],             ipv6address[2],
513             ipv6address[ 3],             ipv6address[3],
514             ipv6address[ 4],             ipv6address[4],
515             ipv6address[ 5],             ipv6address[5],
516             ipv6address[ 6],             ipv6address[6],
517             ipv6address[ 7],             ipv6address[7]);
            ipv6address[ 8],  
            ipv6address[ 9],  
            ipv6address[10],  
            ipv6address[11],  
            ipv6address[12],  
            ipv6address[13],  
            ipv6address[14],  
            ipv6address[15]);  
518    } // else if    } // else if
519    else { // unknown address family    else { // unknown address family
520      fprintf(stderr, "%s:%s:%ld: unknown address family = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, ftell(file), addressfamily, 0x04, 0x06);      fprintf(stderr, "%s:%s:%ld: unknown address family = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, ftell(file), addressfamily, 0x04, 0x06);
521      exit(EXIT_FAILURE);      exit(EXIT_FAILURE);
522    } // else    } // else
523    
524    if (follow_specification == true) {    if (follow_specification == true) {
525      macaddress[0] = read8u();      macaddress[0] = read8u();
526      macaddress[1] = read8u();      macaddress[1] = read8u();
527      macaddress[2] = read8u();      macaddress[2] = read8u();
528      macaddress[3] = read8u();      macaddress[3] = read8u();
529      macaddress[4] = read8u();      macaddress[4] = read8u();
530      macaddress[5] = read8u();      macaddress[5] = read8u();
531    
532      print_indentation();      print_indentation();
# Line 565  void decode_host_header_v3(void) Line 549  void decode_host_header_v3(void)
549    
550      macaddress[0] = read8u();      macaddress[0] = read8u();
551      macaddress[1] = read8u();      macaddress[1] = read8u();
552      macaddress[2] = read8u();      macaddress[2] = read8u();
553      macaddress[3] = read8u();      macaddress[3] = read8u();
554      macaddress[4] = read8u();      macaddress[4] = read8u();
555      macaddress[5] = read8u();      macaddress[5] = read8u();
556    
557      print_indentation();      print_indentation();
558      printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);      printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]);
559    } // else    } // else
560    
561    hostnamelen = read8u();    hostnamelen = read8u();
562    
563    print_indentation();    print_indentation();
564    printf("Hostname length %d\n", hostnamelen);    printf("Hostname length %u\n", hostnamelen);
565    
566    for (i = 0; i < hostnamelen; i++) {    for (i = 0; i < hostnamelen; i++) {
567      hostname[i] = read8u();      hostname[i] = read8u();
568    } // for    } // for
569    hostname[i] = '\0';    hostname[i] = '\0';
570    
571    print_indentation();    print_indentation();
572    printf("Hostname %s\n", hostname);    printf("Hostname %s\n", hostname);
573    
574    bytesin = read64u();    bytesin = read64u();
575    
576    print_indentation();    print_indentation();
577    printf("Bytes in %lu\n", bytesin);    printf("Bytes in %lu\n", bytesin);
578    
579    bytesout = read64u();    bytesout = read64u();
# Line 613  void decode_protos_data(void) Line 597  void decode_protos_data(void)
597    
598    if ( (udpdata = read8u()) != 'U') { // missing udp data    if ( (udpdata = read8u()) != 'U') { // missing udp data
599      fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata);      fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata);
600      exit(EXIT_FAILURE);      exit(EXIT_FAILURE);
601    } // if    } // if
602    
603    decode_udp_data();    decode_udp_data();
604    
605    exdent();    exdent();
606  } // decode_host_header_v3  } // decode_host_header_v3
607    
608  void decode_protos_data(void)  void decode_protos_data(void)
609  {  {
610    unsigned char ipprotocount;    unsigned char ipprotocount;
611    
612    unsigned char u;    unsigned char i;
613    
614    ipprotocount = read8u();    ipprotocount = read8u();
615    
616    print_indentation();    print_indentation();
617    printf("IP Proto count %d\n", ipprotocount);    printf("IP Proto count %u\n", ipprotocount);
618    
619    indent();    indent();
620    
621    for (u = 0; u < ipprotocount; u++) {    for (i = 0; i < ipprotocount; i++) {
622      unsigned char proto;      unsigned char proto;
623      unsigned long in;      unsigned long in;
624      unsigned long out;      unsigned long out;
625    
626      print_indentation();      print_indentation();
627      printf("Protocol #%u of %u:\n", u + 1, ipprotocount);      printf("Protocol #%u of %u:\n", i + 1, ipprotocount);
628    
629      proto = read8u();      proto = read8u();
630    
631      indent();      indent();
632      print_indentation();      print_indentation();
633      printf("Protocol 0x%02x\n", proto);      printf("Protocol 0x%02x\n", proto);
634    
635      in = read64u();      in = read64u();
636    
637      print_indentation();      print_indentation();
638      printf("In %lu\n", in);      printf("In %lu\n", in);
639    
640      out = read64u();      out = read64u();
641    
642      print_indentation();      print_indentation();
# Line 661  void decode_tcp_data(void) Line 645  void decode_tcp_data(void)
645      exdent();      exdent();
646    } // for    } // for
647    
648    exdent();    exdent();
649  } // decode_protos_data();  } // decode_protos_data();
650    
651  void decode_tcp_data(void)  void decode_tcp_data(void)
652  {  {
653    unsigned char tcpprotocount;    unsigned char tcpprotocount;
654    
655    unsigned short i;    unsigned short i;
656    
657    tcpprotocount = read16u();    tcpprotocount = read16u();
658    
659    print_indentation();    print_indentation();
660    printf("TCP proto count %d\n", tcpprotocount);    printf("TCP proto count %u\n", tcpprotocount);
661    
662    indent();    indent();
663    
664    for (i = 0; i < tcpprotocount; i++) {    for (i = 0; i < tcpprotocount; i++) {
665      unsigned short port;      unsigned short port;
666      unsigned long syn;      unsigned long syn;
667      unsigned long in;      unsigned long in;
668      unsigned long out;      unsigned long out;
669    
670      port = read16u();      port = read16u();
671    
672      print_indentation();      print_indentation();
673      printf("Port %d:\n", port);      printf("Port %u:\n", port);
674    
675      syn = read64u();      syn = read64u();
676    
677      indent();      indent();
678      print_indentation();      print_indentation();
679      printf("SYN %lu\n", syn);      printf("SYN %lu\n", syn);
680    
681      in = read64u();      in = read64u();
682    
683      print_indentation();      print_indentation();
684      printf("In %lu\n", in);      printf("In %lu\n", in);
685    
686      out = read64u();      out = read64u();
687    
688      print_indentation();      print_indentation();
# Line 707  void decode_udp_data(void) Line 691  void decode_udp_data(void)
691      exdent();      exdent();
692    } // for    } // for
693    
694    exdent();    exdent();
695  } // decode_tcp_data()  } // decode_tcp_data()
696    
697  void decode_udp_data(void)  void decode_udp_data(void)
698  {  {
699    unsigned char udpprotocount;    unsigned char udpprotocount;
700    
701    unsigned short i;    unsigned short i;
702    
703    udpprotocount = read16u();    udpprotocount = read16u();
704    
705    print_indentation();    print_indentation();
706    printf("UDP proto count %d\n", udpprotocount);    printf("UDP proto count %u\n", udpprotocount);
707    
708    indent();    indent();
709    
710    for (i = 0; i < udpprotocount; i++) {    for (i = 0; i < udpprotocount; i++) {
711      unsigned short port;      unsigned short port;
712      unsigned long in;      unsigned long in;
713      unsigned long out;      unsigned long out;
714    
715      port = read16u();      port = read16u();
716    
717      print_indentation();      print_indentation();
718      printf("Port %d:\n", port);      printf("Port %u:\n", port);
719    
720      in = read64u();      in = read64u();
721    
722      indent();      indent();
723      print_indentation();      print_indentation();
724      printf("In %lu\n", in);      printf("In %lu\n", in);
725    
726      out = read64u();      out = read64u();
727    
728      print_indentation();      print_indentation();
729      printf("Out %lu\n", out);      printf("Out %lu\n", out);
730    
731      exdent();      exdent();
732    } // for    } // for
733    
# Line 759  void decode_graph_db_v1(void) Line 743  void decode_graph_db_v1(void)
743    lasttime = read64s();    lasttime = read64s();
744    
745    indent();    indent();
746    print_indentation();    print_indentation();
747    printf("Last time 0x%lx = %ld = ", lasttime, lasttime);    printf("Last time 0x%lx = %ld = ", lasttime, lasttime);
748    print_time_t(lasttime);    print_time_t(lasttime);
749    puts("");    puts("");
750    
751    for (i = 0; i < 4; i++) {    for (i = 0; i < 4; i++) {
752      unsigned char nbars;      unsigned char nbars;
753      unsigned char idxlastbar;      unsigned char idxlastbar;
754    
755      unsigned int j;      unsigned int j;
756    
757      print_indentation();      print_indentation();
758      printf("Graph #%d of 4:\n", i + 1);      printf("Graph #%u of 4:\n", i + 1);
759    
760      nbars = read8u();      nbars = read8u();
761    
762      indent();      indent();
763      print_indentation();      print_indentation();
764      printf("Number of bars %u\n", nbars);      printf("Number of bars %u\n", nbars);
765    
766      idxlastbar = read8u();      idxlastbar = read8u();
767    
768      print_indentation();      print_indentation();
769      printf("Index of last bar %u\n", idxlastbar);      printf("Index of last bar %u\n", idxlastbar);
770    
771      indent();      indent();
772      for (j = 0; j < idxlastbar; j++) {      for (j = 0; j < idxlastbar; j++) {
773        unsigned long in;        unsigned long in;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

svn@ximalas.info
ViewVC Help
Powered by ViewVC 1.3.0-dev