Changeset 4e65f42


Ignore:
Timestamp:
05/11/06 11:40:21 (15 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
83445f0
Parents:
3fcb8b4
Message:

Fixed segmentation faults when trace_destroy is called on a trace that wasn't successfully created
libdl is now checked for and only linked against if available (BSD's don't have a libdl)
Fixed the libpacketdump .so's to use libtrace's generic protocol headers as well as trace_ether_ntoa
Added missing check for strlcpy
Added a couple of #defines to various tools that needed them under FreeBSD
Removed some needless #includes from the libpacketdump .so's

Files:
17 edited

Legend:

Unmodified
Added
Removed
  • configure.in

    r77285d9 r4e65f42  
    3232AC_PROG_CXX
    3333AC_PROG_INSTALL
    34 AC_LIBTOOL_DLOPEN
     34#AC_LIBTOOL_DLOPEN
    3535AC_PROG_LIBTOOL
    3636
     
    4747# Checks for library functions.
    4848AC_PROG_GCC_TRADITIONAL
    49 AC_CHECK_FUNCS(socket strdup)
     49AC_CHECK_FUNCS(socket strdup strlcpy)
    5050
    5151AC_CHECK_SIZEOF([long int])
     
    132132             [AC_DEFINE(HAVE_GDC_H,1,[Conditional for building with libGDC support]) libtrace_gdc=true],
    133133             [AC_DEFINE(HAVE_GDC_H,0,[Conditional for building with libGDC support]) libtrace_gdc=false])
     134
     135# Check to see if we have libdl - *BSD has built-in libdl
     136AC_CHECK_LIB(dl, dlopen, libtrace_dl=true, libtrace_dl=false)
     137if test "$libtrace_dl" = true; then
     138        AC_DEFINE(HAVE_LIBDL,1,[Conditional for building with dynamic library support])
     139        ADD_LIBS="$ADD_LIBS -ldl"
     140else
     141        AC_DEFINE(HAVE_LIBDL,0,[Conditional for building with dynamic library support])
     142fi
    134143
    135144
  • lib/trace.c

    r77285d9 r4e65f42  
    577577DLLEXPORT void trace_destroy(libtrace_t *libtrace) {
    578578        assert(libtrace);
    579         if (libtrace->started && libtrace->format->pause_input)
    580                 libtrace->format->pause_input(libtrace);
    581         libtrace->format->fin_input(libtrace);
     579        if (libtrace->format) {
     580                if (libtrace->started && libtrace->format->pause_input)
     581                        libtrace->format->pause_input(libtrace);
     582                libtrace->format->fin_input(libtrace);
     583        }
    582584        /* need to free things! */
    583         free(libtrace->uridata);
    584         destroy_tracefifo(libtrace->fifo);
     585        if (libtrace->uridata)
     586                free(libtrace->uridata);
     587        if (libtrace->fifo)
     588                destroy_tracefifo(libtrace->fifo);
    585589        free(libtrace);
    586590}
  • libpacketdump/Makefile.am

    re5f1431 r4e65f42  
    1515
    1616INCLUDES= @ADD_INCLS@ -I../lib -I../
    17 libpacketdump_la_LIBADD = @ADD_LIBS@  -ldl
     17libpacketdump_la_LIBADD = @ADD_LIBS@ 
    1818libpacketdump_la_LDFLAGS=\
    1919        -version-info @LIBTRACE_MAJOR@:@LIBTRACE_MINOR@:@LIBTRACE_MID@ \
     
    3333
    3434install-exec-local:
    35         for plugin in $(PLUGINS); do install -D -m 755 $$plugin $(DESTDIR)$(PLUGINDIR)/$$plugin; done
     35        mkdir -p $(DESTDIR)$(PLUGINDIR); for plugin in $(PLUGINS); do install -m 755 $$plugin $(DESTDIR)$(PLUGINDIR)/$$plugin; done
    3636
    3737uninstall-local:
  • libpacketdump/eth_2048.cc

    r010fafb r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    32#include <stdio.h>
    43#include <inttypes.h>
    54#include <dlfcn.h>
    6 #include <map>
    75#include "libpacketdump.h"
    86#include <sys/socket.h>
     7#ifndef WIN32
     8        #include <netinet/in_systm.h>
     9#endif
    910#include <netinet/in.h>
    1011#include <netinet/ip.h>
     
    2627void decode(int link_type,char *packet,int len)
    2728{
    28         struct iphdr *ip = (struct iphdr*)packet;
     29        libtrace_ip_t *ip = (libtrace_ip_t*)packet;
    2930        if (len>=1) {
    30                 printf(" IP: Header Len %i",ip->ihl*4);
    31                 printf(" Ver %i",ip->version);
     31                printf(" IP: Header Len %i",ip->ip_hl*4);
     32                printf(" Ver %i",ip->ip_v);
    3233        }
    33         DISPLAY(tos," TOS %02x")
    34         DISPLAYS(tot_len," Total Length %i")
     34        DISPLAY(ip_tos," TOS %02x")
     35        DISPLAYS(ip_len," Total Length %i")
    3536        printf("\n IP:");
    36         DISPLAY(id," Id %i");
    37         DISPLAY(frag_off," Fragoff %i");
     37        DISPLAY(ip_id," Id %i");
     38       
     39        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
     40                printf(" \n Fragoff %i", ip->ip_off);
     41                if (ip->ip_mf) printf(" MORE_FRAG");
     42                if (ip->ip_df) printf(" DONT_FRAG");
     43                if (ip->ip_rf) printf(" RESV_FRAG");
     44        }
    3845        //printf("\n IP:");
    39         DISPLAY(ttl," TTL %i");
    40         if ((unsigned int)len>=((char*)&ip->protocol-(char*)ip+sizeof(ip->protocol))) {
    41                 struct protoent *ent=getprotobynumber(ip->protocol);
     46        DISPLAY(ip_ttl,"\n TTL %i");
     47        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
     48                struct protoent *ent=getprotobynumber(ip->ip_p);
    4249                if (ent) {
    43                         printf(" Proto %i (%s)",ip->protocol,ent->p_name);
     50                        printf(" Proto %i (%s)",ip->ip_p,ent->p_name);
    4451                }
    4552                else {
    46                         printf(" Proto %i",ip->protocol);
     53                        printf(" Proto %i",ip->ip_p);
    4754                }
    4855        } else {
     
    5057                return;
    5158        }
    52         DISPLAYS(check," Checksum %i\n");
    53         DISPLAYIP(saddr," IP: Source %s ");
    54         DISPLAYIP(daddr,"Destination %s\n");
    55         decode_next(packet+sizeof(*ip),len-sizeof(*ip),"ip",ip->protocol);
     59        DISPLAYS(ip_sum," Checksum %i\n");
     60        DISPLAYIP(ip_src," IP: Source %s ");
     61        DISPLAYIP(ip_dst,"Destination %s\n");
     62        decode_next(packet+sizeof(*ip),len-sizeof(*ip),"ip",ip->ip_p);
    5663        return;
    5764}
  • libpacketdump/eth_2054.cc

    r950d54a r4e65f42  
    11/* ARP */
    2 #include <netinet/ether.h>
    3 #include <netinet/in.h>
    42#include <stdio.h>
    53#include <inttypes.h>
    64#include <dlfcn.h>
    7 #include <map>
    85#include "libpacketdump.h"
    96#include <sys/socket.h>
     7#ifndef WIN32
     8        #include <netinet/in_systm.h>
     9#endif
    1010#include <netinet/in.h>
    1111#include <netinet/ip.h>
    1212#include <net/if_arp.h>
    1313#include <arpa/inet.h>
     14#include <string.h>
    1415
    1516#define DISPLAY_EXP(x,fmt,exp) \
     
    2728{
    2829        static char buffer[1024];
     30        char ether_buf[18] = {0, };
    2931        if (hrd==NULL)
    3032                return "Truncated (Truncated)";
    3133        switch(arp->ar_hrd) {
    3234                case ARPHRD_ETHER:
    33                         strcpy(buffer,ether_ntoa((struct ether_addr*)&hrd));
     35                        strcpy(buffer,trace_ether_ntoa((uint8_t *)&hrd,
     36                                                ether_buf));
    3437                        break;
    3538                default:
  • libpacketdump/ip_1.cc

    r950d54a r4e65f42  
    22#include <inttypes.h>
    33#include <dlfcn.h>
    4 #include <map>
    54#include "libpacketdump.h"
    6 #include <netinet/ip_icmp.h>
    7 #include <netinet/in.h>
    85
    96#define STRUCT icmp
     
    4542void decode(int link_type,char *packet,int len)
    4643{
    47         struct icmphdr *icmp = (struct icmphdr*)packet;
     44        libtrace_icmp_t *icmp = (libtrace_icmp_t*)packet;
    4845        if (len<1)
    4946                return;
  • libpacketdump/ip_6.cc

    r010fafb r4e65f42  
    22#include <inttypes.h>
    33#include <dlfcn.h>
    4 #include <map>
    54#include "libpacketdump.h"
    6 #include <netinet/tcp.h>
    7 #include <netinet/in.h>
    85#include <assert.h>
    96#include <netdb.h>
     
    5249void decode(int link_type,char *packet,int len)
    5350{
    54         struct tcphdr *tcp = (struct tcphdr*)packet;
     51        libtrace_tcp_t *tcp = (libtrace_tcp_t *)packet;
    5552        printf(" TCP:");
    5653        if (SAFE(source)) {
  • libpacketdump/link_0.cc

    r950d54a r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    32#include <stdio.h>
    43#include <inttypes.h>
    54#include <dlfcn.h>
    6 #include <map>
    75#include "libpacketdump.h"
    86
  • libpacketdump/link_10.cc

    r3b8a5ef r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    32#include <stdio.h>
    43#include <inttypes.h>
    54#include <dlfcn.h>
    6 #include <map>
    75#include "libpacketdump.h"
    86#include "libtrace.h"
  • libpacketdump/link_11.cc

    r3b8a5ef r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    3 #include <net/ethernet.h>
    42#include <stdio.h>
    53#include <inttypes.h>
    64#include <dlfcn.h>
    7 #include <map>
    85#include "libpacketdump.h"
    96
  • libpacketdump/link_2.cc

    r1851624 r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    32#include <stdio.h>
    43#include <inttypes.h>
    54#include <dlfcn.h>
    6 #include <map>
     5#include "libtrace.h"
    76#include "libpacketdump.h"
    87
     
    109void decode(int link_type,char *packet,int len)
    1110{
     11        char ether_buf[18] = {0, };
    1212        printf(" Ethernet:");
    1313        if (len>=6)
    14                 printf(" Dest: %s",ether_ntoa((struct ether_addr*)packet));
     14                printf(" Dest: %s",trace_ether_ntoa((uint8_t *)packet,
     15                                        ether_buf));
    1516        else {
    1617                printf("[|Truncated]\n");
     
    1819        }
    1920        if (len>=12)
    20                 printf(" Source: %s",ether_ntoa((struct ether_addr*)(packet+6)));
     21                printf(" Source: %s",trace_ether_ntoa((uint8_t*)(packet+6),
     22                                        ether_buf));
    2123        else {
    2224                printf("[|Truncated]\n");
  • libpacketdump/link_4.cc

    r950d54a r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    32#include <stdio.h>
    43#include <inttypes.h>
    54#include <dlfcn.h>
    6 #include <map>
    75#include "libpacketdump.h"
     6#include "libtrace.h"
    87
    98struct ieee_802_11_header {
     
    3635void decode(int link_type,char *packet,int len)
    3736{
     37        char ether_buf[18] = {0, };
    3838        printf(" 802.11:");
    3939        struct ieee_802_11_header *hdr = (struct ieee_802_11_header *)packet;
    4040
    41         printf(" %s",ether_ntoa((struct ether_addr*)(hdr->mac1)));
    42         printf(" %s",ether_ntoa((struct ether_addr*)(hdr->mac2)));
    43         printf(" %s",ether_ntoa((struct ether_addr*)(hdr->mac3)));
     41        printf(" %s",trace_ether_ntoa((uint8_t*)(hdr->mac1), ether_buf));
     42        printf(" %s",trace_ether_ntoa((uint8_t*)(hdr->mac2), ether_buf));
     43        printf(" %s",trace_ether_ntoa((uint8_t*)(hdr->mac3), ether_buf));
    4444
    4545        struct ieee_802_11_payload *pld = (struct ieee_802_11_payload *) ((int)packet + sizeof(struct ieee_802_11_header) - 2);
  • libpacketdump/link_9.cc

    r3b8a5ef r4e65f42  
    1 #include <netinet/ether.h>
    21#include <netinet/in.h>
    32#include <stdio.h>
    43#include <inttypes.h>
    54#include <dlfcn.h>
    6 #include <map>
    75#include "libpacketdump.h"
    86
  • tools/traceanon/ipenc.c

    r49f147b r4e65f42  
     1#include "config.h"
    12#include "ipenc.h"
    23#include "panon.h"
  • tools/tracedump/Makefile.am

    r1b4bc75 r4e65f42  
    55include ../Makefile.tools
    66tracedump_SOURCES = tracedump.cc
    7 tracedump_LDADD = -ltrace -lpacketdump -ldl
     7tracedump_LDADD = -ltrace -lpacketdump  
  • tools/tracertstats/tracertstats.c

    r9c4b5e3 r4e65f42  
    5757#include "dagformat.h"
    5858
     59#ifndef UINT32_MAX
     60        #define UINT32_MAX      0xffffffffU
     61#endif
     62
    5963struct libtrace_t *trace;
    6064char *output_format=NULL;
  • tools/tracestats/tracestats.c

    rd56089a r4e65f42  
    5252
    5353#include "libtrace.h"
     54
     55#ifndef PRIu64
     56        #define PRIu64 "llu"
     57#endif
    5458
    5559struct libtrace_t *trace;
Note: See TracChangeset for help on using the changeset viewer.