Re: ARP program & sockets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 15 Dec 2001, Casey Carter wrote:

> AF_INET?
> 
> Amit Kucheria wrote:
> 
> > Can anybody explain whats wrong with the following piece of code?
> > 
> > Specifically, the bind() fails. I have a clue that its something to do 
> > with packet sockets, but what ? I checked my kernel, packet sockets are 
> > compiled in.
> > 
> > -------------------------------------------------
> > struct sockaddr_ll me, he;
> > 
> > int main(int argc, char *argv[])
> > {
> >     struct sockaddr hwaddr;
> >     
> >     if (argc < 2)
> >     {
> >         usage(argv[0]);
> >         exit(1);
> >     }
> >     strcpy(device, argv[1]);
> >     
> >     sockfd = socket(PF_PACKET, SOCK_DGRAM, 0);
> >     if (sockfd < 0)
> >     {
> >         DBG("main(): unable to create socket\n");
> >         perror("main()");
> >         return -1;
> >     }
> > 
> >     req_dest.s_addr = address_generate(); /* linklocal address we want to own */
> >     req_src.s_addr = 0;  /* send with IP addr 0.0.0.0 */
> >     
> >     ret = get_ether_addr(device, &hwaddr);
> >     if (ret < 0)
> >     {
> >         ERR("main(): get_ether_addr failed\n");
> >         exit(-1);
> >     }
> >     me.sll_family = AF_INET;
> >     me.sll_ifindex = ifindex;
> >     me.sll_protocol = htons(ETH_P_ARP);
> >     if (bind(sockfd, (struct sockaddr*)&me, sizeof(me)) == -1) 
> >     {
> > 		perror("main(): bind");
> > 		exit(2);
> >     }

But i need to use PF_PACKET type to create a socket to 'bypass' the 
protocol layers and send the packet directly to the ethernet layer (link 
layer). I dont think AF_INET with SOCK_RAW would support struct 
sockaddr_ll.

Regards,
Amit

-- 
The statement below is true.
The statement above is false.
^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
                  Amit Kucheria
          EECS Grad. Research Assistant
         University of Kansas @ Lawrence
   (R)+1-(785)-830 8521 ||| (O)+1-(785)-864 7774
____________________________________________________

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux