summaryrefslogtreecommitdiffstats
path: root/usr.bin/talk/get_addrs.c
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1996-03-09 19:23:01 +0000
committerjoerg <joerg@FreeBSD.org>1996-03-09 19:23:01 +0000
commita12cf8aa0e1029b87db1d40e09450d0d09635334 (patch)
tree05d5824bd651018bd12409c9b3fa9369e6f2c193 /usr.bin/talk/get_addrs.c
parent17cc9fc50275a82f4224ba957d768981a45929d7 (diff)
downloadFreeBSD-src-a12cf8aa0e1029b87db1d40e09450d0d09635334.zip
FreeBSD-src-a12cf8aa0e1029b87db1d40e09450d0d09635334.tar.gz
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
Diffstat (limited to 'usr.bin/talk/get_addrs.c')
-rw-r--r--usr.bin/talk/get_addrs.c33
1 files changed, 11 insertions, 22 deletions
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 <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <protocols/talkd.h>
+#include <string.h>
#include <netdb.h>
#include <stdio.h>
+#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) {
OpenPOWER on IntegriCloud