This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Can't get socket's IP address w/ new stack?


I use the following routines to get the current IP address and
netmask.  Both worked fine under the old network stack, but
with the new stack, getting the IP address retuns nothing
(stuct is all 0's).  

I know the IP address is set, since I can commuincation with
the web server.

Can somebody point me to documentation on which ioctl()
operations are supported by the new stack?  

Or better yet, a list of API changes from the old stack to the
new?

unsigned long myIpMask(void)
{
  int s;
  unsigned long r;
  struct ifreq ifr;
  
  if ((s=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    return 0;

  strcpy(ifr.ifr_name, "eth0");

  if (ioctl(s, SIOCGIFNETMASK, &ifr))
    r = 0;
  else
    r = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;

  close(s);
  return r;
}

unsigned long myIpAddr(void)
{
  int s;
  unsigned long r;
  struct ifreq ifr;
  
  if ((s=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    return 0;

  strcpy(ifr.ifr_name, "eth0");
  
  if (ioctl(s, SIOCGIFADDR, &ifr))
      r = 0;
  else
      r = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;

  close(s);
  return r;
}


-- 
Grant Edwards
grante@visi.com

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


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