Loading ...
Sorry, an error occurred while loading the content.

RE: [blug-prog] SIOCGIFHWADDR mac address

Expand Messages
  • Mani Mahadevan
    Prior to performing ioctl with SIOCGIFHWADDR cmd, Fill in the ifreq structure with the proper interface name and Interface Index. The following steps should
    Message 1 of 4 , Nov 14, 2002
    • 0 Attachment
      Prior to performing ioctl with SIOCGIFHWADDR cmd,
      Fill in the ifreq structure with the proper interface
      name and Interface Index.

      The following steps should do:-
      sprintf (req.ifr_name,"eth0");
      ioctl (sockfd, SIOCGIFINDEX,&req);

      -Mani


      -----Original Message-----
      From: paroliasunil [mailto:sunil@...]
      Sent: Thursday, November 14, 2002 7:03 PM
      To: linux-bangalore-programming@yahoogroups.com
      Subject: [blug-prog] SIOCGIFHWADDR mac address


      Hi all,

      How can i get the macaddress of a linux machine using ioctl. Is there
      any other way to get the macaddress programmatically.
      I have tried this :

      ioctl(sockFd, SIOCGIFHWADDR ,&req);
      sin = (sockaddr_in *)&req.ifr_addr;
      sin = (sockaddr_in *)&req.ifr_hwaddr;

      but no gain.


      thanks,
      Sunil parolia





      ---------------------------------------------------------------
      This is the programming list of the Bangalore Linux Users Group
      ---------------------------------------------------------------
      Go to http://linux-bangalore.org for more information
      about us, as well as our other mailing lists

      Before you post to this list, please read
      http://linux-bangalore.org/articles/smart-questions.php


      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    • paroliasunil
      ... i have done this plz go thru the code snippet main() { int sockFd; struct ifreq req; struct sockaddr_in *sin; sockFd=
      Message 2 of 4 , Nov 14, 2002
      • 0 Attachment
        --- In linux-bangalore-programming@y..., "Mani Mahadevan"
        <mrsmani@c...> wrote:
        > Prior to performing ioctl with SIOCGIFHWADDR cmd,
        > Fill in the ifreq structure with the proper interface
        > name and Interface Index.
        >
        > The following steps should do:-
        > sprintf (req.ifr_name,"eth0");
        > ioctl (sockfd, SIOCGIFINDEX,&req);
        >

        i have done this plz go thru the code snippet

        main()
        {

        int sockFd;
        struct ifreq req;
        struct sockaddr_in *sin;

        sockFd= socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);

        memset(&req,0,sizeof(req));
        strcpy(req.ifr_name,"eth0");

        ioctl(sockFd, SIOCGIFHWADDR ,&req);

        sin = (sockaddr_in *)&req.ifr_hwaddr;

        }

        also after getting the hardware address how to get in char string??

        thanks,
        Sunil Parolia
      • Mani Mahadevan
        To be on the safer side, fill in the Index value also. For getting the MAC address..dump as hex the values from req.ifr_hwaddr[0] to req.ifr_hwaddr[5] -Mani
        Message 3 of 4 , Nov 15, 2002
        • 0 Attachment
          To be on the safer side, fill in the Index value also.
          For getting the MAC address..dump as hex the values
          from req.ifr_hwaddr[0] to req.ifr_hwaddr[5]

          -Mani

          -----Original Message-----
          From: paroliasunil [mailto:sunil@...]
          Sent: Friday, November 15, 2002 11:59 AM
          To: linux-bangalore-programming@yahoogroups.com
          Subject: Re: [blug-prog] SIOCGIFHWADDR mac address


          --- In linux-bangalore-programming@y..., "Mani Mahadevan"
          <mrsmani@c...> wrote:
          > Prior to performing ioctl with SIOCGIFHWADDR cmd,
          > Fill in the ifreq structure with the proper interface
          > name and Interface Index.
          >
          > The following steps should do:-
          > sprintf (req.ifr_name,"eth0");
          > ioctl (sockfd, SIOCGIFINDEX,&req);
          >

          i have done this plz go thru the code snippet

          main()
          {

          int sockFd;
          struct ifreq req;
          struct sockaddr_in *sin;

          sockFd= socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);

          memset(&req,0,sizeof(req));
          strcpy(req.ifr_name,"eth0");

          ioctl(sockFd, SIOCGIFHWADDR ,&req);

          sin = (sockaddr_in *)&req.ifr_hwaddr;

          }

          also after getting the hardware address how to get in char string??

          thanks,
          Sunil Parolia





          ---------------------------------------------------------------
          This is the programming list of the Bangalore Linux Users Group
          ---------------------------------------------------------------
          Go to http://linux-bangalore.org for more information
          about us, as well as our other mailing lists

          Before you post to this list, please read
          http://linux-bangalore.org/articles/smart-questions.php


          Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        Your message has been successfully submitted and would be delivered to recipients shortly.