This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Pb with ioctl()


I have a problem for compiling this function :

Errors :
gpublic.c: In function `get_hwaddr':
gpublic.c:943: `SIOCGIFHWADDR' undeclared (first use in this function)
gpublic.c:943: (Each undeclared identifier is reported only once
gpublic.c:943: for each function it appears in.)
gpublic.c:956: structure has no member named `ifr_hwaddr'
gpublic.c:957: structure has no member named `ifr_hwaddr'
gpublic.c:958: structure has no member named `ifr_hwaddr'
gpublic.c:959: structure has no member named `ifr_hwaddr'
gpublic.c:960: structure has no member named `ifr_hwaddr'
gpublic.c:961: structure has no member named `ifr_hwaddr'
 

Source code :
int get_hwaddr(char *interface, char hwaddr[]) {

 int sd;

 struct ifreq req;
 sd = socket(AF_INET,SOCK_DGRAM,IPPROTO_IP);
 if (sd == -1) {
  perror("socket()");
  return -1;
 }
 sprintf(req.ifr_name,"%s",interface);
 if (ioctl(sd,SIOCGIFHWADDR,&req) == -1)  {
  perror("ioctl():SIOCGIFHWADDR");
  return -1;
 }
/*
 sprintf(hwaddr,"%02x:%02x:%02x:%02x:%02x:%02x",
(int)(req.ifr_hwaddr.sa_data[0] & 0xff),
(int)(req.ifr_hwaddr.sa_data[1] & 0xff),
(int)(req.ifr_hwaddr.sa_data[2] & 0xff),
(int)(req.ifr_hwaddr.sa_data[3] & 0xff),
(int)(req.ifr_hwaddr.sa_data[4] & 0xff),
(int)(req.ifr_hwaddr.sa_data[5] & 0xff)); */
  sprintf(hwaddr,"%d%d%d%d%d%d",
 (int)(req.ifr_hwaddr.sa_data[0] & 0xff),
 (int)(req.ifr_hwaddr.sa_data[1] & 0xff),
 (int)(req.ifr_hwaddr.sa_data[2] & 0xff),
 (int)(req.ifr_hwaddr.sa_data[3] & 0xff),
 (int)(req.ifr_hwaddr.sa_data[4] & 0xff),
 (int)(req.ifr_hwaddr.sa_data[5] & 0xff));
 return 0;
 

How can I make a good compilation ?

-- 
Bertrand Bourdon - Chef de Projet Informatique
PerformanSe S.A., l'évaluation des compétences et des comportements 
BP 703  - 44481 Carquefou Cedex - Tél. : 02 28 01 55 13 
http://www.performanse.fr/ Mailto:bertrand.bourdon@performanse.fr
 
Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]