Main.MacInLinux History

Hide minor edits - Show changes to output

2007-01-02,02:59 下午 by 61.229.48.236 -
Changed lines 12-13 from:
int
main()
to
int main(int argc, char **argv)
Changed line 27 from:
printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
to
printf("%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
2007-01-02,02:57 下午 by 61.229.48.236 -
Changed line 40 from:
** Also see: [[ MacInWin || Retrieval MAC address in Windiws ]]
to
** Also see: [[ MacInWin | Retrieval MAC address in Windiws ]]
2007-01-02,02:56 下午 by 61.229.48.236 -
Changed lines 38-40 from:
=]
to
=]

** Also see: [[ MacInWin || Retrieval MAC address in Windiws ]]
2007-01-02,02:56 下午 by 61.229.48.236 -
Added lines 1-38:
=cpp [=
#include <stdio.h>

#include <string.h> /* for strncpy */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>

int
main()
{
int fd;
struct ifreq ifr;

fd = socket(AF_INET, SOCK_DGRAM, 0);

ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);

ioctl(fd, SIOCGIFHWADDR, &ifr);

close(fd);

/* display result */
printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.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;
}
=]
 

PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.