From: muench-philip@math.yale.edu (Philip Muench)
Newsgroups: comp.dcom.lans.ethernet
Subject: Re: Information needed
Date: 25 Jan 1993 02:50:01 -0500
Organization: Yale University Mathematics Dept., New Haven, CT 06520-2155
Distribution: world
NNTP-Posting-Host: cantor.math.yale.edu

In article <1jj4a3INNh41@fbi-news.Informatik.Uni-Dortmund.DE> kluemper@snorre.informatik.uni-dortmund.de (Stefan Kluempers (PG211)) writes:
>Hi,
>
>i am searching for a solution to read the number of a ethernet card out
>of a program.
>The solutions should work under SCO-Unix or SINIX.
>
>Thanks in advance,
>
>
>
>   Stefan

Newsgroups: comp.dcom.lans.ethernet
Subject: Re: Information needed
Summary: 
Expires: 
Followup-To: 
Distribution: world
Organization: Yale University Mathematics Dept., New Haven, CT 06520-2155
Keywords: 

In article <1jj4a3INNh41@fbi-news.Informatik.Uni-Dortmund.DE> kluemper@snorre.informatik.uni-dortmund.de (Stefan Kluempers (PG211)) writes:
>Hi,
>
>i am searching for a solution to read the number of a ethernet card out
>of a program.
>The solutions should work under SCO-Unix or SINIX.
>
>Thanks in advance,
>
>
>
>   Stefan

   This is how one might do it with SunOS 4.1.1. Perhaps your systems
behave similarly:
(1) The super user may use
        /usr/etc/ifconfig -a ether
to see the the Ethernet address of every interface that has one.
Use the name of a specific interface like "le0" instead of "-a", if only
that interface is of interest. 
If your program is not a shell script and you do not want
        system ( "/usr/etc/ifconfig le0 ether > myfile" );
        fp = fopen ( "myfile", "r" );
        fscanf( fp, "%s", text );
        ...
in your program and you do not want a more elaborate version
running the user-level command "ifconfig" and piping its output
into your program with fork, dup, close, exec, and all that, 
you'll probably have to use something like this, which would
have to be run by the super user or be owned by the super user
and have its setuid permission turned on:
# Warning! The program fragment below is untested and contains no
# error checking!
     #include <sys/types.h>
     #include <sys/socket.h>
     #include <net/if.h>
     #include <netinet/in.h>
     #include <netinet/if_ether.h>
          struct    ifreq {
               char ifr_name[16];       /* name of interface (e.g. "ec0") */
               union {
                    struct    sockaddr ifru_addr;
                    struct    sockaddr ifru_dstaddr;
                    short     ifru_flags;
               } ifr_ifru;
          #define   ifr_addr       ifr_ifru.ifru_addr  /* address */
          #define   ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
          #define   ifr_flags      ifr_ifru.ifru_flags /* flags */
          };
struct ifreq myifreq;
strcpy ( myifreq.ifr_name, "le0" ) ; /* Specify the interface by name. */
myifreq.ifr_addr.sa_family = AF_UNSPEC ; /* Use AF_UNSPEC for hardware "address
                                         family". */
int fd;
fd = socket ( AF_UNSPEC, SOCK_RAW, PF_UNSPEC ); /* Only super user */
                                                /* may do this. */
ioctl ( fd, SIOCGIFADDR, &myifreq ); /* Request is "get address". */
/* Read the result and convert to printable form: */
printf("Ethernet address is %s.\n", ether_ntoa( myifreq.ifr_addr.sa_data ) );

(2) If the interface is running Internet protocols, the following
should work (perhaps not practical within a program):
Non-super users have to resort to logging in to another machine that
has an Address Resolution Protocol (ARP) cache and using
        /usr/etc/arp HOST-OF-INTEREST
(with the hostname or IP address of the machine whose Ethernet
address is sought substituted for "HOST-OF-INTEREST". Naturally,
if the machine where one logs in to consult the ARP cache
is not running SunOS, its command to check the ARP cache may be
different. On a Xyplex terminal server, the command
       show server internet translation table
could be used.
It may be necessary to ping, telnet, or otherwise use an Internet
protocol to communicate between the ARP caching machine and
the machine whose Ethernet address is being checked, and to
do so shortly before examining the ARP cache.
Naturally, the machine whose ARP cache is being examined must
be in direct (no Internet routing used) contact with the interface
whose Ethernet address is being checked.
-Philip Muench
 muench@cantor.cs.yale.edu 128.36.23.26
Xref: sparky comp.dcom.lans.ethernet:3077 misc.forsale.computers.pc-clone:3019