title: how to get the MAC address of client using ioctl function?
body: <p>I want to capture the Client MAC address who are all request for my server. I use the following program to get the MAC address of the client but its showing "ioctl: Protocol Family Not Supported" . How to get the MAC address?..</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;sys/socket.h&gt;
  #include&lt;sys/types.h&gt;
  #include&lt;netinet/in.h&gt;
  #include&lt;netdb.h&gt;
  #include&lt;errno.h&gt;
  #include&lt;string.h&gt;
  #include&lt;netinet/if_ether.h&gt;
  #include&lt;net/if.h&gt;
  #include&lt;linux/sockios.h&gt;
  int main()
  {
    int socket1, socket2;
    socket1 = 0;
    socket2 = 0;
    struct sockaddr_in server, client;
    int returnstatus = 0;
  socket1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if(socket1 == -1)
  {
    perror("socket()");
  }
  
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(8888);
  returnstatus = bind(socket1, (struct sockaddr*)&amp;server, sizeof(server));
  if(returnstatus == -1)
  {
    perror("bind()");
  }
  returnstatus = listen(socket1, 5);
  if(returnstatus == -1)
  {
   perror("listen()");
  }
  for(;;)
  {
    int buffr[4];
    int addrlen, n;
    addrlen = sizeof(client);
    socket2 = accept(socket1, (struct sockaddr *)&amp;client, &amp;addrlen);
      printf("%s\n",inet_ntoa(client.sin_addr));
      printf("%d\n",(int) ntohs(client.sin_port));
  struct arpreq arpreq_;
  bzero(&amp;arpreq_, sizeof(struct arpreq));
  
  if( ( n = ioctl(socket2, SIOCGARP, &amp;arpreq_) ) &lt; 0 ){
  perror("ioctl");
  }
  
  unsigned char *ptr = &amp;arpreq_.arp_ha.sa_data[0];
  printf("MAC: %x:%x:%x:%x:%x:%x\n", *ptr, *(ptr+1), *(ptr+2), *(ptr+3),
  *(ptr+4), *(ptr+5));
  
  if (socket2 == -1)
  {
    perror("accept()");
  }
  returnstatus = read(socket2, buffr, sizeof(buffr));
  
  if(returnstatus == -1)
  {
    perror("read()");
  }
  int c[2]; 
  int *w;
  c[0] = buffr[0] + buffr[1];
  w = c;
  returnstatus = write(socket2, w, sizeof(c));
  if(returnstatus == -1)
  {
   perror("write()");
  }
  close(socket2);
  
  }
  close(socket1);
  return 0;
  }
  
  int addition(int x, int y)
  {
   int z;
   z = x + y;
   return(z);
  }
  </code></pre>