I've grabbed snippets from both interface.c and ifconfig.c of the net-tools
package and have tried the following (linking with libnet-tools.a)..
int skfd = -1;
int main(void){
struct interface ife;
int ret;
memset(&ife,0,sizeof(struct interface));
strcpy(ife.name, "eth0");
ret = if_fetch(&ife);
}
/* Fetch the interface configuration from the kernel. */
int if_fetch(struct interface *ife)
{
struct ifreq ifr;
int fd;
char *ifname = ife->name;
/* Create a channel to the NET kernel. */
if ((skfd = sockets_open(0)) < 0) {
perror("socket");
exit(1);
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0){
memset(ife->hwaddr, 0, 32);
printf("Zero\n");
}
else{
memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8);
printf("Not Zero: %s\n",ife->hwaddr);
}
return(1);
}
which doesn't seem to work. It prints out a blank HWADDR. No errors, though.
I also tried using parts from inconfig.c's ife_print function. It prints out
the correct name 'eth0' .. but prints out a blank HWADDR and wrong 'encap:
'. Can anyone point me in the direction of an ioctl howto??
Thanks
-Andy
> -----Original Message-----
> From: Malcolm Dodds [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 20, 2000 6:25 AM
> To: Andy Angrick
> Cc: [EMAIL PROTECTED]
> Subject: Re: Retrieving IP/MAC
>
>
> There are ioctls for this.
>
> For the MAC address:
> SIOCGIFHWADDR
>
> For the IP address:
> SIOCGIFADDR
>
> For the Sub net mask:
> SIOCGIFNETMASK
>
> There are also equivalent set ioctls for the address and mask.
> (Substitue G with
> S in the names).
>
> (Look at the ifconfig source code if unsure how to use them).
>
> Malcolm.
>
> Andy Angrick wrote:
>
> > Does anyone know of a more elegant way to retrieve the IP
> address and MAC
> > address of a network adapter other than parsing the output from
> ifconfig. Is
> > there a proc file where you can get this info or some other place?
> >
> > -Andy
--
To unsubscribe from this list, send a message to [EMAIL PROTECTED]
with the command "unsubscribe linux-embedded" in the message body.
For more information, see <http://waste.org/mail/linux-embedded>.