Subject: API suggestion

From: Richard Draves <[email-masked]>
Date: Fri, 17 Dec 1999 17:02:09 -0800

Since there's been some mail recently about getaddrinfo and new flags...
based on some recent experience porting code to use getaddrinfo, I'd suggest
adding a flag that says return only IP addresses, either AF_INET or AF_INET6
but not other address families. And ideally there would also be a
"sockaddr_ip" that was a union of sockaddr_in and sockaddr_in6 and in
particular gave easy access to the port field.

The reason being, that is was easier to port code to getaddrinfo while
maintaining the assumption that addresses have a port field, instead of
truly making the code address/protocol-independent.

Rich
--------------------------------------------------------------------
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: Tue, 21 Dec 1999 16:49:22 +0900

>truly making the code address/protocol-independent.

	At least for 4.4BSD derived systems, "port" portion is located
	at same bits for sockaddr_in6 and sockaddr_in.
	I do not get why you need sockaddr_ip.  struct addrinfo is tagged
	correctly with ai_family so there should be no trouble.

	Separately, we may need some function/macro that manipulates sockaddr,
	for:
	- comparing two sockaddrs at ease.  family and length must match.
	  i can think of:
		- address (and scope) match
		- port match
		- address (and scope) and port match
		- address (and scope) with certain prefix length match only.
	- masking address with prefix length.
	cmetz and francis wanted these.  Does this solve your problem?

itojun

---

From: Hideaki YOSHIFUJI <[email-masked]>
Date: Wed, 22 Dec 1999 00:06:50 +0900

In article <4D0A23B3F74DD111ACCD00805F31D8101CA2187E@RED-MSG-50> (at Fri, 17 Dec 1999 17:02:09 -0800), Richard Draves <[email-masked]> says:

> but not other address families. ...

Your suggestion (that you want to add new flag) is not generic solution 
and has drawbacks in 2 points at least:

1. you cannot specify other set of families.
   ex) IPv6 and IPv7 addresses are wanted, but I hate IPv4.
2. you cannot specify the order of items in answered list.
   ex) I want to get IPv4 first because throughputs of IPv4 connections 
       are much better than that of IPv6 ones.

Another aproach that I suggest, is to use multiple-hints that can query 
for multiple-families, multiple-socktypes and even multiple-flags 
answers like this:

/* Sample code */
#include <stdio.h>
#include <sys/socket.h>
#include <netdb.h>

int main(int argc, char *argv[]){
  struct addrinfo hints[2], *res0, *res;
  int gai;
  char *host, *serv;
  char buff[NI_MAXHOST];

  host = (argc > 1) ? argv[1] : "localhost";
  serv = (argc > 2) ? argv[2] : "80";

  printf("host='%s', serv='%s'\n", host, serv);

  memset(&hints[0], 0, sizeof(hints[0]));
  hints[0].ai_family = PF_INET6 ;
  hints[0].ai_socktype = SOCK_STREAM;
  hints[0].ai_next = &hints[1];
  memset(&hints[1], 0, sizeof(hints[1]));
  hints[1].ai_family = PF_INET;
  hints[1].ai_socktype = SOCK_STREAM;
  hints[1].ai_next = NULL;
  res = res0 = NULL;

  /* the order of items in the result list (res0) 
     should be PF_INET6 -> PF_INET */
  gai = getaddrinfo(host, serv, &hints[0], &res0);

  printf ("gai=%d (%s), res0=0x%X\n", 
	  gai, (gai ? gai_strerror(gai) : "OK"), res0);
  if (!gai){
    for (res=res0; res; res=res->ai_next){
      buff[0] = '\0';
      getnameinfo(res->ai_addr, res->ai_addrlen,
		  buff, sizeof(buff), NULL, 0,
		  NI_NUMERICHOST);
      printf ("family=%d, socktype=%d, addr=%s\n", 
	      res->ai_family, res->ai_socktype, buff);
    }
  }
  if (res0) freeaddrinfo(res0);

  return (0);
}

-- 
Hideaki YOSHIFUJI <[email-masked]>
Web Page: http://www.ecei.tohoku.ac.jp/%7Eyoshfuji/
PGP5i FP: F731 6599 5EB2 BBA7 1515  1323 1806 A96F 5700 6B25 
--------------------------------------------------------------------
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: Wed, 22 Dec 1999 12:36:41 +0900

>for multiple-families, multiple-socktypes and even multiple-flags 

	If the granurality of flexibility is address family (i.e. you do not
	try to tweak about v4 mapped address, for example),
	you can always perform two lookup (two calls to getaddrinfo) to
	get the same result (you just need to append two lists).  what is
	wrong with it?

itojun

---

From: Jim Bound <[email-masked]>
Date: Tue, 21 Dec 1999 22:50:10 -0500

Itojun,

>	get the same result (you just need to append two lists).  what is

I don't want my ISV apps to have to do two getaddrinfo queries.  Just
one and one big list with both families.  This is pretty easy to
implement and it works now with getipnodebyname as one example its
AI_ALL.  This functionality has been deployed already we must support it
in the update to getaddrinfo.  I know apps that use it now for IPv6.

/jim

---

From: [email-masked]
Date: Wed, 22 Dec 1999 12:55:09 +0900

>in the update to getaddrinfo.  I know apps that use it now for IPv6.

	I'm not sure I got your point...  AI_ALL and Hideaki's proposal
	looks to be very separate for me.

itojun

---

From: Jim Bound <[email-masked]>
Date: Tue, 21 Dec 1999 23:08:32 -0500

>	looks to be very separate for me.

Yes my mistake.  I just want all addresses back from AI_ALL for AF_INET6
so I will get all native IPv6 addresses and all IPv4 addresses as
Mapped.

So do we need to discuss it further?  But what about PF_UNSPEC ???? 

We did get input during base API discussion to return both families and
that was rejected as a historical note.

/jim

---

From: Francis Dupont <[email-masked]>
Date: Tue, 28 Dec 1999 19:59:41 +0100

In your previous mail you wrote:

   	Separately,

=> I'd like to get standard function/macros to set/get the port field too
(I already have some but they are not (yet?) standardized).

        we may need some function/macro that manipulates sockaddr,
   	for:
   	- comparing two sockaddrs at ease.  family and length must match.
   	  i can think of:
   		- address (and scope) match
   		- port match
   		- address (and scope) and port match
   		- address (and scope) with certain prefix length match only.
   	- masking address with prefix length.
   	cmetz and francis wanted these.

=> I still want these (:-)!

Thanks

[email-masked]