ARP program & sockets

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

 



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.

Regards,
Amit

-------------------------------------------------
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);
    }
<snip>
--------------------------------------------------

On Sat, 15 Dec 2001, Amit Kucheria wrote:

> On Fri, 14 Dec 2001, James Stevenson wrote:
> 
> > it should not take long just create a raw socket and send and
> > eth header and arp packet you should see it.
> > 
> > as far as i can see this should work i am thinking it is a problem with
> > libnet
> > i have never used it but i have tried other libs that are meant todo the
> > same
> > things but i have always ened up creating my own structs etc.. because they
> > have created nothing but problems then if you need to make it portable you
> > only
> > need to change the socket type between certin OS's
> 
> 

-- 
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