inet(3) inet_network() bug, [was: cvs commit: src/usr.sbin/jexec jexec.8 jexec.c]

Bjoern A. Zeeb bz at FreeBSD.org
Thu May 29 15:00:08 UTC 2008


On Thu, 29 May 2008, Oliver Fromme wrote:

Hi,

> > > However, I do share the concern that there's an ambiguity
> > > in the syntax:  "127" can be a jail ID as well as an IP
> > > number (same as 0.0.0.127) or a hostname.  Either the
> >
> > actually 127.0.0.0
>
> I'm afraid I think it is 0.0.0.127.
> 127.0.0.0 would be 2130706432.

127.0.0.1 is 0x0000007f.

~/tmp> ./a.out 127
127.0.0.0

> > > using 127.1 as a shotcut for 127.0.0.1.
> >
> > Yes. because that is 127.1.0.0 and not 127.0.0.1.
>
> I'm pretty sure 127.1 is the same as 127.0.0.1.  Last
> time I used telnet 127.1 to test things it worked fine.
>
> 127.1.0.0 would be 127.65536.

re-reading the man page inet(3) it seems you would be right
for 127.0.0.1 == 127.1 -- just that our implementation of
inet_network() doesn't think you are... *sigh* I know this
function. It's from bind sources...

~/tmp> ./a.out 127.1
1.127.0.0

btw. the 3 digit version seems to be broken as well:
~/tmp> ./a.out 128.1.2
2.1.128.0


~/tmp> cat 127.c 
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <err.h>

int
main(int argc, char *argv[])
{
         in_addr_t ia;
         char buf[16];

         if (argc != 2)
                 errx(1, "usage: %s IP-address", argv[0]);

         ia = inet_network(argv[1]);
         if (ia == INADDR_NONE)
                 err(1, "inet_network");

         if (inet_ntop(AF_INET, &ia, buf, sizeof(buf)) == NULL)
                 err(1, "inet_ntop");

         printf("%s\n", buf);

         return (0);
}

-- 
Bjoern A. Zeeb              Stop bit received. Insert coin for new game.


More information about the cvs-src mailing list