All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
Finding MAC Address of Network Interface
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login |
|
|
Finding MAC Address of Network Interface - Jul. 10, '06, 11:40:10 AM
|
|
|
technalysis
Posts: 4
Joined: Jun. 29, '06,
Status: offline
|
I'm trying to find the MAC address of a network interface for licensing purposes. I'm not sure how to go about that, even after reading the ioctl SIOCGFCONF question. I've installed libport 1.0 and here is the code we used in Linux to do the same job:
int _sock,res;
struct ifreq ifr;
unsigned char *hwa;
char *machid; //This is the variable used for licensing.
memset (&ifr,0,sizeof(struct ifreq));
/* Dummy socket, just to make ioctls with */
_sock=socket(PF_INET,SOCK_DGRAM,0);
/* name of the card */
/***** How are NIC devices named in SFU? *****/
strcpy(ifr.ifr_name,"eth0");
res=ioctl(_sock,SIOCGIFHWADDR,&ifr);
if (res<0) perror ("Get hw addr");
hwa=ifr.ifr_ifru.ifru_hwaddr.sa_data;
close(_sock);
sprintf(machid,"%02x%02x%02x%02x%02x%02x",
hwa[0],hwa[1],hwa[2],hwa[3],hwa[4],hwa[5]);
|
|
|
RE: Finding MAC Address of Network Interface - Jul. 10, '06, 12:49:17 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
The extended ioctl() requests for sockets (SIOC*) in libport doesn't
include SIOCGIFHWADDR. However, you will notice the naming convention of
the NIC's. The name is generated uniquely by Windows OS when the machine
detects the hardware. If the NIC is moved, for example, from slot 1 to
slot 2 on the board, a new name is generated for it. It's yet another
uniquely generated name. If you move the NIC back to the original slot
then the original name will be used. Reboot to reboot the name will
remain the same as long as the hardware is in the same location. So I
think you can safely use the name returned by SIOCGIFCONF for the same
purpose that you are using SIOCGIFHWADDR.
You want to install the most current version of libport which is
version 1.1.5 which is currently sitting in the beta directory, but will
go live later today. The 1.0 version, as discussed in the thread you mention,
noted that 1.0 had the debug names coming out.
< Message edited by Rodney -- Jul. 10, '06, 1:01:29 PM >
|
|
|
RE: Finding MAC Address of Network Interface - Jul. 10, '06, 2:37:24 PM
|
|
|
technalysis
Posts: 4
Joined: Jun. 29, '06,
Status: offline
|
I believe you're correct about being able to use SIOCGIFCONF. Could you please post some example code, including variable declarations, showing how one would get the mac address of a NIC? Or, at least, point me to some documentation that might help? Thanks.
|
|
|
RE: Finding MAC Address of Network Interface - Jul. 11, '06, 11:48:04 AM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
I don't have any code or documentation for getting the MAC of a NIC on Windows.
I imagine that such information can be found in the MSDN (on-line & free).
|
|
|
RE: Finding MAC Address of Network Interface - Jul. 13, '06, 4:25:05 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
This is a sample bit of code for using SIOCGIFCONF.
It's just a cut & paste from one part of the test program.
Just valid/active NIC's are returned. This is for a system
I happen to know has fewer than 10 NIC's.
Error recovery here is non-existent. But I imagine you can
handle beefing that part up.
int ret, fd, i, count;
struct ifconf my_ifconf;
struct ifreq *req;
size_t size;
struct sockaddr_in *data;
printf("ioctl SIOCGIFCONF, size 10 content\n");
printf("\texpect it to succeed with >1 i/f\n");
size = 10 * sizeof(struct ifreq);
my_ifconf.ifc_len = size;
my_ifconf.ifc_req = malloc(size);
ret = ioctl(fd, SIOCGIFCONF, &my_ifconf);
if (ret == -1) {
printf("\tfailed: (not expected) FAIL\n");
}
else {
count = my_ifconf.ifc_len/sizeof(struct ifreq);
printf("\tsuccess: count=%d\n", count);
for (i=0; i<count; i++) {
data = (struct sockaddr_in *)&(my_ifconf.ifc_req[i].ifr_addr);
printf("\t\t(%s/%s)\n",
my_ifconf.ifc_req[i].ifr_name,
inet_ntoa(data->sin_addr.s_addr));
}
}
free(my_ifconf.ifc_req);
< Message edited by Rodney -- Jul. 13, '06, 4:27:11 PM >
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|