Changeset 1708aa8


Ignore:
Timestamp:
09/05/07 11:41:27 (14 years ago)
Author:
Scott Raynel <smr26@…>
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:
34e22d1
Parents:
27bd348
Message:

Fix trace_get_source_mac() for wireless frames. Returns NULL if the frame
does not contain a source MAC, otherwise returns addr2 in all other cases.

Fixes #253

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/protocols.c

    r1344aa8 r1708aa8  
    695695}
    696696
     697/* Take a pointer to the start of an IEEE 802.11 MAC frame and return a pointer
     698 * to the source MAC address. 
     699 * If the frame does not contain a sender address, e.g. ACK frame, return NULL.
     700 * If the frame is a 4-address WDS frame, return TA, i.e. addr2.
     701 * NB: This function decodes the 802.11 header, so it assumes that there are no
     702 * bit-errors. If there are, all bets are off.
     703 */
     704static
     705uint8_t *get_source_mac_from_wifi(void *wifi) {
     706        if (wifi == NULL) return NULL;
     707        struct libtrace_80211_t *w = (struct libtrace_80211_t *) wifi;
     708       
     709        /* If the frame is of type CTRL */
     710        if (w->type == 0x1)
     711                /* If bit 2 of the subtype field is zero, this indicates that
     712                 * there is no transmitter address, i.e. the frame is either an
     713                 * ACK or a CTS frame */
     714                if ((w->subtype & 0x2) == 0)
     715                        return NULL;
     716
     717        /* Always return the address of the transmitter, i.e. address 2 */
     718        return (uint8_t *) &w->mac2;
     719}
    697720
    698721uint8_t *trace_get_source_mac(libtrace_packet_t *packet) {
    699722        void *link = trace_get_link(packet);
    700         libtrace_80211_t *wifi;
    701723        libtrace_ether_t *ethptr = (libtrace_ether_t*)link;
    702724        if (!link)
    703725                return NULL;
    704726        switch (trace_get_link_type(packet)) {
     727                case TRACE_TYPE_80211_RADIO:
     728                        link = trace_get_payload_from_radiotap(
     729                                        link, NULL, NULL);
     730                        /* Fall through for 802.11 */
    705731                case TRACE_TYPE_80211:
    706                         wifi=(libtrace_80211_t*)link;
    707                         return (uint8_t*)&wifi->mac2;
    708                 case TRACE_TYPE_80211_RADIO:
    709                         wifi=(libtrace_80211_t*)trace_get_payload_from_radiotap(
    710                                         link,NULL,NULL);
    711                         return (uint8_t*)&wifi->mac1;
     732                        return get_source_mac_from_wifi(link);
    712733                case TRACE_TYPE_80211_PRISM:
    713                         wifi=(libtrace_80211_t*)((char*)link+144);
    714                         return (uint8_t*)&wifi->mac2;
     734                        link = ((char*)link+144);
     735                        return get_source_mac_from_wifi(link);
    715736                case TRACE_TYPE_ETH:
    716737                        return (uint8_t*)&ethptr->ether_shost;
Note: See TracChangeset for help on using the changeset viewer.