From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,302e58e2b12f84a2 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-09-13 14:10:13 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!news.compaq.com!news.cpqcorp.net!53ab2750!not-for-mail Message-ID: <3D825433.3BD312B9@hp.com> From: Brian Haley X-Mailer: Mozilla 4.79 [en] (X11; U; OSF1 V5.1 alpha) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.unix.tru64 Subject: Re: Code to change MAC address in Tru64 4.0f References: <20020913.135943.776532036.2339@shade.agi.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 13 Sep 2002 21:17:29 GMT NNTP-Posting-Host: 16.140.64.151 X-Complaints-To: abuse@Compaq.com X-Trace: news.cpqcorp.net 1031951849 16.140.64.151 (Fri, 13 Sep 2002 14:17:29 PDT) NNTP-Posting-Date: Fri, 13 Sep 2002 14:17:29 PDT Organization: Compaq, part of the new hp Xref: archiver1.google.com comp.unix.tru64:8654 d0 wrote: > Call me nuts or clear up my confusion but it seems either the man page is > incorrect or their header files are incorrect. Or perhaps there is some > substantial documentation I have yet to find. Anyone have a clue? I have a clue :) The man page and header files are correct, see the example code below. -Brian HP Tru64 UNIX Networking /* * 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; }