[Olsr-users] olsr.org olsrd and nrlsmf
Bernd Petrovitsch
(spam-protected)
Wed Aug 27 22:47:38 CEST 2008
On Die, 2008-08-19 at 09:18 +0200, Roar Bjørgum Rotvik wrote:
[...]
> Or just use ioctl(), here is a short example:
Cute. But where does this actually work?
Because my recent Linux kernels needs the device name too as added below
(yes, one wants to make it a parameter of the function).
Otherwise I get a "No such device".
> Input is IPv4 address (ip argument), returned MAC is in hw_addr as a 6 byte unsigned char
> array. Flags is for any arp-flags.
>
> bool arp_get (const in_addr_t ip, unsigned char *hw_addr, int *flags)
> {
> int ret;
> int fd;
> struct arpreq arpreq = {0};
> struct sockaddr_in *sin = NULL;
>
> fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_IP);
> if (fd == -1) {
> return false;
> }
> sin = (struct sockaddr_in *)&arpreq.arp_pa;
> sin->sin_family = AF_INET;
> sin->sin_addr.s_addr = ip;
strncpy(arpreq.arp_dev, "eth0", sizeof(arpreq.arp_dev));
>
> ret = ioctl (fd, SIOCGARP, &arpreq);
> if (ret == -1) {
> return false;
> }
> memcpy (hw_addr, &arpreq.arp_ha.sa_data[0], 6);
> if (flags) {
> *flags = arpreq.arp_flags;
> }
> close (fd);
> return true;
> }
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
More information about the Olsr-users
mailing list