Implement get HWAddress

This is a discussion on Implement get HWAddress within the Networking/Device Communication forums, part of the General Programming Boards category; Hi, I'm new here, I need some little help here, I have this code and I need get the MAC ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Exclamation Implement get HWAddress

    Hi, I'm new here, I need some little help here, I have this code and I need get the MAC ADDRESS too, I tried few ways, but I dont had lucky.

    Code:
    #include <sys/ioctl.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <net/if.h>
    
    int main()
    {
      struct ifconf conf;
      struct sockaddr_in *s_in;
      int sock, i, count;
    
      // Abrir um socket nulo
      if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
      {
         perror("erro ao abrir o socket.");
         return -1;
      }
    
      // Pega lista de interfaces de rede, so os 10 primeiros.
      memset(&conf, 0, sizeof(conf));
      conf.ifc_len = sizeof(struct ifreq) * 10;
      conf.ifc_buf = (char*) malloc(conf.ifc_len);
            
      if (ioctl(sock, SIOCGIFCONF, &conf) == -1)
      {
         perror("falha ao pegar a lista de interfaces de rede");
         return -1;
      }
    
      count = conf.ifc_len / sizeof(struct ifreq);
    
      for (i = 0; i < count; i++)
      {
         s_in = (struct sockaddr_in*) &conf.ifc_req[i].ifr_addr;
         printf("%s %s\n", conf.ifc_req[i].ifr_name,
                           inet_ntoa(s_in->sin_addr));
      }
    
      free(conf.ifc_buf);
    
      return 0;
    }
    thanks in advance.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,578
    Searching for an answer is out of the question?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-02-2010, 02:26 PM
  2. Replies: 4
    Last Post: 12-20-2007, 07:55 PM
  3. Implement "Whats This" using Win32
    By hemanth.balaji in forum Windows Programming
    Replies: 1
    Last Post: 05-29-2005, 07:03 AM
  4. implement hash program
    By Abdi in forum C Programming
    Replies: 2
    Last Post: 05-19-2002, 12:22 AM
  5. Can't Implement Tabbing
    By Invincible in forum Windows Programming
    Replies: 10
    Last Post: 02-27-2002, 05:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21