summaryrefslogtreecommitdiffstats
path: root/usr.bin/talk
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2001-08-09 06:45:35 +0000
committerdd <dd@FreeBSD.org>2001-08-09 06:45:35 +0000
commit05ca6abd65ef08443f471ab674224faf7e0037b8 (patch)
treea83ae28f586c4a1175e106223a8ca8ab90c26f21 /usr.bin/talk
parent339ce28dbd27e3cfab24cbc191c4fd571559b678 (diff)
downloadFreeBSD-src-05ca6abd65ef08443f471ab674224faf7e0037b8.zip
FreeBSD-src-05ca6abd65ef08443f471ab674224faf7e0037b8.tar.gz
Print the peer's name and address in the "Connection establish"
message. Similar information is given by the talk daemon when a connection is requested, but that part isn't on the screen when the main "talk" screen appears, and sometimes it's nice to know who you're talking to. Reviewed by: ru
Diffstat (limited to 'usr.bin/talk')
-rw-r--r--usr.bin/talk/io.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/usr.bin/talk/io.c b/usr.bin/talk/io.c
index 4a6fd9e..782314f 100644
--- a/usr.bin/talk/io.c
+++ b/usr.bin/talk/io.c
@@ -46,10 +46,13 @@ static const char rcsid[] =
*/
#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/filio.h>
#include <unistd.h>
#include "talk.h"
+#include "talk_ctl.h"
#define A_LONG_TIME 10000000
@@ -59,12 +62,32 @@ static const char rcsid[] =
void
talk()
{
+ struct hostent *hp, *hp2;
int nb;
fd_set read_set, read_template;
- char buf[BUFSIZ];
+ char buf[BUFSIZ], **addr, *his_machine_name;
struct timeval wait;
- message("Connection established");
+ his_machine_name = NULL;
+ hp = gethostbyaddr((const char *)&his_machine_addr.s_addr,
+ sizeof(his_machine_addr.s_addr), AF_INET);
+ if (hp != NULL) {
+ hp2 = gethostbyname(hp->h_name);
+ if (hp2 != NULL && hp2->h_addrtype == AF_INET &&
+ hp2->h_length == sizeof(his_machine_addr))
+ for (addr = hp2->h_addr_list; *addr != NULL; addr++)
+ if (memcmp(*addr, &his_machine_addr,
+ sizeof(his_machine_addr)) == 0) {
+ his_machine_name = strdup(hp->h_name);
+ break;
+ }
+ }
+ if (his_machine_name == NULL)
+ his_machine_name = strdup(inet_ntoa(his_machine_addr));
+ snprintf(buf, sizeof(buf), "Connection established with %s@%s.",
+ msg.r_name, his_machine_name);
+ free(his_machine_name);
+ message(buf);
write(STDOUT_FILENO, "\007\007\007", 3);
current_line = 0;
OpenPOWER on IntegriCloud