4 extern "C" { int socket ( int addr, int type, int protocol ); }
5 /* phn:20/4/94:delete:begin:because not the same signature in </sys/ioctl.h> */
6 /* extern "C" { int ioctl ( int d, unsigned long request, char *argp);} */
7 /* phn:20/4/94:delete:end:because not the same signature in </sys/ioctl.h> */
8 extern "C" { int close ( int filedes ); }
11 Standard_CString Ethernet() {
13 Standard_CString result;
14 static char *ether_devices[] = {
24 int e[6]; // For byte to int conversions
27 /* we need a socket */
28 sock = socket (AF_INET, SOCK_DGRAM, 0);
29 if (sock < 0) // Error : "Socket for Ethernet device localisation"
32 /* loop until we find a device or we error out */
33 for (i = 0; ether_devices[i] != NULL; i++) {
34 /* setup the device name */
35 strcpy (&devea.ifr_name[0], ether_devices[i]);
37 /* read the interface address */
38 /* phn:20/4/94:update:begin:because not the same signature in </sys/ioctl.h> */
39 if (ioctl (sock, SIOCRPHYSADDR, &devea) < 0) { // error ?
40 /* if (ioctl (sock, (unsigned long)SIOCRPHYSADDR, (char*) &devea) < 0) { */ // error ?
41 /* phn:20/4/94:update:end:because not the same signature in </sys/ioctl.h> */
42 if (errno == ENXIO) { // doesn't exist, try next device
44 } else { // unexpected error
45 //perror (&devea.ifr_name[0]);
48 } else break; // found one, break out
53 if (ether_devices[i] == NULL) // Error : no Ethernet device
56 // unsigned char to int conversions
58 e[0] = (unsigned char)devea.default_pa[0];
59 e[1] = (unsigned char)devea.default_pa[1];
60 e[2] = (unsigned char)devea.default_pa[2];
61 e[3] = (unsigned char)devea.default_pa[3];
62 e[4] = (unsigned char)devea.default_pa[4];
63 e[5] = (unsigned char)devea.default_pa[5];
65 sprintf(name,"%x:%x:%x:%x:%x:%x",e[0],e[1],e[2],e[3],e[4],e[5]);