DLI/Ethernet interface questions
Jeff Michaud
michaud at decvax.dec.com
Fri Jul 21 08:54:46 AEST 1989
In article <810 at uhnix2.uh.edu>, jh at allez.uh.edu (Jeff Hayward) writes:
> How can I obtain the Ethernet address of a given interface?
As promised, here is the sample program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/ioctl.h>
main(argc, argv)
int argc;
char *argv[];
{
struct ifdevea address;
int sock;
if( argc <= 1 ) {
fprintf(stderr, "Usage: %s device\n", argv[0]);
exit();
}
bzero(&address, sizeof(address));
strcpy(address.ifr_name, argv[1]);
sock = socket(AF_UNIX, SOCK_DGRAM, 0);
if( sock < 0 ) {
perror("socket(AF_UNIX, SOCK_DGRAM, 0)");
exit();
}
if( ioctl(sock, SIOCRPHYSADDR, &address) < 0 ) {
perror("ioctl(SIOCRPHYSADDR)");
exit();
}
close(sock);
printf("Current Physical Address: %02x-%02x-%02x-%02x-%02x-%02x\n",
address.current_pa[0], address.current_pa[1], address.current_pa[2],
address.current_pa[3], address.current_pa[4], address.current_pa[5]);
printf("Default Hardware Address: %02x-%02x-%02x-%02x-%02x-%02x\n",
address.default_pa[0], address.default_pa[1], address.default_pa[2],
address.default_pa[3], address.default_pa[4], address.default_pa[5]);
}
--
/--------------------------------------------------------------\
|Jeff Michaud michaud at decwrl.dec.com michaud at decvax.dec.com|
|DECnet-ULTRIX #include <standard/disclaimer.h> |
\--------------------------------------------------------------/
More information about the Comp.unix.ultrix
mailing list