Re: c code for the MAC Address from an Ethernet Adapter
From: Simone Stanzani (devnull_at_libero.it)
Date: 09/09/03
- Next message: Dave: "kde Debugging into a console app."
- Previous message: d2003xx: "Re: Linux and CodeWarrior C/C++ IDE ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Sep 2003 15:12:26 GMT
Gary Desrosiers ha scritto:
> #include <string.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <netinet/in.h>
> #include <net/if.h>
> #include <sys/types.h>
> #include <arpa/inet.h>
> #include <sys/ioctl.h>
> #include <sys/socket.h>
> #include <netdb.h>
>
> int main(int argc,char *argv[])
> {
> int r;
> struct protoent *proto;
> int sock;
> struct ifreq ifr;
>
> if(argc < 2)
> {
> printf("Usage: dumpmac ifname\n");
> exit(1);
> }
> proto = getprotobyname("tcp");
> sock = socket(PF_INET,SOCK_STREAM,proto->p_proto);
> memset(&ifr,0,sizeof(struct ifreq));
> strcpy(ifr.ifr_name,argv[1]);
> r = ioctl(sock,SIOCGIFHWADDR,&ifr);
> if(r != 0)
> {
> printf("Couldn't get mac address\n");
> exit(1);
> }
> printf("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
> (unsigned char)ifr.ifr_hwaddr.sa_data[0],
> (unsigned char)ifr.ifr_hwaddr.sa_data[1],
> (unsigned char)ifr.ifr_hwaddr.sa_data[2],
> (unsigned char)ifr.ifr_hwaddr.sa_data[3],
> (unsigned char)ifr.ifr_hwaddr.sa_data[4],
> (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
> return(0);
> }
>
> Gary.
>
> nkl wrote:
>
>
>>Any code/code-fragments will be helpful.
>>Thanks,
>>
>>"Grant Edwards" <grante@visi.com> ¦b¶l¥ó
>>news:slrnbfnghq.j3f.grante@localhost.localdomain ¤¤¼¶¼g...
>>
>>>In article <3efbba2a$1@shknews01>, nkl wrote:
>>>
>>>
>>>>Any experts can help me to get the c ocde that can retrieve
>>>>1) the MAC Address from an Ethernet Adapter, and
>>>>2) "Drive Serial Number" from the Harddisk firmware
>>>
>>>Sure sounds like some sort of lame copy-protection scheme, eh?
>>>
>>>--
>>>Grant Edwards grante Yow! I just had a
>>>NOSE
>>> at JOB!!
>>> visi.com
>
>
- Next message: Dave: "kde Debugging into a console app."
- Previous message: d2003xx: "Re: Linux and CodeWarrior C/C++ IDE ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]