- use warn/err
- if both users are on the same machine, use the loopback address. This allows us to use talkd from inetd listening only to the loopback.
This commit is contained in:
parent
7c8b13934d
commit
0be3040a8f
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: get_addrs.c,v 1.10 2011/09/06 18:32:03 joerg Exp $ */
|
||||
/* $NetBSD: get_addrs.c,v 1.11 2012/12/29 23:44:22 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)get_addrs.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
__RCSID("$NetBSD: get_addrs.c,v 1.10 2011/09/06 18:32:03 joerg Exp $");
|
||||
__RCSID("$NetBSD: get_addrs.c,v 1.11 2012/12/29 23:44:22 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "talk.h"
|
||||
@ -42,6 +42,7 @@ __RCSID("$NetBSD: get_addrs.c,v 1.10 2011/09/06 18:32:03 joerg Exp $");
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include "talk_ctl.h"
|
||||
|
||||
void
|
||||
@ -51,34 +52,30 @@ get_addrs(const char *my_machine_name, const char *his_machine_name)
|
||||
struct servent *sp;
|
||||
|
||||
msg.pid = htonl(getpid());
|
||||
/* look up the address of the local host */
|
||||
hp = gethostbyname(my_machine_name);
|
||||
if (hp == NULL) {
|
||||
fprintf(stderr, "talk: %s: ", my_machine_name);
|
||||
herror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
memmove((char *)&my_machine_addr, hp->h_addr, hp->h_length);
|
||||
/*
|
||||
* If the callee is on-machine, just copy the
|
||||
* network address, otherwise do a lookup...
|
||||
* If the callee is on-machine, just use loopback
|
||||
* otherwise do a lookup...
|
||||
*/
|
||||
if (strcmp(his_machine_name, my_machine_name)) {
|
||||
if (strcmp(his_machine_name, my_machine_name) != 0) {
|
||||
/* look up the address of the local host */
|
||||
hp = gethostbyname(my_machine_name);
|
||||
if (hp == NULL)
|
||||
errx(EXIT_FAILURE, "%s: %s", my_machine_name,
|
||||
hstrerror(h_errno));
|
||||
memcpy(&my_machine_addr, hp->h_addr, sizeof(my_machine_addr));
|
||||
hp = gethostbyname(his_machine_name);
|
||||
if (hp == NULL) {
|
||||
fprintf(stderr, "talk: %s: ", his_machine_name);
|
||||
herror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
memmove((char *) &his_machine_addr, hp->h_addr, hp->h_length);
|
||||
if (hp == NULL)
|
||||
errx(EXIT_FAILURE, "%s: %s", his_machine_name,
|
||||
hstrerror(h_errno));
|
||||
memcpy(&his_machine_addr, hp->h_addr, sizeof(his_machine_addr));
|
||||
} else
|
||||
his_machine_addr = my_machine_addr;
|
||||
his_machine_addr.s_addr = my_machine_addr.s_addr =
|
||||
htonl(INADDR_LOOPBACK);
|
||||
|
||||
/* find the server's port */
|
||||
sp = getservbyname("ntalk", "udp");
|
||||
if (sp == 0) {
|
||||
fprintf(stderr, "talk: %s/%s: service is not registered.\n",
|
||||
if (sp == 0)
|
||||
errx(EXIT_FAILURE, "%s/%s: service is not registered.\n",
|
||||
"ntalk", "udp");
|
||||
exit(1);
|
||||
}
|
||||
daemon_port = sp->s_port;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: get_names.c,v 1.15 2011/09/06 18:32:03 joerg Exp $ */
|
||||
/* $NetBSD: get_names.c,v 1.16 2012/12/29 23:44:23 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)get_names.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
__RCSID("$NetBSD: get_names.c,v 1.15 2011/09/06 18:32:03 joerg Exp $");
|
||||
__RCSID("$NetBSD: get_names.c,v 1.16 2012/12/29 23:44:23 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "talk.h"
|
||||
@ -61,20 +61,17 @@ get_names(int argc, char *argv[])
|
||||
char *names;
|
||||
|
||||
if (argc < 2 ) {
|
||||
printf("usage: talk user [ttyname]\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!isatty(0)) {
|
||||
printf("Standard input must be a tty, not a pipe or a file\n");
|
||||
fprintf(stderr, "Usage: %s user [ttyname]\n", getprogname());
|
||||
exit(1);
|
||||
}
|
||||
if (!isatty(0))
|
||||
errx(EXIT_FAILURE, "Standard input must be a tty, "
|
||||
"not a pipe or a file");
|
||||
if ((my_name = getlogin()) == NULL) {
|
||||
struct passwd *pw;
|
||||
|
||||
if ((pw = getpwuid(getuid())) == NULL) {
|
||||
printf("You don't exist. Go away.\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((pw = getpwuid(getuid())) == NULL)
|
||||
errx(EXIT_FAILURE, "You don't exist. Go away.");
|
||||
my_name = pw->pw_name;
|
||||
}
|
||||
if ((cp = getenv("TALKHOST")) != NULL)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: invite.c,v 1.9 2011/09/06 18:32:03 joerg Exp $ */
|
||||
/* $NetBSD: invite.c,v 1.10 2012/12/29 23:44:23 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)invite.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
__RCSID("$NetBSD: invite.c,v 1.9 2011/09/06 18:32:03 joerg Exp $");
|
||||
__RCSID("$NetBSD: invite.c,v 1.10 2012/12/29 23:44:23 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "talk.h"
|
||||
@ -43,6 +43,7 @@ __RCSID("$NetBSD: invite.c,v 1.9 2011/09/06 18:32:03 joerg Exp $");
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include "talk_ctl.h"
|
||||
|
||||
/*
|
||||
@ -179,11 +180,11 @@ send_delete(void)
|
||||
if (sendto(ctl_sockt, &msg, sizeof (msg), 0,
|
||||
(struct sockaddr *)&daemon_addr,
|
||||
sizeof (daemon_addr)) != sizeof(msg))
|
||||
perror("send_delete (remote)");
|
||||
warn("send_delete (remote)");
|
||||
msg.id_num = htonl(local_id);
|
||||
daemon_addr.sin_addr = my_machine_addr;
|
||||
if (sendto(ctl_sockt, &msg, sizeof (msg), 0,
|
||||
(struct sockaddr *)&daemon_addr,
|
||||
sizeof (daemon_addr)) != sizeof (msg))
|
||||
perror("send_delete (local)");
|
||||
warn("send_delete (local)");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user