Computing.Net > Forums > Unix > get mac address

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

get mac address

Reply to Message Icon

Name: ballordo
Date: February 21, 2003 at 04:13:15 Pacific
OS: osf1 5.1 alpha unix
CPU/Ram: 512 mb
Comment:

hi, I'd like to get mac address, I know that I can use ifconfig, but does anybody know how to get it by c code? thank u



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 21, 2003 at 10:52:21 Pacific
Reply:

/*Hi:

To get this info in "C", requires being familiar with the TCP/IP
network routines. It also can be platform specific. The following
program works on my Solaris 7 box. For more info, read Chapter 8 of Unix
Network Programming by W. Richhard Stevens:

(I placed the include files in double quotes simply because the form wipes out anything in double braces . Please change back to normal "C")
*/
#include "stdio.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "netdb.h"
#include "arpa/inet.h" /* inet_ntoa repository */

void main(argc, argv)
int argc;
char **argv;
{

struct hostent *hp;
struct in_addr *ptr;

/* get the server name */
if ((hp = gethostbyname("skinner")) == NULL)
{
fprintf(stderr, "%s: server unknown.\n", *argv);
exit (1);
}

/* get the address */
if(hp->h_addrtype = AF_INET)
{
while((ptr=(struct in_addr *) *hp->h_addr_list++) != NULL)
fprintf(stderr, "address: %s \n", inet_ntoa(*ptr));
}

exit(0);
}


0
Reply to Message Icon

Related Posts

See More


Deleting old files 'find' syntax



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: get mac address

get ethernet NIC'c MAC address www.computing.net/answers/unix/get-ethernet-nicc-mac-address/4079.html

How to read Mac address of NIC www.computing.net/answers/unix/how-to-read-mac-address-of-nic-/4619.html

Mac Address www.computing.net/answers/unix/mac-address/4646.html