Raw Sockets

Pedro Estrela pedro.estrela
Thu May 8 15:14:44 PDT 2003


Hi,

I'm using these functions to generate ARP packts directly to the wireless
medium, and they are tested with prism2 cards. Use/Modify/Compare then to
your case to see what is wrong!

feel free to ask more help, if needed.

regards,
Pedro Estrela

static int low_arp_sockid;

int init_low_arp_send(void)

{

if((low_arp_sockid = socket(AF_INET,SOCK_PACKET,htons(ETH_P_802_3)))<0)

{

perror("Socket call failed in init_low_arp_send\n");

exit(1);

}


return low_arp_sockid;

}



void close_low_arp_send(void)

{

close(low_arp_sockid);

}



void low_full_arp_send(char *device, unsigned short op,

char *eth_dst, char *eth_src,

char *s_hwaddr, unsigned long *s_ipaddr,

char *d_hwaddr, unsigned long *d_ipaddr

)

{

char frame[ sizeof(struct ethhdr) + sizeof(Arphdr)];

struct ethhdr *ehdr;

Arphdr *ahdr;

struct sockaddr sa;

struct in_addr sin_addr;

printf("==> low_full_arp_send (%s %s)\n", device, long2IP(*s_ipaddr));


bzero((void*)frame, sizeof(frame));

/* Ethernet header */

ehdr = (struct ethhdr*)frame;

memcpy(ehdr->h_dest, eth_dst, 6);

memcpy(ehdr->h_source, eth_src, 6);

ehdr->h_proto = htons(ETH_P_ARP);

/* Arp header */

ahdr = (Arphdr*)(frame + sizeof(struct ethhdr));


ahdr->ar_hrd = htons(1);

ahdr->ar_pro = htons(ETH_P_IP);

ahdr->ar_hln = 6;

ahdr->ar_pln = 4;

ahdr->ar_op = htons(op);

memcpy(ahdr->ar_sha, s_hwaddr, 6);

memcpy(ahdr->ar_sip, s_ipaddr, 4);


memcpy(ahdr->ar_tha, d_hwaddr, 6);

memcpy(ahdr->ar_tip, d_ipaddr, 4);

sa.sa_family = AF_INET;

strcpy(sa.sa_data, device);


if(sendto(low_arp_sockid, frame, sizeof(frame), 0, &sa, sizeof(sa))<0)

{

perror("Sendto failed:");

exit(-1);

}


printf("<== low_arp_full_send\n");

};





> Ok, I've written a little program to simplify as much as possible the code
> that doesn't work.  The example program opens up a raw socket and sends an
> Ethernet packet (type 1535) every second.
>
> I ran the program on my linux box as so: (eth0 is a realtek card)
>
> rawsocket eth0
>
> And on another machine I go:
>
> tcpdump -i eth0 ether proto 1535
>
> I will see one packet per second.
> I then run the program as so: (eth2 is an aironet wireless card associated
> to a cisco bridge)
>
> rawsocket eth2
>
> And on the other machine I will see 1 packet per second.  If I pull out
the
> aironet card, and slide in the prismII card, configure it to Managed mode
> and to the proper essid and then go:
>
> rawsocket wlan0
>
> I see nothing on the other computer as far as my packets go.  If I run the
> tcpdump on the machine with the prism card in it, I can see the packets as
> they're going "out", they just never show up on the subnet from the point
of
> view of the other computers.
>
>
> I'm hoping that someone better with kernel code than me can fix this
> problem, I cannot find one single reference on writing linux Ethernet
> drivers.
>
> David
>
> Btw, I'm using release 0.0.2, and a "Long Range Wireless LAN PC Card" from
> "Wireless LAN Simple Mobility" pcmcia card.   I've also tried and failed
> with agera mini pci cards.
>
>
> -----Original Message-----
> From: Michael Smith [mailto:msmith at cbnco.com]
> Sent: Thursday, May 08, 2003 12:08 PM
> To: Dave Hinkle
> Cc: hostap at shmoo.com
> Subject: Re: Raw Sockets
>
> On Thu, 8 May 2003, Dave Hinkle wrote:
>
> > My first question is, does anybody know off hand why this doesn't work?
> Do
> > I need to encapsulate my Ethernet packet inside some sort of 802.11
packet
> > for this driver?  If nobody knows off hand why it doesn't work I'll
write
> up
> > a simplified piece of example code that fails on hostap cards.
>
> Hi Dave,
>
> I've used raw sockets to test bandwidth with HostAP. Back then I
> was using the 2002-05-12 release I think, and DWL-520's and NL-2511 Senao
> cards.
>
> There is nothing special to the encapsulation - just send plain Ethernet
> frames, i.e. it should work over a wired network too.
>
> Mike
>
>






More information about the Hostap mailing list