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