home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.ultrix
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!news.iastate.edu!john
- From: john@iastate.edu (John Hascall)
- Subject: Re: ioctl call to ln0
- Message-ID: <C02zKH.5n2@news.iastate.edu>
- Sender: news@news.iastate.edu (USENET News System)
- Organization: Iowa State University, Ames, IA
- References: <1992Dec30.135231.292@athena.mit.edu>
- Date: Wed, 30 Dec 1992 16:38:38 GMT
- Lines: 51
-
- goeke@space.mit.edu (Robert F. Goeke) writes:
- }I am running Ultrix 4.3 on a variety of DECStation 5000s and wanted to
- }interogate the Ethernet interface in order to retrieve the physical
- }address. The ln(4) man page gives the ioctl request, and I tracked
- }down via sys/ioctl.h and net/if.h what I think is enough information
- }to do the job, but....I'm new to this ioctl game. How do I open
- }a file descriptor for this hardware interface (the first arg needed
- }in the ioctl call)?
-
- Here are some code excerpts (error checking, etc. omitted for brevity) which
- do this sort of thing (note that this looks for the net interface rather than
- assuming ln0, [ie. it works for fza0 too]):
-
- sockfd = socket(AF_INET, SOCK_DGRAM, 0);
- interface = find_hardware_interface(sockfd);
- find_hardware_address(sockfd, interface, hardware);
-
- char * find_hardware_interface(sfd)
- int sfd;
- {
- struct ifconf ifconf;
- struct ifreq ifreq[10]; /* more than 10 net ifaces? */
- int i;
-
- ifconf.ifc_len = sizeof(ifreq);
- ifconf.ifc_req = ifreq;
- ioctl(sfd, SIOCGIFCONF, &ifconf);
- for (i = 0; i < (ifconf.ifc_len / sizeof(struct ifreq)); ++i) {
- /* find & return a suitable interface using ifreq[i] */
- }
- }
-
- int find_hardware_address(sfd, interface, hardware)
- int sfd;
- char * interface;
- char * hardware;
- {
- struct ifdevea dev_info;
-
- strcpy(dev_info.ifr_name, interface);
- ioctl(sfd, SIOCRPHYSADDR, &dev_info);
- memcpy(hardware, dev_info.current_pa, 6); /* using 6 is gross... */
- }
-
- Hope this helps,
- John
- --
- John Hascall ``An ill-chosen word is the fool's messenger.''
- Systems Software Engineer
- Project Vincent
- Iowa State University Computation Center + Ames, IA 50011 + 515/294-9551
-