From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fa528,6252e8e4f140c308 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-04-09 08:44:04 PST Path: supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!newsfeed.berkeley.edu!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!paloalto-snf1.gtei.net!news.gtei.net!news.compaq.com!news.cpqcorp.net!not-for-mail Message-ID: <3AD1D87C.BB2D3CA5@zk3.dec.com> From: Brian Haley X-Mailer: Mozilla 4.76 [en] (X11; U; OSF1 V4.0 alpha) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.unix.tru64 Subject: Re: Ethernet Address: how to change References: <5k83dtc00gfiv3suuk5rj3u398ocserpn3@4ax.com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Date: Mon, 09 Apr 2001 11:42:53 -0400 NNTP-Posting-Host: 16.140.64.151 X-Complaints-To: abuse@Compaq.com X-Trace: news.cpqcorp.net 986830978 16.140.64.151 (Mon, 09 Apr 2001 08:42:58 PDT) NNTP-Posting-Date: Mon, 09 Apr 2001 08:42:58 PDT Organization: Compaq Computer Corporation Xref: supernews.google.com comp.unix.tru64:2058 "Axel K�ster" wrote: > I would like to know how to change the ethernet (MAC) address of an > interface. At linux, I can do so with ifconfig. On True64 Unix I even > dont get the hardware address from the interface. Which version of the OS are you running? On V5.1 and later you can use ifconfig -v to get the hwaddr, and you can always get it with netstat -i. > Is there another command for managing this parameters of the > interface? I've included sources for something that can change the hwaddr using a simple ioctl() call - you can put this in /etc/inet.local so that it gets run at boot time. -Brian -------------------------------------------------- Brian P. Haley enet: haley@zk3.dec.com Tru64 UNIX Networking Group Compaq Computer Corporation /* * sphyaddr - set a network adapter's physical Ethernet hardware address * * to compile: cc sphyaddr.c -o sphyaddr * * usage: sphyaddr tu0 08-00-2b-ff-ff-ff */ #define _SOCKADDR_LEN #include #include #include #include #include #include #include #include #include #include #include #include /* function prototype */ void ether_aton(char *, u_char *); int main (int argc, char **argv) { int s, n; u_char *cp; static struct ifdevea devea; static struct ifreq newaddress; if (argc < 3) { fprintf(stderr, "usage: %s: interface address\n", argv[0]); fprintf(stderr, "for example: %s tu0 08-00-2b-ff-ff-ff\n", argv[0]); exit(1); } s = socket(AF_INET, SOCK_DGRAM, 0); strcpy(devea.ifr_name, argv[1]); strcpy(newaddress.ifr_name, argv[1]); /* * get current address from driver */ if ((ioctl(s, SIOCRPHYSADDR, &devea) < 0)) { perror("couldn't get devea from driver"); } else { /* * print the current address */ cp = (u_char *)devea.current_pa; n = 0; printf("Current: "); do { printf("%02X-", cp[n++]); } while (n < sizeof(devea.current_pa) - 1); printf("%02X\n", cp[n++]); /* * print the target address */ printf("Target : %s\n", argv[2]); /* convert it */ cp = (u_char *)argv[2]; ether_aton((char *)cp, (u_char *)newaddress.ifr_addr.sa_data); newaddress.ifr_addr.sa_family = AF_LINK; newaddress.ifr_addr.sa_len = sizeof(newaddress.ifr_addr); /* set it */ if ((ioctl(s, SIOCSPHYSADDR, &newaddress) < 0)) { perror("couldn't set devea"); } exit(0); } exit(1); } /* * Convert an ASCII Ethernet address to a numeric address */ void ether_aton(char *a, u_char *n) { int i, o[6]; i = sscanf(a, "%x-%x-%x-%x-%x-%x", &o[0], &o[1], &o[2], &o[3], &o[4], &o[5]); if (i != 6) { fprintf(stderr, "invalid Ethernet address '%s'\n", a); exit(1); } for (i = 0; i < 6; i++) n[i] = o[i]; return; }