FROM : Pierre-Olivier Latour
DATE : Mon Nov 18 04:48:15 2002
Whoa, this is some pretty heavy stuff ;) Try rather this:
http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddressSa
mple.htm
http://developer.apple.com/samplecode/Sample_Code/Networking/GetPrimaryMACAd
dress.htm
More specifically:
http://developer.apple.com/samplecode/Sample_Code/Networking/GetPrimaryMACAd
dress/GetPrimaryMACAddress.c.htm
Once you've removed all the comments, it should be way shorter and it'll
teach you a bit of the IOKit ;)
> Hi,
>
> This is from some C stuff I found either on this list or elsewhere on the
> 'net. (Sorry, I like to give credit, but I just don't recall the source of
> this.)
>
> Terence
>
> #define MAXADDRS 32
> char *hw_addrs[MAXADDRS];
>
> void GetHWAddresses()
> {
> struct ifconf ifc;
> struct ifreq *ifr;
> int i, sockfd;
> char buffer[BUFFERSIZE], *cp, *cplim;
> char temp[80];
>
> for (i=0; i<MAXADDRS; ++i)
> {
> hw_addrs[i] = NULL;
> }
>
> sockfd = socket(AF_INET, SOCK_DGRAM, 0);
> if (sockfd < 0)
> {
> perror("socket failed");
> return;
> }
>
> ifc.ifc_len = BUFFERSIZE;
> ifc.ifc_buf = buffer;
>
> if (ioctl(sockfd, SIOCGIFCONF, (char *)&ifc) < 0)
> {
> perror("ioctl error");
> close(sockfd);
> return;
> }
>
> ifr = ifc.ifc_req;
>
> cplim = buffer + ifc.ifc_len;
>
> for (cp=buffer; cp < cplim; )
> {
> ifr = (struct ifreq *)cp;
> if (ifr->ifr_addr.sa_family == AF_LINK)
> {
> struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr;
> int a,b,c,d,e,f;
> int i;
>
> strcpy(temp, (char *)ether_ntoa(LLADDR(sdl)));
> sscanf(temp, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f);
> sprintf(temp, "%02X:%02X:%02X:%02X:%02X:%02X",a,b,c,d,e,f);
>
> for (i=0; i<MAXADDRS; ++i)
> {
> if ((if_names[i] != NULL) && (strcmp(ifr->ifr_name, if_names[i]) ==
> 0))
> {
> if (hw_addrs[i] == NULL)
> {
> hw_addrs[i] = (char *)malloc(strlen(temp)+1);
> strcpy(hw_addrs[i], temp);
> break;
> }
> }
> }
> }
> cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr),
> ifr->ifr_addr.sa_len);
> }
>
> close(sockfd);
> }
>
>
>
>
>> From: "Peter Hudson" <<email_removed>>
>> Reply-To: <email_removed>
>> To: <email_removed>
>> Subject: MAC Address of machine.
>> Date: Sun, 17 Nov 2002 23:27:03 +0000
>>
>> I need to get the MAC address of the machine that my application is running
>> on. I figured there must be a way in Cocoa to do it.
>>
>> Any help much appreciated.
>>
>>
>> Peter Hudson
>> _______________________________________________
>> cocoa-dev mailing list | <email_removed>
>> Help/Unsubscribe/Archives:
>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>> Do not post admin requests to the list. They will be ignored.
>
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_____________________________________________________________
Pierre-Olivier Latour <email_removed>
Palo Alto, USA http://www.pol-online.net
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Mon Nov 18 04:48:15 2002
Whoa, this is some pretty heavy stuff ;) Try rather this:
http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddressSa
mple.htm
http://developer.apple.com/samplecode/Sample_Code/Networking/GetPrimaryMACAd
dress.htm
More specifically:
http://developer.apple.com/samplecode/Sample_Code/Networking/GetPrimaryMACAd
dress/GetPrimaryMACAddress.c.htm
Once you've removed all the comments, it should be way shorter and it'll
teach you a bit of the IOKit ;)
> Hi,
>
> This is from some C stuff I found either on this list or elsewhere on the
> 'net. (Sorry, I like to give credit, but I just don't recall the source of
> this.)
>
> Terence
>
> #define MAXADDRS 32
> char *hw_addrs[MAXADDRS];
>
> void GetHWAddresses()
> {
> struct ifconf ifc;
> struct ifreq *ifr;
> int i, sockfd;
> char buffer[BUFFERSIZE], *cp, *cplim;
> char temp[80];
>
> for (i=0; i<MAXADDRS; ++i)
> {
> hw_addrs[i] = NULL;
> }
>
> sockfd = socket(AF_INET, SOCK_DGRAM, 0);
> if (sockfd < 0)
> {
> perror("socket failed");
> return;
> }
>
> ifc.ifc_len = BUFFERSIZE;
> ifc.ifc_buf = buffer;
>
> if (ioctl(sockfd, SIOCGIFCONF, (char *)&ifc) < 0)
> {
> perror("ioctl error");
> close(sockfd);
> return;
> }
>
> ifr = ifc.ifc_req;
>
> cplim = buffer + ifc.ifc_len;
>
> for (cp=buffer; cp < cplim; )
> {
> ifr = (struct ifreq *)cp;
> if (ifr->ifr_addr.sa_family == AF_LINK)
> {
> struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr;
> int a,b,c,d,e,f;
> int i;
>
> strcpy(temp, (char *)ether_ntoa(LLADDR(sdl)));
> sscanf(temp, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f);
> sprintf(temp, "%02X:%02X:%02X:%02X:%02X:%02X",a,b,c,d,e,f);
>
> for (i=0; i<MAXADDRS; ++i)
> {
> if ((if_names[i] != NULL) && (strcmp(ifr->ifr_name, if_names[i]) ==
> 0))
> {
> if (hw_addrs[i] == NULL)
> {
> hw_addrs[i] = (char *)malloc(strlen(temp)+1);
> strcpy(hw_addrs[i], temp);
> break;
> }
> }
> }
> }
> cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr),
> ifr->ifr_addr.sa_len);
> }
>
> close(sockfd);
> }
>
>
>
>
>> From: "Peter Hudson" <<email_removed>>
>> Reply-To: <email_removed>
>> To: <email_removed>
>> Subject: MAC Address of machine.
>> Date: Sun, 17 Nov 2002 23:27:03 +0000
>>
>> I need to get the MAC address of the machine that my application is running
>> on. I figured there must be a way in Cocoa to do it.
>>
>> Any help much appreciated.
>>
>>
>> Peter Hudson
>> _______________________________________________
>> cocoa-dev mailing list | <email_removed>
>> Help/Unsubscribe/Archives:
>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>> Do not post admin requests to the list. They will be ignored.
>
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_____________________________________________________________
Pierre-Olivier Latour <email_removed>
Palo Alto, USA http://www.pol-online.net
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Peter Hudson | Nov 18, 00:27 | |
| Terence G4 Mac | Nov 18, 04:16 | |
| Pierre-Olivier Lat… | Nov 18, 04:48 | |
| Ryan McGann | Nov 18, 07:04 | |
| Jerry LeVan | Nov 18, 17:53 |






Cocoa mail archive

