Sponsored Content
Top Forums Programming How do I find the MAC address in C on different UNIX platforms? Post 302452760 by Pug on Monday 13th of September 2010 03:19:16 AM
Old 09-13-2010
Power How do I find the MAC address in C on different UNIX platforms?

I need to find the MAC address of the ethernet cards on the host machine from the C language. I have found a way to do this on Linux using socket(), ioctl() and the ifreq structure. But this does not seem to work on AIX, HP/UX and probably the others I need (Solaris, SCO, Alpha etc).

Is there a standard way to do this in UNIX?
Why do the UNIX ifreq structures not have a MAC address field like Linux?
Or and I missing something here? It would be fine with me if I need to to it differently for each platform, if I have to. I just need to know what calls to use for each type of UNIX.

Please help!

Thank you.
 

10 More Discussions You Might Find Interesting

1. IP Networking

Mac address - what is line command to find and active new card

How do you find mac address and active new card. (1 Reply)
Discussion started by: wmetz
1 Replies

2. IP Networking

How to Achive IP address through MAC(Ethernet) address

Hi sir, i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address....... but i'm nt getting that how i can pass the MAC address to Frame........ Please give me an idea for making such program... Thanks & regards Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies

3. UNIX for Advanced & Expert Users

Find IP Address of a Printer Q in Hp-Unix

Could anyone help me to identify the IP address of a printer queue with its printer queue name information . (1 Reply)
Discussion started by: lenin1985
1 Replies

4. UNIX for Dummies Questions & Answers

Unix Platforms

Hi. Where can i learn, Which Unix platform specific for what? Properties? (1 Reply)
Discussion started by: Enrgy
1 Replies

5. Solaris

Get ip address from mac address

I have following message in my messages file on solaris 10 WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
Discussion started by: fugitive
6 Replies

6. UNIX and Linux Applications

Platforms using Unix

Hi ;) Which hardware platforms/machine types use the Operating System Unix? A list of all would be appreaciated Thx Megadrink :cool: (2 Replies)
Discussion started by: Megadrink
2 Replies

7. UNIX for Dummies Questions & Answers

Is there a unix command to find ALL hostnames for an ip address?

I am trying to determine if there are several url/host names for an IP address. Is there a UNIX command to find ALL host names for an IP address? Thank you in advance. (3 Replies)
Discussion started by: rukasu
3 Replies

8. IP Networking

Tracing a MAC address to IP address: Solaris

Hi there I lost connectivity to one of our remote systems and when I checked the messages log I found the following: Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1 Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies

9. Shell Programming and Scripting

Multichecks across all unix platforms

Can somebody refer me following multicheck to perform across most of unix platform like AIX, HP-UX, solaris, Linux. CPU utilization above X% Check IO above X% Swap usage check above X% Memory utilization above X% ... (3 Replies)
Discussion started by: sendtoshailesh
3 Replies

10. IP Networking

MAC Address - Four Interfaces with the same MAC Address

four interfaces with ifconfig all interfaces have the same mac. If is not set for unique. but it still works. what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies
NETDEVICE(7)						     Linux Programmer's Manual						      NETDEVICE(7)

NAME
netdevice - Low level access to Linux network devices. SYNOPSIS
#include <sys/ioctl.h> #include <net/if.h> DESCRIPTION
This man page describes the sockets interface which is used to configure network devices. Linux supports some standard ioctls to configure network devices. They can be used on any socket's file descriptor regardless of the family or type. They pass an ifreq structure: struct ifreq { char ifr_name[IFNAMSIZ];/* Interface name */ union { struct sockaddrifr_addr; struct sockaddrifr_dstaddr; struct sockaddrifr_broadaddr; struct sockaddrifr_netmask; struct sockaddrifr_hwaddr; short ifr_flags; int ifr_ifindex; int ifr_metric; int ifr_mtu; struct ifmapifr_map; char ifr_slave[IFNAMSIZ]; char ifr_newname[IFNAMSIZ]; char * ifr_data; }; }; struct ifconf { int ifc_len; /* size of buffer */ union { char * ifc_buf; /* buffer address */ struct ifreq *ifc_req; /* array of structures */ }; }; Normally, the user specifies which device to affect by setting ifr_name to the name of the interface. All other members of the structure may share memory. IOCTLS
If an ioctl is marked as privileged then using it requires an effective user id of 0 or the CAP_NET_ADMIN capability. If this is not the case EPERM will be returned. SIOCGIFNAME Given the ifr_ifindex, return the name of the interface in ifr_name. This is the only ioctl which returns its result in ifr_name. SIOCGIFINDEX Retrieve the interface index of the interface into ifr_ifindex. SIOCGIFFLAGS, SIOCSIFFLAGS Get or set the active flag word of the device. ifr_flags contains a bitmask of the following values: Device flags IFF_UP Interface is running. IFF_BROADCAST Valid broadcast address set. IFF_DEBUG Internal debugging flag. IFF_LOOPBACK Interface is a loopback interface. IFF_POINTOPOINT Interface is a point-to-point link. IFF_RUNNING Resources allocated. IFF_NOARP No arp protocol, L2 destination address not set. IFF_PROMISC Interface is in promiscuous mode. IFF_NOTRAILERS Avoid use of trailers. IFF_ALLMULTI Receive all multicast packets. IFF_MASTER Master of a load balancing bundle. IFF_SLAVE Slave of a load balancing bundle. IFF_MULTICAST Supports multicast IFF_PORTSEL Is able to select media type via ifmap. IFF_AUTOMEDIA Auto media selection active. IFF_DYNAMIC The addresses are lost when the interface goes down. Setting the active flag word is a privileged operation, but any process may read it. SIOCGIFMETRIC, SIOCSIFMETRIC Get or set the metric of the device using ifr_metric. This is currently not implemented; it sets ifr_metric to 0 if you attempt to read it and returns EOPNOTSUPP if you attempt to set it. SIOCGIFMTU, SIOCSIFMTU Get or set the MTU (Maximum Transfer Unit) of a device using ifr_mtu. Setting the MTU is a privileged operation. Setting the MTU to too small values may cause kernel crashes. SIOCGIFHWADDR, SIOCSIFHWADDR Get or set the hardware address of a device using ifr_hwaddr. The hardware address is specified in a struct sockaddr. sa_family contains the ARPHRD_* device type, sa_data the L2 hardware address starting from byte 0. Setting the hardware address is a privi- leged operation. SIOCSIFHWBROADCAST Set the hardware broadcast address of a device from ifr_hwaddr. This is a privileged operation. SIOCGIFMAP, SIOCSIFMAP Get or set the interface's hardware parameters using ifr_map. Setting the parameters is a privileged operation. struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }; The interpretation of the ifmap structure depends on the device driver and the architecture. SIOCADDMULTI, SIOCDELMULTI Add an address to or delete an address from the device's link layer multicast filters using ifr_hwaddr. These are privileged opera- tions. See also packet(7) for an alternative. SIOCGIFTXQLEN, SIOCSIFTXQLEN Get or set the transmit queue length of a device using ifr_qlen. Setting the transmit queue length is a privileged operation. SIOCSIFNAME Changes the name of the interface specified in ifr_name to ifr_newname. This is a privileged operation. It is only allowed when the interface is not up. SIOCGIFCONF Return a list of interface (transport layer) addresses. This currently means only addresses of the AF_INET (IPv4) family for compat- ibility. The user passes a ifconf structure as argument to the ioctl. It contains a pointer to an array of ifreq structures in ifc_req and its length in bytes in ifc_len. The kernel fills the ifreqs with all current L3 interface addresses that are running: ifr_name contains the interface name (eth0:1 etc.), ifr_addr the address. The kernel returns with the actual length in ifc_len. If ifc_len is equal to the original length the buffer probably has overflowed and you should retry with a bigger buffer to get all addresses. When no error occurs the ioctl returns 0; otherwise -1. Overflow is no error. Most protocols support their own ioctls to configure protocol specific interface options. See the protocol man pages for a description. For configuring IP addresses see ip(7). In addition some devices support private ioctls. These are not described here. NOTES
Strictly seen, SIOCGIFCONF is IP specific and belongs in ip(7). The names of interfaces with no addresses or that don't have the IFF_RUNNING flag set can be found via /proc/net/dev. Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7). BUGS
glibc 2.1 is missing the ifr_newname macro in net/if.h. Add the following to your program as workaround: #ifndef ifr_newname #define ifr_newname ifr_ifru.ifru_slave #endif SEE ALSO
ip(7), proc(7), rtnetlink(7) Linux Man Page 1999-05-02 NETDEVICE(7)
All times are GMT -4. The time now is 03:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy