Changeset 1267

Show
Ignore:
Timestamp:
05/09/07 20:51:56 (1 year ago)
Author:
smr26
Message:

Internal changes to trace_get_source_mac(). Now deals with Linux SLL headers :)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/protocols.c

    r1263 r1267  
    266266        } 
    267267 
    268         if (type) *type = 0
     268        if (type) *type = TRACE_TYPE_80211
    269269 
    270270        return (void *) ((char*)link+144); 
     
    283283        } 
    284284 
    285         if (type) *type = 0
     285        if (type) *type = TRACE_TYPE_80211
    286286 
    287287        return (void*) ((char*)link + rtaplen); 
     
    718718} 
    719719 
    720 uint8_t *trace_get_source_mac(libtrace_packet_t *packet) { 
    721         void *link = trace_get_link(packet); 
    722         libtrace_ether_t *ethptr = (libtrace_ether_t*)link; 
     720static 
     721uint8_t *__trace_get_source_mac(void *link, libtrace_linktype_t *linktype, uint32_t *rem) { 
     722        libtrace_ether_t *ethptr = (libtrace_ether_t *) link; 
     723        uint16_t arphrd; 
    723724        if (!link) 
    724725                return NULL; 
    725         switch (trace_get_link_type(packet)) { 
     726         
     727        switch (*linktype) { 
     728                case TRACE_TYPE_ETH: 
     729                        return (uint8_t *)&ethptr->ether_shost; 
     730                case TRACE_TYPE_80211: 
     731                        return get_source_mac_from_wifi(link); 
    726732                case TRACE_TYPE_80211_RADIO: 
    727733                        link = trace_get_payload_from_radiotap( 
    728                                         link, NULL, NULL); 
    729                         /* Fall through for 802.11 */ 
    730                 case TRACE_TYPE_80211: 
    731                         return get_source_mac_from_wifi(link); 
     734                                        link, linktype, rem); 
     735                        return __trace_get_source_mac(link, linktype, rem); 
    732736                case TRACE_TYPE_80211_PRISM: 
    733                         link = ((char*)link+144); 
    734                         return get_source_mac_from_wifi(link); 
    735                 case TRACE_TYPE_ETH: 
    736                         return (uint8_t*)&ethptr->ether_shost; 
     737                        link = trace_get_payload_from_prism( 
     738                                        link, linktype, rem); 
     739                        return __trace_get_source_mac(link, linktype, rem); 
     740                case TRACE_TYPE_LINUX_SLL: 
     741                        link = trace_get_payload_from_linux_sll( 
     742                                        link, &arphrd, rem); 
     743                        *linktype = arphrd_type_to_libtrace(arphrd); 
     744                        return __trace_get_source_mac(link, linktype, rem); 
    737745                case TRACE_TYPE_POS: 
    738746                case TRACE_TYPE_NONE: 
    739747                case TRACE_TYPE_HDLC_POS: 
    740                 case TRACE_TYPE_LINUX_SLL: 
    741748                case TRACE_TYPE_PFLOG: 
    742749                case TRACE_TYPE_ATM: 
     
    747754                        break; 
    748755        } 
    749         fprintf(stderr,"Not implemented\n"); 
     756        fprintf(stderr,"%s not implemented for linktype %i\n", __func__, *linktype); 
    750757        assert(0); 
    751758        return NULL; 
     759} 
     760 
     761DLLEXPORT uint8_t *trace_get_source_mac(libtrace_packet_t *packet) { 
     762        if (packet == NULL)  
     763                return NULL; 
     764        void *link = trace_get_link(packet); 
     765        uint32_t len = trace_get_capture_length(packet); 
     766        libtrace_linktype_t lt = trace_get_link_type(packet); 
     767        return __trace_get_source_mac(link, &lt, &len); 
    752768} 
    753769