[En-Nut-Discussion] u_long inet_addr(CONST char * str) returns -1

Harald Kipp harald.kipp at egnite.de
Thu Nov 13 13:04:46 CET 2008


José Vallet wrote:
> I have noticed that the definition of the inet_ntoa function (line 172 
> of file inet.c) goes like this.
> 
> u_long inet_addr(CONST char * str)
> {
>   ...
>   return -1;
> }
> 
> To me this looks weird, as the value to be returned is supposed to be 
> unsigned. So I guess I am missing something. Does this mean that the 
> returned value will be 2^32-1 and that is supposed to be the value 
> returned when error?

More details can be found here:
http://linux.die.net/man/3/inet_addr
However, this uses in_addr_t instead of u_long found in Nut/OS 4.6 or 
uint32_t found in later Nut/OS versions. But in general they return IP 
address 255.255.255.255 in case of an error, which is INADDR_NONE or 
(uint32_t)-1.

> And shouldn't the compiler complain about this?

Frankly, I do not know how GCC decides when to silently convert a 
constant to the required type and when to spit out a warning. Upcoming 
versions may indeed complain.

Harald




More information about the En-Nut-Discussion mailing list