lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] inet_ntoa implementation


From: Sergio PérezAlcañiz
Subject: [lwip-users] inet_ntoa implementation
Date: Fri, 11 Apr 2003 10:50:58 +0200 (CEST)
User-agent: IMP/PHP IMAP webmail program 2.2.3

Hello, I'm using the porting of ares in my own lwip porting (RTLinux porting)
and I find very interesting to have a inet_ntoa implementation. Next lines are a
simple implementation for that. 

Include in the file inet.h this line:
char *inet_ntoa(struct in_addr in);


and at the end of inet.c:


static unsigned int i2a(char* dest,unsigned int x) {
  register unsigned int tmp=x;
  register unsigned int len=0;
  if (x>=100) { *dest++=tmp/100+'0'; tmp=tmp%100; ++len; }
  if (x>=10) { *dest++=tmp/10+'0'; tmp=tmp%10; ++len; }
  *dest++=tmp+'0';
  return len+1;
}

char *inet_ntoa(struct in_addr in) {
  static char buf[20];
  unsigned int len;
  unsigned char *ip=(unsigned char*)∈
  len=i2a(buf,ip[0]); buf[len]='.'; ++len;
  len+=i2a(buf+ len,ip[1]); buf[len]='.'; ++len;
  len+=i2a(buf+ len,ip[2]); buf[len]='.'; ++len;
  len+=i2a(buf+ len,ip[3]); buf[len]=0;
  return buf;
}


I think that this is useful for everybody who uses the socket api.


Regards.
Sergio.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]