From a12cf8aa0e1029b87db1d40e09450d0d09635334 Mon Sep 17 00:00:00 2001 From: joerg Date: Sat, 9 Mar 1996 19:23:01 +0000 Subject: Make talk automagically find out the interface IP address where the remote peer will be connected through. This avoids the ``Checking for invitation on caller's machine'' problem for multi-homed hosts. Thanks to: Garrett, for his `find_interface' example --- usr.bin/talk/get_addrs.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'usr.bin/talk/get_addrs.c') diff --git a/usr.bin/talk/get_addrs.c b/usr.bin/talk/get_addrs.c index b9db4a6..7ac9267 100644 --- a/usr.bin/talk/get_addrs.c +++ b/usr.bin/talk/get_addrs.c @@ -35,14 +35,13 @@ static char sccsid[] = "@(#)get_addrs.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ -#include -#include -#include -#include +#include #include #include +#include "talk.h" #include "talk_ctl.h" +void get_addrs(my_machine_name, his_machine_name) char *my_machine_name, *his_machine_name; { @@ -50,28 +49,18 @@ get_addrs(my_machine_name, his_machine_name) struct servent *sp; msg.pid = htonl(getpid()); - /* look up the address of the local host */ - hp = gethostbyname(my_machine_name); + + hp = gethostbyname(his_machine_name); if (hp == NULL) { - fprintf(stderr, "talk: %s: ", my_machine_name); + fprintf(stderr, "talk: %s: ", his_machine_name); herror((char *)NULL); exit(-1); } - bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length); - /* - * If the callee is on-machine, just copy the - * network address, otherwise do a lookup... - */ - if (strcmp(his_machine_name, my_machine_name)) { - hp = gethostbyname(his_machine_name); - if (hp == NULL) { - fprintf(stderr, "talk: %s: ", his_machine_name); - herror((char *)NULL); - exit(-1); - } - bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length); - } else - his_machine_addr = my_machine_addr; + bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length); + if (get_iface(&his_machine_addr, &my_machine_addr) == -1) { + perror("failed to find my interface address"); + exit(-1); + } /* find the server's port */ sp = getservbyname("ntalk", "udp"); if (sp == 0) { -- cgit v1.1