summaryrefslogtreecommitdiff
path: root/src/OSD/ethernet.h-dec
blob: b6731b2fe1af8d1d4e87be8ed5e128d91fd91c07 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
extern "C" { int socket ( int addr, int type, int protocol ); }
/* phn:20/4/94:delete:begin:because not the same signature in </sys/ioctl.h> */
/* extern "C" { int ioctl  ( int d, unsigned long request, char *argp);}     */
/* phn:20/4/94:delete:end:because not the same signature in </sys/ioctl.h>   */
extern "C" { int close  ( int filedes ); }       


Standard_CString Ethernet() {
 struct ifdevea devea;
 Standard_CString result;
 static char  *ether_devices[] = {
       "qe0",
       "se0",
       "ln0",
       "de0",
       "ni0",
        NULL
       };
 char name[32];
 long *eth;
 int e[6];   // For byte to int conversions
 int sock, i;
   
   /* we need a socket */
   sock = socket (AF_INET, SOCK_DGRAM, 0);
   if (sock < 0) // Error : "Socket for Ethernet device localisation"
    return(result);

    /* loop until we find a device or we error out */
    for (i = 0; ether_devices[i] != NULL; i++) {
         /* setup the device name */
         strcpy (&devea.ifr_name[0], ether_devices[i]);

         /* read the interface address */
	 /* phn:20/4/94:update:begin:because not the same signature in </sys/ioctl.h> */
         if (ioctl (sock, SIOCRPHYSADDR, &devea) < 0) {   // error ? 
         /* if (ioctl (sock, (unsigned long)SIOCRPHYSADDR, (char*) &devea) < 0) {     */  // error ? 
	 /* phn:20/4/94:update:end:because not the same signature in </sys/ioctl.h>   */
         if (errno == ENXIO) {                 // doesn't exist, try next device
            continue;
         } else {                              // unexpected error
            //perror (&devea.ifr_name[0]);
            return(result);
         }
      } else   break;                         // found one, break out
   } /* for ... */

   close (sock);

   if (ether_devices[i] == NULL) // Error : no Ethernet device
      return(result);

   // unsigned char to int conversions

   e[0] = (unsigned char)devea.default_pa[0];
   e[1] = (unsigned char)devea.default_pa[1];
   e[2] = (unsigned char)devea.default_pa[2];
   e[3] = (unsigned char)devea.default_pa[3];
   e[4] = (unsigned char)devea.default_pa[4];
   e[5] = (unsigned char)devea.default_pa[5];

   sprintf(name,"%x:%x:%x:%x:%x:%x",e[0],e[1],e[2],e[3],e[4],e[5]);
   result = name;
   return(result);

}