- use getnameinfo instead of gethostbyaddr

- add tsa2sa and use it
This commit is contained in:
christos 2007-01-08 17:51:34 +00:00
parent aa3d024933
commit 129c516e3b
3 changed files with 23 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.3 2002/09/19 14:39:51 itojun Exp $ */
/* $NetBSD: extern.h,v 1.4 2007/01/08 17:51:34 christos Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
@ -52,3 +52,4 @@ int delete_invite __P((int));
/* talkd.c */
extern int debug;
extern int logging;
void tsa2sa __P((struct sockaddr *, const struct talkd_sockaddr *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: process.c,v 1.11 2004/10/01 12:27:09 christos Exp $ */
/* $NetBSD: process.c,v 1.12 2007/01/08 17:51:34 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)process.c 8.2 (Berkeley) 11/16/93";
#else
__RCSID("$NetBSD: process.c,v 1.11 2004/10/01 12:27:09 christos Exp $");
__RCSID("$NetBSD: process.c,v 1.12 2007/01/08 17:51:34 christos Exp $");
#endif
#endif /* not lint */
@ -141,9 +141,12 @@ do_announce(mp, rp)
CTL_MSG *mp;
CTL_RESPONSE *rp;
{
struct hostent *hp;
CTL_MSG *ptr;
int result;
char hostname[NI_MAXHOST];
struct sockaddr sa;
tsa2sa(&sa, &mp->ctl_addr);
/* see if the user is logged */
result = find_user(mp->r_name, mp->r_tty, sizeof(mp->r_tty));
@ -151,17 +154,15 @@ do_announce(mp, rp)
rp->answer = result;
return;
}
#define satosin(sa) ((struct sockaddr_in *)(sa))
hp = gethostbyaddr((char *)&satosin(&mp->ctl_addr)->sin_addr,
sizeof (struct in_addr), AF_INET);
if (hp == (struct hostent *)0) {
if (getnameinfo(&sa, sa.sa_len, hostname, sizeof(hostname), NULL,
0, 0)) {
rp->answer = MACHINE_UNKNOWN;
return;
}
ptr = find_request(mp);
if (ptr == (CTL_MSG *) 0) {
insert_table(mp, rp);
rp->answer = announce(mp, hp->h_name);
rp->answer = announce(mp, hostname);
return;
}
if (mp->id_num > ptr->id_num) {
@ -171,7 +172,7 @@ do_announce(mp, rp)
*/
ptr->id_num = new_id();
rp->id_num = htonl(ptr->id_num);
rp->answer = announce(mp, hp->h_name);
rp->answer = announce(mp, hostname);
} else {
/* a duplicated request, so ignore it */
rp->id_num = htonl(ptr->id_num);

View File

@ -1,4 +1,4 @@
/* $NetBSD: talkd.c,v 1.17 2003/08/07 09:46:51 agc Exp $ */
/* $NetBSD: talkd.c,v 1.18 2007/01/08 17:51:34 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)talkd.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: talkd.c,v 1.17 2003/08/07 09:46:51 agc Exp $");
__RCSID("$NetBSD: talkd.c,v 1.18 2007/01/08 17:51:34 christos Exp $");
#endif
#endif /* not lint */
@ -133,9 +133,7 @@ main(argc, argv)
lastmsgtime = time(0);
process_request(mp, &response);
(void)memcpy(&ctl_addr, &mp->ctl_addr, sizeof(ctl_addr));
ctl_addr.sa_family = mp->ctl_addr.sa_family;
ctl_addr.sa_len = sizeof(ctl_addr);
tsa2sa(&ctl_addr, &mp->ctl_addr);
if (ctl_addr.sa_family != AF_INET)
continue;
@ -158,3 +156,11 @@ timeout(n)
alarm(TIMEOUT);
errno = save_errno;
}
void
tsa2sa(struct sockaddr *sa, const struct talkd_sockaddr *tsa)
{
(void)memcpy(sa, tsa, sizeof(*tsa));
sa->sa_len = sizeof(*tsa);
sa->sa_family = tsa->sa_family;
}