summaryrefslogtreecommitdiff
path: root/src/OSD/ethernet.h-sgi
blob: b15b3b4edc0ea70df0564d7b040cf29857726598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <net/if.h>
#include <net/raw.h>
 Standard_CString Ethernet() {
 Standard_CString result;
 static char *ether_devices[]={
   "ec0",
   "enp0",
   "et0",
   "fxp0",
   NULL
 };
 int sock,i;
 int e[6];
 struct ifreq         ifreq;
 static char buffer[16];

  sock = socket(AF_RAW,SOCK_RAW,RAWPROTO_DRAIN); 
  if (sock < 0)  /* Error : "drain_open:could not open socket" */
    return(result);

  for (i=0; ether_devices[i] != NULL; i++){
   strcpy(ifreq.ifr_name, ether_devices[i]);  /* Puts name */

   if (ioctl(sock, SIOCGIFADDR, (char *) &ifreq) < 0) 
    if (errno == ENXIO) continue;
    else   /* Error : "drain:getmyaddr:cannot get raw address" */
     return(result);
   }
    
   e[0] = (unsigned char)ifreq.ifr_addr.sa_data[0];
   e[1] = (unsigned char)ifreq.ifr_addr.sa_data[1];
   e[2] = (unsigned char)ifreq.ifr_addr.sa_data[2];
   e[3] = (unsigned char)ifreq.ifr_addr.sa_data[3];
   e[4] = (unsigned char)ifreq.ifr_addr.sa_data[4];
   e[5] = (unsigned char)ifreq.ifr_addr.sa_data[5];

   sprintf(buffer,"%x:%x:%x:%x:%x:%x", e[0],e[1],e[2],e[3],e[4],e[5]);
   close(sock);

   result = buffer;
   return(result);
}