sonnenblen.de wurde überarbeitet - jetzt mit reCAPTCHA als Spamschutz und standardmäßig SSL-verschlüsselt erreichbar.
Solaris/SunOSOn Solaris and SunOS systems, the ethernet device is typically called le0 or ie0. In order to find the MAC address of the ethernet device, you must first become root, through the use of su. Then, type ifconfig -a and look up the relevant info. For example: # ifconfig -a le0: flags=863 <UP,BROADCAST,NOTRAILERS,RUNNING> inet 131.225.220.144 netmask ffffff00 broadcast 131.225.255.255 ether 8:0:20:f:c2:f8 Note: Solaris and SunOS strip off the leading 0 commonly included in the MAC address. In the case of this machine, the MAC address is 08:00:20:0f:c2:f8
Unter Linux komme ich mittels fcntl() und SIOCGIFHWADDR an die HW-Adresse eines Netzwerkinterface. Nur wie geht das unter Solaris? Google hat mir da nicht wirklich weiter helfen können...
#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/sockio.h>#include <net/if.h>#include <net/if_arp.h>#include <netinet/in.h>#include <arpa/inet.h> main(int argc,char *argv){ unsigned char eth_addr[6]; int i,j,sock; unsigned char *p; struct lifconf lic; struct lifreq lifrs[30]; struct lifnum num; struct arpreq ar; struct sockaddr_in *soap,*soap2; /* Enumerate all IP addresses of the system */ sock=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP); num.lifn_family=AF_INET; num.lifn_flags=0; ioctl(sock,SIOCGLIFNUM,&num); lic.lifc_family=AF_INET; lic.lifc_flags=0; lic.lifc_len=sizeof(lifrs); lic.lifc_buf=(caddr_t)&(lifrs[0] ); ioctl(sock,SIOCGLIFCONF,&lic); /* Get the ethernet address for each of them */ for(i=0;i<num.lifn_count;i++) { /* Get IP address */ ioctl(sock,SIOCGLIFADDR,&(lifrs[ i ])); soap=(struct sockaddr_in *)&(lifrs[ i ].lifr_addr); soap2=(struct sockaddr_in *)&(ar.arp_pa); *soap2=*soap; /* Print IP address */ p=(unsigned char *)&(soap->sin_addr); printf("%s: %u.%u.%u.%u - ",lifrs[ i ].lifr_name, p[0],p[1],p[2],p[3]); /* Get ethernet address */ if(ioctl(sock,SIOCGARP,&ar)<0) { printf("No ethernet address.\n"); } else { p=(unsigned char *)&(ar.arp_ha.sa_data); printf("%02X:%02X:%02X:%02X:%02X:%02X\n", p[0],p[1],p[2],p[3],p[4],p[5]); } } close(sock);}
Dass das nur als root geht...