home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / wizards / 3816 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.1 KB

  1. Path: sparky!uunet!eiffel!eiffel.com
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Newsgroups: comp.unix.wizards
  4. Subject: Getting the Ethernet address from a network interface
  5. Keywords: network, ethernet, IP, arp
  6. Message-ID: <126@eiffel.eiffel.com>
  7. Date: 6 Sep 92 20:22:42 GMT
  8. Sender: ram@eiffel.com
  9. Organization: Interactive Software Engineering, Santa Barbara CA
  10. Lines: 41
  11.  
  12. Hi!
  13.  
  14. I am facing what appears to be a simple problem, but cannot seem to
  15. be able to solve it. What I want is to retrieve the ethernet address
  16. of the machine. Unfortunately, this has to be done from a program with
  17. no super-user privileges.
  18.  
  19. I know the ARP protocol, but the informations are kept in the kernel
  20. data space, and the mapping between IP and Ethernet addresses is done
  21. only for the other machines, not the local host. And I did not manage
  22. to find a system call which would probe the ethernet device and give
  23. me its ethernet address.
  24.  
  25. There is obviously a shell solution which works sometimes:
  26.  
  27.     remsh another_host /etc/arp my_host | sed -e 's/^.*at //'
  28.  
  29. but this is not really acceptable. And the other host might not have
  30. the maping in its kernel. An arbitrary program cannot depend on this
  31. to get the local Ethernet address...
  32.  
  33. What I managed to do so far is getting a datagram socket and calling
  34. an iotcl SIOCGIFCONF on the socket descriptor, which gives a list of
  35. the network interfaces available. In particular the struct ifreq
  36. contains the sockaddr information, providing me with the IP address
  37. (ifr_addr field from struct ifreq, which is a struct sockaddr).
  38.  
  39. But how do you get to the struct ether_addr? Is there a way at the
  40. user level (i.e. with no root privilege) to force an arp resolution
  41. and then retrieve that information from the kernel via a system call?
  42. On my machine, /usr/etc/arp is setgid to sys, indicating the program
  43. is reading /dev/kmem directly, i.e. the information retrieval is not
  44. easily portable from kernel to kernel.
  45.  
  46.  
  47. Thank you for any information on this topic.
  48. -- 
  49. Raphael Manfredi <ram@eiffel.com>
  50. Interactive Software Engineering Inc.
  51. 270 Storke Road, Suite #7                      / Tel +1 (805) 685-1006 \
  52. Goleta, California 93117, USA                  \ Fax +1 (805) 685-6869 /
  53.