Hi, I am trying to cross compile a program for openwrt to capture the beacon
frames.
The program(beaconCap.c) is as follows.
*************************************************************************************************
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<pcap.h>
#include<errno.h>
#include<arpa/inet.h>
#include<net/ethernet.h>
#include<linux/wireless.h>
#include<netinet/if_ether.h>

typedef struct mac_header
{
    unsigned char fc[2];
    unsigned char id[2];
    unsigned char add1[6];
    unsigned char add2[6];
    unsigned char add3[6];
    unsigned char sc[2];
}mac_header;

typedef struct frame_control
{
    unsigned protocol:2;
    unsigned type:2;
    unsigned subtype:4;
    unsigned to_ds:1;
    unsigned from_ds:1;
    unsigned more_frag:1;
    unsigned retry:1;
    unsigned pwr_mgt:1;
    unsigned more_data:1;
    unsigned wep:1;
    unsigned order:1;
}frame_control;

typedef struct beacon_header
{
    unsigned char timestamp[8];
    unsigned char beacon_interval[2];
    unsigned char cap_info[2];
}beacon_header;


void packet_decoder(u_char * useless, const struct pcap_pkthdr *pkthdr,
const u_char * packet)
{
    printf("Got Packet");
    char ssid[32], *temp;
    struct mac_header *p = (struct mac_header *) packet;
    struct frame_control *control = (struct frame_control *)p->fc;
    temp = (char *)(packet + sizeof(struct mac_header)+sizeof(struct
beacon_header));

    memset (ssid, '\0', 32);
    // check if frame is beacon frame
    if ((control->protocol==0)&&(control->type==0)&&(control->subtype==8))
    {
//temp[1] contains the size of the ssid field and temp[2] the beginning
ofthe ssid string .
    memcpy (ssid, &temp[2], temp[1]);
    printf ("\n\nFound SSID : \n");
    printf ("Destination Add : %s\n", ether_ntoa (p->add1));
    printf ("Source Add : %s\n", ether_ntoa (p->add2));
    printf ("BSSID : %s\n", ether_ntoa (p->add3));
    printf ("ssid = %s\n", ssid);
    }
}

int main(int argc, char **argv)
{
    char *dev = argv[1];
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t *handle;
    if(argc<2)
    {
        printf ("usage : %s capture_device \n", argv[0]);
        exit (1);
    }

    printf ("Initialising capture interface..\n");
//pcap initialisation

    handle = pcap_open_live (dev, BUFSIZ, 1, -1, errbuf);

    if (handle == NULL)
    {
        printf ("pcap_open_live : %s\n", errbuf);
        exit (1);
    }

    printf ("\nStarting Capture ...........\n");
// tell pcap to pass on captures frames to our packet_decoder fn
    pcap_loop(handle, -1, packet_decoder, NULL);
    return (0);
}
*************************************************************************************

I have cross compiled libpcap 1.1 with openwrt mips tool chain in my ubuntu
10.04 64bit.
libpcap in installed in  /usr/local/lib
scorpio@scorpio-desktop:/usr/local/lib$ ls libpcap.
libpcap.a         libpcap.so        libpcap.so.1      libpcap.so.1.1.1

pcap.h in located in /usr/local/include
scorpio@scorpio-desktop:/usr/local/include$ ls pcap.h
pcap.h
only      #include <pcap/pcap.h>
exists in  /usr/local/include/pcap.h
However in /usr/local/include/pcap, another pcap.h is here and this is the
real pcap.h.
*******************************************************************************************************
My problem is when I cross compiled beaconCap.c with
mips-openwrt-linux-gcc beaconCap.c -o beaconCap -L /usr/local/lib/ -I
/usr/local/include/
I got following errors:
/tmp/ccA7FOzC.o: In function `main':
beaconCap.c:   (.text+0x270): undefined reference to `pcap_open_live'
beaconCap.c:   (.text+0x2d8): undefined reference to `pcap_loop'
collect2: ld returned 1 exit status
*******************************************************************************************************
I do not know how to solve it. Actually pcap_open_live and pcap_loop are
declared in  /usr/local/include/pcap/pcap.h

Could any help me? I really need you help.

Thank you,
Jin
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to