[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
hostmux using getaddrinfo
From: |
James A Morrison |
Subject: |
hostmux using getaddrinfo |
Date: |
Sat, 9 Mar 2002 17:38:45 -0500 (EST) |
Hi, I managed to get this to work manually bootstrapping it to show that
these changes work.
2002-03-09 James A. Morrison <ja2morri@uwaterloo.ca>
* mux.c: Changed lookup behaviour to use the addrinfo struct instead of
the hostent struct. Renamed lookup_hostent to lookup_addrinfo.
Index: mux.c
===================================================================
RCS file: /cvsroot/hurd/hurd/hostmux/mux.c,v
retrieving revision 1.7
diff -u -r1.7 mux.c
--- mux.c 1 Aug 2001 13:00:55 -0000 1.7
+++ mux.c 9 Mar 2002 20:10:25 -0000
@@ -273,8 +273,8 @@
if HOST refers to the official name of the host, or a symlink node to the
official name, if it doesn't. */
static error_t
-lookup_hostent (struct hostmux *mux, const char *host, struct hostent *he,
- struct node **node)
+lookup_addrinfo (struct hostmux *mux, const char *host, struct addrinfo *he,
+ struct node **node)
{
error_t err;
struct hostmux_name *nm = malloc (sizeof (struct hostmux_name));
@@ -283,10 +283,10 @@
return ENOMEM;
nm->name = strdup (host);
- if (strcmp (host, he->h_name) == 0)
+ if (strcmp (host, he->ai_canonname) == 0)
nm->canon = nm->name;
else
- nm->canon = strdup (he->h_name);
+ nm->canon = strdup (he->ai_canonname);
err = create_host_node (mux, nm, node);
if (err)
@@ -325,9 +325,12 @@
{
int was_cached;
int h_err;
- struct hostent _he, *he;
- struct in_addr inet_addr;
- char hostent_data[2048]; /* XXX what size should this be???? */
+ struct addrinfo *ai;
+ struct addrinfo hints;
+ hints.ai_flags = AI_CANONNAME;
+ hints.ai_family = PF_INET;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_IP;
rwlock_reader_lock (&mux->names_lock);
was_cached = lookup_cached (mux, host, 0, node);
@@ -335,20 +338,15 @@
if (was_cached)
return 0;
- else if (inet_aton (host, &inet_addr))
+
+ h_err = getaddrinfo (host, NULL, &hints, &ai);
+
+ if (! h_err)
{
- if (gethostbyaddr_r ((char *)&inet_addr, sizeof inet_addr, AF_INET,
- &_he, hostent_data, sizeof hostent_data,
- &he, &h_err) == 0)
- return lookup_hostent (mux, host, he, node);
- else
- return ENOENT;
+ h_err = lookup_addrinfo (mux, host, ai, node);
+ freeaddrinfo (ai);
}
- else if (gethostbyname_r (host, &_he, hostent_data, sizeof hostent_data,
- &he, &h_err) == 0)
- return lookup_hostent (mux, host, he, node);
- else
- return ENOENT;
+ return h_err;
}
/* This should sync the entire remote filesystem. If WAIT is set, return
- hostmux using getaddrinfo,
James A Morrison <=