Changeset 3c2ddf4


Ignore:
Timestamp:
07/30/10 11:51:22 (11 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:
ba2263a
Parents:
f2b53d2
Message:
  • Added support for sockaddr_dl to the trace_get_*_ethernet_address functions - should fix the warnings about unused variables AND provide extra functionality
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/protocols_l3.c

    rf6730d8 r3c2ddf4  
    4444#include <net/ethernet.h>
    4545#include <net/if_arp.h>
     46#include <string.h>
     47#else
     48#include <net/if_dl.h>
    4649#include <string.h>
    4750#endif
     
    314317        libtrace_ether_t *ethernet, struct sockaddr *addr)
    315318{
     319        static struct sockaddr_storage dummy;
    316320#ifdef HAVE_NETPACKET_PACKET_H
    317321/* Use linux's sockaddr_ll structure */
    318         static struct sockaddr_storage dummy;
    319322        struct sockaddr_ll *l2addr;
    320323
     
    334337        return (struct sockaddr*)l2addr;
    335338#else
    336 /* TODO: implement BSD's sockaddr_dl structure, sigh. */
    337         return NULL;
     339/* Use BSD's sockaddr_dl structure */
     340        struct sockaddr_dl *l2addr;
     341
     342        if (addr)
     343                l2addr = (struct sockaddr_dl *)addr;
     344        else
     345                l2addr = (struct sockaddr_dl *)&dummy;
     346       
     347        l2addr->sdl_family = AF_LINK;
     348        l2addr->sdl_len = sizeof(struct sockaddr_dl);
     349        l2addr->sdl_index = 0; /* Unused */
     350        l2addr->sdl_alen = 6; /* Address length  */
     351        l2addr->sdl_nlen = 0; /* No name in here - this *should* work, right? */
     352        l2addr->sdl_slen = 0;   
     353        l2addr->sdl_type = 0; /* Hopefully zero is OK for this value too */
     354        memcpy(l2addr->sdl_data, ethernet->ether_shost, 6);
     355
     356        return (struct sockaddr *)l2addr;
    338357#endif
    339358}
     
    419438        libtrace_ether_t *ethernet, struct sockaddr *addr)
    420439{
     440        static struct sockaddr_storage dummy;
    421441#ifdef HAVE_NETPACKET_PACKET_H
    422442/* Use linux's sockaddr_ll structure */
    423         static struct sockaddr_storage dummy;
    424443        struct sockaddr_ll *l2addr;
    425444        if (addr)
     
    438457        return (struct sockaddr*)l2addr;
    439458#else
    440 /* TODO: implement BSD's sockaddr_dl structure, sigh. */
    441         return NULL;
     459/* Use BSD's sockaddr_dl structure */
     460        struct sockaddr_dl *l2addr;
     461
     462        if (addr)
     463                l2addr = (struct sockaddr_dl *)addr;
     464        else
     465                l2addr = (struct sockaddr_dl *)&dummy;
     466       
     467        l2addr->sdl_family = AF_LINK;
     468        l2addr->sdl_len = sizeof(struct sockaddr_dl);
     469        l2addr->sdl_index = 0; /* Unused */
     470        l2addr->sdl_alen = 6; /* Address length  */
     471        l2addr->sdl_nlen = 0; /* No name in here - this *should* work, right? */
     472        l2addr->sdl_slen = 0;   
     473        l2addr->sdl_type = 0; /* Hopefully zero is OK for this value too */
     474        memcpy(l2addr->sdl_data, ethernet->ether_dhost, 6);
     475
     476        return (struct sockaddr *)l2addr;
    442477#endif
    443478}
Note: See TracChangeset for help on using the changeset viewer.