Subject: getaddrinfo with numeric port number and hints->ai_socktype == 0

From: Assar Westerlund <[email-masked]>
Date: 17 Feb 2000 03:34:08 +0100

What should be the behaviour of these two programs?  It seems rather
limited and unuseful for the first program a) to return EAI_SERVICE,
when it's basically the same as program b).  I think that all socket
types should be considered as supported for a numeric servname.

The only text I could find in rfc2553 on this matter is the definition
of the EAI_SERVICE error code:

      EAI_SERVICE     servname not supported for ai_socktype

It is useful to be able to specify a service/port number numerically,
for example, when looking up the service with getservbyname() or
equivalent and having a numeric fallback in case the particular host
does not have that mapping configured or when accepting explicit port
numbers as arguments from the user.

Comments?

/assar

----------------------------------------------------------------------
/* a) */

#include <stdio.h>
#include <string.h>
#include <netdb.h>

int main(int argc, char **argv)
{
	struct addrinfo hints;
	struct addrinfo *ai, *a;
	int ret;

	memset (&hints, 0, sizeof(hints));
	ret = getaddrinfo ("localhost", "7", &hints, &ai);
	if(ret) {
		printf("failed: %s\n", gai_strerror(ret));
		return 1;
	}
	for (a = ai; a != NULL; a = a->ai_next)
	    printf ("family = %d, socktype = %d\n",
		    a->ai_family, a->ai_socktype);
	return 0;
}
----------------------------------------------------------------------
/* b) */
#include <stdio.h>
#include <string.h>
#include <netdb.h>

int main(int argc, char **argv)
{
	struct addrinfo hints;
	struct addrinfo *ai, *a;
	int ret;

	memset (&hints, 0, sizeof(hints));
	ret = getaddrinfo ("localhost", "echo", &hints, &ai);
	if(ret) {
		printf("failed: %s\n", gai_strerror(ret));
		return 1;
	}
	for (a = ai; a != NULL; a = a->ai_next)
	    printf ("family = %d, socktype = %d\n",
		    a->ai_family, a->ai_socktype);
	return 0;
}
----------------------------------------------------------------------
--------------------------------------------------------------------
IETF IPng Working Group Mailing List
IPng Home Page:                      http://playground.sun.com/ipng
FTP archive:                      ftp://playground.sun.com/pub/ipng
Direct all administrative requests to [email-masked]
--------------------------------------------------------------------

---

From: [email-masked]
Date: Thu, 17 Feb 2000 11:47:33 +0900

>types should be considered as supported for a numeric servname.

	If I remember correctly, with numeric port number you need to somehow
	specify you need either UDP or TCP.  In some cases port numbers are
	not the same for TCP and UDP (in some cases only one of them are
	in the table) so it is not very good to set port # to
	"7" blindly for both entries.

itojun

---

From: Assar Westerlund <[email-masked]>
Date: 17 Feb 2000 03:56:36 +0100

[email-masked] writes:
> 	specify you need either UDP or TCP.

Why shouldn't we assume that the programmer actually knows what (s)he
is doing?  If you want udp or tcp you can specify it in
`hints.ai_socktype'.  If you _do_ want both, should you have to
perform two (at least) calls to getaddrinfo?

>       In some cases port numbers are

Yes, but since we're not going to look them up in services (or
equivalent), we might as well trust the programmer.  Should you not be
able to create sockets even the ports you're using are not listed in
services?

/assar

---

From: [email-masked]
Date: Thu, 17 Feb 2000 12:52:52 +0900

>perform two (at least) calls to getaddrinfo?

	This may be KAME implementation issue, not the spec problem.
	I couldn't find explicit mention in RFC2553, nor X/Open spec.

	NRL (= BIND9 = BIND8 = glibc) and KAME behaves the same against the
	situation, both will raise error.  De-facto?

	The problem here is (I believe) that RFC2553 does not specify well
	enough how should we glob the input on which case.
	By "enough" I mean a specification which gives us uniform behavior.
	I really would like to see more examples on how it should behave.

	Things gets more interesting if we think about AF_LOCAL and other
	families...

itojun

---

From: Vladislav Yasevich <[email-masked]>
Date: Thu, 17 Feb 2000 10:03:24 -0500

>         I couldn't find explicit mention in RFC2553, nor X/Open spec.

Here is what XNS 5.2 states:
	If a specific socket type is not given (for example, a value of zero) and the
	service name could be interpreted as valid with multiple supported socket
types,
	the implementation will attempt to resolve the service name for all supported
	socket types and, in absense of errors, all possible successful results will be
	returned. A non-zero socket type value will limit the returned information to
	values with the specified socket type.

I am currently working on supporting this in our implementation.

>         I really would like to see more examples on how it should behave.

You are right.  Hopefully 2552bis will specify this better and then sync up with
XNS
so both specs will be identical in their definitions.

-vlad

-- 
+++++++++++++++++++++++++++++++
Vladislav Yasevich
Compaq Computer Corp.
110 Spit Brook Rd ZK03-3/T07
Nashua, NH 03062
(603) 884-1079
--------------------------------------------------------------------
IETF IPng Working Group Mailing List
IPng Home Page:                      http://playground.sun.com/ipng
FTP archive:                      ftp://playground.sun.com/pub/ipng
Direct all administrative requests to [email-masked]
--------------------------------------------------------------------