ioctl SIOCGARP question

From: Guillaume Morin (guillaume@morinfr.org)
Date: Sat Jan 19 2002 - 14:20:45 EST


Hi,

I am trying to play with SIOCGARP. Here is the program

#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if_arp.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <string.h>

#define IP "62.4.22.236"
#define INTERFACE "eth1"

int main(int argc, char ** argv) {
        int s;
        struct arpreq a;
        struct sockaddr_in * sin;
        
        if ((s = socket(AF_INET,SOCK_DGRAM,0) == -1)) {
                perror("socket");
                return -1;
        }
        memset(&a,0,sizeof(a));
        strcpy(a.arp_dev,INTERFACE);
        sin = (struct sockaddr_in *) &(a.arp_pa);
        sin->sin_family = AF_INET;
        if (! inet_aton(IP,&sin->sin_addr)) {
                puts("Cannot convert " IP ".");
                return -1;
        }

        if (ioctl(s,SIOCGARP,&a)) {
                perror("ioctl");
                return -1;
        }

        printf("HWADDR: %x\n",*a.arp_ha.sa_data);
        return 0;
}

ioctl always returns EINVAL. I've looked at net/ipv4/arp.c, I don't see
how this is possible.

Could anyone tell me what I am missing ?

TIA.

-- 
Guillaume Morin <guillaume@morinfr.org>

La vie est facÚtieuse - To unsubscribe from this list: 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



This archive was generated by hypermail 2b29 : Wed Jan 23 2002 - 21:01:13 EST