Changeset 59751a5 for tools


Ignore:
Timestamp:
03/23/09 17:01:09 (12 years ago)
Author:
Perry Lorier <perry@…>
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:
5dd06d6
Parents:
d4242e4
Message:

have trace_get_source_address() / trace_get_destination_address() return link layer addresses
where possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracetop/tracetop.cc

    rd4242e4 r59751a5  
    1313#include <sys/socket.h>
    1414#include <netdb.h>
     15#include "config.h"
     16#ifdef HAVE_NETPACKET_PACKET_H
     17#include <sys/socket.h>
     18#include <netpacket/packet.h>
     19#include <net/ethernet.h>
     20#endif
     21
     22typedef enum { BITS_PER_SEC, BYTES } display_t;
     23display_t display_as = BYTES;
    1524
    1625int cmp_sockaddr_in6(const struct sockaddr_in6 *a, const struct sockaddr_in6 *b)
     
    2736        return a->sin_addr.s_addr - b->sin_addr.s_addr;
    2837}
     38
     39#ifdef HAVE_NETPACKET_PACKET_H
     40int cmp_sockaddr_ll(const struct sockaddr_ll *a, const struct sockaddr_ll *b)
     41{
     42        return memcmp(a->sll_addr, b->sll_addr, b->sll_halen);
     43}
     44#endif
    2945
    3046int cmp_sockaddr(const struct sockaddr *a, const struct sockaddr *b)
     
    3854                case AF_INET6:
    3955                        return cmp_sockaddr_in6((struct sockaddr_in6 *)a,(struct sockaddr_in6*)b);
     56#ifdef HAVE_NETPACKET_PACKET_H
     57                case AF_PACKET:
     58                        return cmp_sockaddr_ll((struct sockaddr_ll *)a,(struct sockaddr_ll*)b);
     59#endif
    4060                case AF_UNSPEC:
    4161                        return 0; /* Can't compare UNSPEC's! */
     
    5272        size_t mybufflen = buffer ? bufflen : sizeof(intbuffer);
    5373        int err;
    54         if ((err=getnameinfo(a, salen, mybuf, mybufflen, NULL, 0, NI_NUMERICHOST))!=0) {
    55                 strncpy(mybuf,gai_strerror(err),mybufflen);
     74        switch (a->sa_family) {
     75                case AF_INET:
     76                case AF_INET6:
     77                        if ((err=getnameinfo(a, salen, mybuf, mybufflen, NULL, 0, NI_NUMERICHOST))!=0) {
     78                                strncpy(mybuf,gai_strerror(err),mybufflen);
     79                        }
     80                        break;
     81#ifdef HAVE_NETPACKET_PACKET_H
     82                case AF_PACKET:
     83                        trace_ether_ntoa(((struct sockaddr_ll*)a)->sll_addr, mybuf);
     84                        break;
     85#endif
     86                default:
     87                        snprintf(mybuf,mybufflen,"Unknown family %d",a->sa_family);
    5688        }
    5789        return mybuf;
     
    94126        flows_t::iterator it;
    95127
    96         if (trace_get_source_address(packet,(struct sockaddr*)&flowkey.sip)==0)
     128        if (trace_get_source_address(packet,(struct sockaddr*)&flowkey.sip)==NULL)
    97129                flowkey.sip.ss_family = AF_UNSPEC;
    98         if (trace_get_destination_address(packet,(struct sockaddr*)&flowkey.dip)==0)
     130        if (trace_get_destination_address(packet,(struct sockaddr*)&flowkey.dip)==NULL)
    99131                flowkey.dip.ss_family = AF_UNSPEC;
    100132        trace_get_transport(packet,&flowkey.protocol, NULL);
     
    112144        ++it->second.packets;
    113145        it->second.bytes+=trace_get_capture_length(packet);
     146
    114147}
    115148
Note: See TracChangeset for help on using the changeset viewer.