inet:ip/1

Matthias Lang matthias@REDACTED
Wed Apr 12 23:41:22 CEST 2006


This doesn't seem to be erlang-specific behaviour, which makes me
suspect that there's more to this than appears at first glance.

Try playing around with the attached program.

Matthias

--------------------

Serge Aleynikov writes:
 > While playing with the inet:ip/1 function I noticed that it can take an 
 > argument containing less than four octets.  What's the meaning of such a 
 > strange conversion like inet:ip("1.2.3")?
 > 
 > 1> inet:ip("1.2.3.4").
 > {ok,{1,2,3,4}}
 > 2> inet:ip("1.2.3").
 > {ok,{1,2,0,3}}
 > 3> inet:ip("1.2").
 > {ok,{1,0,0,2}}
 > 4> inet:ip("1").
 > {ok,{0,0,0,1}}
 > 
 > Serge

----------------------------------------------------------------------
#include <netdb.h>
#include <stdio.h>
#include <assert.h>

int main() {
	struct hostent* he;
	unsigned char** addr;

	he = gethostbyname("1");

	assert(he);
	addr = he->h_addr_list;

	while (*addr) {
		printf("hostent entry: %u.%u.%u.%u\n", **addr, *(*addr+1), *(*addr+2), *(*addr+3));
		addr++;
	}

	return 0;
}



More information about the erlang-questions mailing list