766047
diff --git a/src/autoconf b/src/autoconf
766047
index 3a52e6c..ff78048 100755
766047
--- a/src/autoconf
766047
+++ b/src/autoconf
766047
@@ -68,8 +68,6 @@
766047
 #	#define NOfsync
766047
 #Ok	#define endpwent()
766047
 #Ok	#define endgrent()
766047
-#Ok	#define endhostent()
766047
-#Ok	#define endservent()
766047
 #Ok	#define endprotoent()
766047
 #	#define h_0addr_list h_addr
766047
 #Ok	#define NOpw_passwd
766047
@@ -896,7 +894,7 @@ int main(){int i=0;
766047
  {uid_t vuid_t;i+=vuid_t=1;}
766047
  {gid_t vgid_t;i+=vgid_t=1;}
766047
 #ifndef NO_COMSAT
766047
- {struct hostent vhostent;i+=!(vhostent.h_addr_list=0);}
766047
+ {struct addrinfo res; i+=!(res.ai_socktype=0);}
766047
 #endif
766047
 #ifndef NOuname
766047
  {struct utsname vutsname;i+=!(*vutsname.nodename='\0');}
766047
@@ -917,8 +915,6 @@ do
766047
   test -z "$i3" && grepfor mode_t 'typedef int mode_t;' && i3=I
766047
   test -z "$i4" && grepfor uid_t 'typedef int uid_t;' && i4=I
766047
   test -z "$i5" && grepfor gid_t 'typedef int gid_t;' && i5=I
766047
-  test -z "$i6" && grepfor h_addr_list '#define h_0addr_list h_addr' && i6=I
766047
-  test -z "$i6" && grepfor hostent '#define h_0addr_list h_addr' && i6=I
766047
   test -z "$i6" && grepfor member '#define h_0addr_list h_addr' && i6=I
766047
   test -z "$i7" && grepfor utsname "#define NOuname			      \
766047
 /* <sys/utsname.h> is there, but empty */" && i7=I
766047
@@ -1048,8 +1044,12 @@ int main(){char a[2];
766047
  {struct utsname b;uname(&b);}
766047
 #endif
766047
 #ifndef NO_COMSAT
766047
- gethostbyname("0");getprotobyname(COMSATprotocol);endhostent();endservent();
766047
- endprotoent();
766047
+ {
766047
+ struct addrinfo *res, hints;
766047
+ memset(&hints, '\0', sizeof(hints));
766047
+ if(getaddrinfo(COMSAThost,BIFF_serviceport,&hints,&res))
766047
+ 	freeaddrinfo(res);
766047
+ }
766047
 #endif
766047
  _exit(0);
766047
  return 0;}
766047
@@ -1103,14 +1103,9 @@ grepfor uname "\
766047
 /* <sys/utsname.h> defines it, the libraries don't */"
766047
 grepfor endpwent '#define endpwent()'
766047
 grepfor endgrent '#define endgrent()'
766047
-if grepfor gethostbyname '#define NO_COMSAT'
766047
+if grepfor getaddrinfo '#define NO_COMSAT'
766047
 then
766047
 :
766047
-else
766047
-  grepfor getprotobyname '#define UDP_protocolno 17'
766047
-  grepfor endhostent '#define endhostent()'
766047
-  grepfor endservent '#define endservent()'
766047
-  grepfor endprotoent '#define endprotoent()'
766047
 fi
766047
 grepfor strstr '#define SLOWstrstr' ||
766047
  grepfor clock '#define SLOWstrstr'
766047
@@ -1239,39 +1234,9 @@ int main(argc,argv)int argc;const char*argv[];
766047
 	printf("/* Insufficient memory to perform the benchmark! */\n");
766047
 #endif /* SLOWstrstr */
766047
 #ifndef NO_COMSAT
766047
-#ifndef UDP_protocolno
766047
-     ;{ const struct protoent*p;
766047
-	if(p=getprotobyname(COMSATprotocol))
766047
-	 { printf("#define UDP_protocolno %d\n",p->p_proto);
766047
-#else
766047
-     ;{ if(1)
766047
-	 {
766047
-#endif
766047
-	   ;{ const struct servent*serv;
766047
-	      if(serv=getservbyname(COMSATservice,COMSATprotocol))
766047
-		 printf("#define BIFF_serviceport \"%d\"\n",
766047
-		  ntohs(serv->s_port));
766047
-	    }
766047
-#ifdef AF_INET
766047
-	   ;{ const struct hostent*host;
766047
-	      if(!strcmp("localhost",COMSAThost)&&
766047
-	       (host=gethostbyname(COMSAThost))&&
766047
-	       host->h_0addr_list&&host->h_addrtype==AF_INET&&
766047
-	       host->h_length)
766047
-	       { int j=host->h_length;
766047
-		 const unsigned char*ad=(void*)host->h_0addr_list;
766047
-		 printf("#define IP_localhost {");
766047
-		 printf("%d",*ad++);
766047
-		 while(--j)
766047
-		    printf(",%d",*ad++);
766047
-		 puts("}");
766047
-	       }
766047
-	    }
766047
+#ifndef AF_INET
766047
+	puts("#define NO_COMSAT");
766047
 #endif /* AF_INET */
766047
-	 }
766047
-	else
766047
-	   puts("#define NO_COMSAT");
766047
-      }
766047
 #endif /* NO_COMSAT */
766047
      ;{ unsigned long s=(size_t)~0;int bits;
766047
 	for(bits=1;s>>=1;bits++);
766047
diff --git a/src/comsat.c b/src/comsat.c
766047
index 9712e74..5082b16 100644
766047
--- a/src/comsat.c
766047
+++ b/src/comsat.c
766047
@@ -27,7 +27,8 @@ static /*const*/char rcsid[]=
766047
 #include "comsat.h"
766047
 
766047
 static int csvalid;		     /* is it turned on with a good address? */
766047
-static struct sockaddr_in csaddr;
766047
+static struct addrinfo cai;
766047
+static struct sockaddr *csaddr;
766047
 static char*cslastf,*cslgname;
766047
 
766047
 void setlfcs(folder)const char*folder;		/* set lastfolder for comsat */
766047
@@ -62,56 +63,32 @@ void setlgcs(name)const char*name;		   /* set logname for comsat */
766047
 }
766047
 
766047
 int setcomsat(chp)const char*chp;
766047
-{ char*chad;int newvalid; struct sockaddr_in newaddr;
766047
+{ char*chad;int newvalid; struct addrinfo *res, hints;
766047
   chad=strchr(chp,SERV_ADDRsep);			     /* @ separator? */
766047
   if(!chad&&!renvint(-1L,chp))
766047
      return csvalid=0;					/* turned off comsat */
766047
   newvalid=1;
766047
   if(chad)
766047
      *chad++='\0';				      /* split the specifier */
766047
+  if(!chad||!*chp)					       /* no service */
766047
+     chp=BIFF_serviceport;				/* new balls please! */
766047
   if(!chad||!*chad)						  /* no host */
766047
-#ifndef IP_localhost			      /* Is "localhost" preresolved? */
766047
      chad=COMSAThost;					/* nope, use default */
766047
-#else /* IP_localhost */
766047
-   { static const unsigned char ip_localhost[]=IP_localhost;
766047
-     newaddr.sin_family=AF_INET;
766047
-     tmemmove(&newaddr.sin_addr,ip_localhost,sizeof ip_localhost);
766047
-   }
766047
-  else
766047
-#endif /* IP_localhost */
766047
-   { const struct hostent*host;		      /* what host?  paranoid checks */
766047
-     if(!(host=gethostbyname(chad))||!host->h_0addr_list)
766047
-      { bbzero(&newaddr.sin_addr,sizeof newaddr.sin_addr);
766047
-	newvalid=0;			     /* host can't be found, too bad */
766047
-      }
766047
-     else
766047
-      { newaddr.sin_family=host->h_addrtype;	     /* address number found */
766047
-	tmemmove(&newaddr.sin_addr,host->h_0addr_list,host->h_length);
766047
-      }
766047
-     endhostent();
766047
-   }
766047
-  if(newvalid)						  /* so far, so good */
766047
-   { int s;
766047
-     if(!chad||!*chp)					       /* no service */
766047
-	chp=BIFF_serviceport;				/* new balls please! */
766047
-     s=strtol(chp,&chad,10);
766047
-     if(chp!=chad)			       /* the service is not numeric */
766047
-	newaddr.sin_port=htons((short)s);		    /* network order */
766047
-     else
766047
-      { const struct servent*serv;
766047
-	serv=getservbyname(chp,COMSATprotocol);		   /* so get its no. */
766047
-	if(serv)
766047
-	   newaddr.sin_port=serv->s_port;
766047
-	else
766047
-	 { newaddr.sin_port=htons((short)0);		  /* no such service */
766047
-	   newvalid=0;
766047
-	 }
766047
-	endservent();
766047
-      }
766047
-   }
766047
+  bzero(&hints,sizeof(hints));
766047
+  hints.ai_socktype=SOCK_DGRAM;
766047
+  hints.ai_flags=AI_ADDRCONFIG;
766047
+  if(getaddrinfo(chad,chp,&hints,&res))
766047
+     newvalid=0;
766047
+  
766047
   onguard();				    /* update the address atomically */
766047
   if(csvalid=newvalid)
766047
-     tmemmove(&csaddr,&newaddr,sizeof(newaddr));
766047
+   { if(csaddr)
766047
+        free(csaddr);
766047
+     csaddr=malloc(res->ai_addrlen);
766047
+     tmemmove(csaddr,res->ai_addr,res->ai_addrlen);
766047
+     tmemmove(&cai,res,sizeof(cai));
766047
+     freeaddrinfo(res);
766047
+   }
766047
   offguard();
766047
   return newvalid;
766047
 }
766047
@@ -132,8 +109,8 @@ void sendcomsat(folder)const char*folder;
766047
    }
766047
   strlcat(buf,COMSATxtrsep,linebuf);			 /* custom seperator */
766047
   strlcat(buf,p,linebuf);			  /* where was it delivered? */
766047
-  if((s=socket(AF_INET,SOCK_DGRAM,UDP_protocolno))>=0)
766047
-   { sendto(s,buf,strlen(buf),0,(struct sockaddr*)&csaddr,sizeof(csaddr));
766047
+  if((s=socket(cai.ai_family,cai.ai_socktype,cai.ai_protocol))>=0)
766047
+   { sendto(s,buf,strlen(buf),0,csaddr,cai.ai_addrlen);
766047
      rclose(s);
766047
      yell("Notified comsat:",buf);
766047
    }
766047
diff --git a/src/network.h b/src/network.h
766047
index d7d08f2..b09b6c4 100644
766047
--- a/src/network.h
766047
+++ b/src/network.h
766047
@@ -1,19 +1,13 @@
766047
 /*$Id: network.h,v 1.7 1997/04/02 03:15:41 srb Exp $*/
766047
 
766047
-#include <sys/socket.h>			/* socket() sendto() AF_INET
766047
+#include <sys/socket.h>			/* socket() sendto() */
766047
 					/* SOCK_DGRAM */
766047
-#include <netdb.h>			/* gethostbyname() getservbyname()
766047
-					/* getprotobyname() */
766047
-#include <netinet/in.h>			/* htons() struct sockaddr_in */
766047
+#include <netdb.h>			/* getaddrinfo() */
766047
 
766047
 #ifndef BIFF_serviceport
766047
 #define BIFF_serviceport	COMSATservice
766047
 #endif
766047
 
766047
-#ifndef h_0addr_list
766047
-#define h_0addr_list	h_addr_list[0]		      /* POSIX struct member */
766047
-#endif
766047
-
766047
 #ifndef NO_const      /* since network.h is outside the autoconf const check */
766047
 #ifdef const		    /* loop, we need this backcheck for some systems */
766047
 #undef const