diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-05-09 14:20:58 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-05-09 14:20:58 -0400 |
commit | 5fd83771641d15c418f747bd343ba6738d3875f7 (patch) | |
tree | 5abf0f78f680d9837dbd93d4d4c3933bb7509599 /remote_cmds/talk.tproj | |
download | apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.gz apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.zst apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.zip |
Import macOS userland
adv_cmds-176
basic_cmds-55
bootstrap_cmds-116.100.1
developer_cmds-66
diskdev_cmds-667.40.1
doc_cmds-53.60.1
file_cmds-321.40.3
mail_cmds-35
misc_cmds-34
network_cmds-606.40.1
patch_cmds-17
remote_cmds-63
shell_cmds-216.60.1
system_cmds-880.60.2
text_cmds-106
Diffstat (limited to 'remote_cmds/talk.tproj')
-rw-r--r-- | remote_cmds/talk.tproj/Makefile | 14 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/ctl.c | 128 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/ctl_transact.c | 125 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/display.c | 198 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/get_addrs.c | 71 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/get_iface.c | 103 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/get_names.c | 126 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/init_disp.c | 245 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/invite.c | 202 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/io.c | 188 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/look_up.c | 127 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/msgs.c | 87 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/talk.1 | 172 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/talk.c | 92 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/talk.h | 97 | ||||
-rw-r--r-- | remote_cmds/talk.tproj/talk_ctl.h | 43 |
16 files changed, 2018 insertions, 0 deletions
diff --git a/remote_cmds/talk.tproj/Makefile b/remote_cmds/talk.tproj/Makefile new file mode 100644 index 0000000..47e3631 --- /dev/null +++ b/remote_cmds/talk.tproj/Makefile @@ -0,0 +1,14 @@ +Project = talk +Install_Dir = /usr/bin + +HFILES = talk.h talk_ctl.h +CFILES = ctl.c ctl_transact.c display.c get_addrs.c get_names.c\ + get_iface.c init_disp.c invite.c io.c look_up.c msgs.c talk.c +MANPAGES = talk.1 + +Extra_CC_Flags = -Wall -Werror -fPIE +Extra_LD_Flags = -dead_strip -pie + +Extra_LD_Libraries = -lcurses + +include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/remote_cmds/talk.tproj/ctl.c b/remote_cmds/talk.tproj/ctl.c new file mode 100644 index 0000000..a5b42cc --- /dev/null +++ b/remote_cmds/talk.tproj/ctl.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/ctl.c,v 1.10 2005/02/09 09:13:36 stefanf Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)ctl.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +/* + * This file handles haggling with the various talk daemons to + * get a socket to talk to. sockt is opened and connected in + * the progress + */ + +#include <sys/types.h> +#include <sys/socket.h> + +#include <string.h> + +#include "talk.h" + +struct sockaddr_in daemon_addr = { sizeof(daemon_addr), AF_INET }; +struct sockaddr_in ctl_addr = { sizeof(ctl_addr), AF_INET }; +struct sockaddr_in my_addr = { sizeof(my_addr), AF_INET }; + + /* inet addresses of the two machines */ +struct in_addr my_machine_addr; +struct in_addr his_machine_addr; + +u_short daemon_port; /* port number of the talk daemon */ + +int ctl_sockt; +int sockt; +int invitation_waiting = 0; + +CTL_MSG msg; + +void +open_sockt() +{ + socklen_t length; + + (void)memset(&my_addr, 0, sizeof(my_addr)); + my_addr.sin_family = AF_INET; + my_addr.sin_len = sizeof(my_addr); + my_addr.sin_addr = my_machine_addr; + my_addr.sin_port = 0; + sockt = socket(AF_INET, SOCK_STREAM, 0); + if (sockt == -1) + p_error("Bad socket"); + if (bind(sockt, (struct sockaddr *)&my_addr, sizeof(my_addr)) != 0) + p_error("Binding local socket"); + length = sizeof(my_addr); + if (getsockname(sockt, (struct sockaddr *)&my_addr, &length) == -1) + p_error("Bad address for socket"); +} + +/* open the ctl socket */ +void +open_ctl() +{ + socklen_t length; + + (void)memset(&ctl_addr, 0, sizeof(ctl_addr)); + ctl_addr.sin_family = AF_INET; + ctl_addr.sin_len = sizeof(my_addr); + ctl_addr.sin_port = 0; + ctl_addr.sin_addr = my_machine_addr; + ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0); + if (ctl_sockt == -1) + p_error("Bad socket"); + if (bind(ctl_sockt, + (struct sockaddr *)&ctl_addr, sizeof(ctl_addr)) != 0) + p_error("Couldn't bind to control socket"); + length = sizeof(ctl_addr); + if (getsockname(ctl_sockt, + (struct sockaddr *)&ctl_addr, &length) == -1) + p_error("Bad address for ctl socket"); +} + +/* print_addr is a debug print routine */ +void +print_addr(addr) + struct sockaddr_in addr; +{ + int i; + + printf("addr = %lx, port = %o, family = %o zero = ", + (u_long)addr.sin_addr.s_addr, addr.sin_port, addr.sin_family); + for (i = 0; i<8;i++) + printf("%o ", (int)addr.sin_zero[i]); + putchar('\n'); +} diff --git a/remote_cmds/talk.tproj/ctl_transact.c b/remote_cmds/talk.tproj/ctl_transact.c new file mode 100644 index 0000000..1679250 --- /dev/null +++ b/remote_cmds/talk.tproj/ctl_transact.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +#ifdef __APPLE__ +#include <sys/time.h> +#endif + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/ctl_transact.c,v 1.7 2002/02/18 20:35:26 mike Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)ctl_transact.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +#include <arpa/inet.h> + +#include <errno.h> +#include <string.h> + +#include "talk.h" +#include "talk_ctl.h" + +#define CTL_WAIT 2 /* time to wait for a response, in seconds */ + +/* + * SOCKDGRAM is unreliable, so we must repeat messages if we have + * not recieved an acknowledgement within a reasonable amount + * of time + */ +void +ctl_transact(target, lmsg, type, rp) + struct in_addr target; + CTL_MSG lmsg; + int type; + CTL_RESPONSE *rp; +{ + fd_set read_mask, ctl_mask; + int nready = 0, cc; + struct timeval wait; + + lmsg.type = type; + daemon_addr.sin_addr = target; + daemon_addr.sin_port = daemon_port; + FD_ZERO(&ctl_mask); + FD_SET(ctl_sockt, &ctl_mask); + + /* + * Keep sending the message until a response of + * the proper type is obtained. + */ + do { + wait.tv_sec = CTL_WAIT; + wait.tv_usec = 0; + /* resend message until a response is obtained */ + do { + cc = sendto(ctl_sockt, (char *)&lmsg, sizeof (lmsg), 0, + (struct sockaddr *)&daemon_addr, + sizeof (daemon_addr)); + if (cc != sizeof (lmsg)) { + if (errno == EINTR) + continue; + p_error("Error on write to talk daemon"); + } + read_mask = ctl_mask; + nready = select(ctl_sockt + 1, &read_mask, 0, 0, &wait); + if (nready < 0) { + if (errno == EINTR) + continue; + p_error("Error waiting for daemon response"); + } + } while (nready == 0); + /* + * Keep reading while there are queued messages + * (this is not necessary, it just saves extra + * request/acknowledgements being sent) + */ + do { + cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0); + if (cc < 0) { + if (errno == EINTR) + continue; + p_error("Error on read from talk daemon"); + } + read_mask = ctl_mask; + /* an immediate poll */ + timerclear(&wait); + nready = select(ctl_sockt + 1, &read_mask, 0, 0, &wait); + } while (nready > 0 && (rp->vers != TALK_VERSION || + rp->type != type)); + } while (rp->vers != TALK_VERSION || rp->type != type); + rp->id_num = ntohl(rp->id_num); + rp->addr.sa_family = ntohs(rp->addr.sa_family); +} diff --git a/remote_cmds/talk.tproj/display.c b/remote_cmds/talk.tproj/display.c new file mode 100644 index 0000000..2815ec1 --- /dev/null +++ b/remote_cmds/talk.tproj/display.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/display.c,v 1.11 2003/07/04 20:44:25 luigi Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +/* + * The window 'manager', initializes curses and handles the actual + * displaying of text + */ +#include <ctype.h> + +#include "talk.h" + +xwin_t my_win; +xwin_t his_win; +WINDOW *line_win; + +int curses_initialized = 0; + +/* + * max HAS to be a function, it is called with + * an argument of the form --foo at least once. + */ +int +max(a,b) + int a, b; +{ + + return (a > b ? a : b); +} + +/* + * Display some text on somebody's window, processing some control + * characters while we are at it. + */ +void +display(win, text, size) + xwin_t *win; + char *text; + int size; +{ + int i; + char cch; + + for (i = 0; i < size; i++) { + if (*text == '\n' || *text == '\r') { + waddch(win->x_win, '\n'); + getyx(win->x_win, win->x_line, win->x_col); + text++; + continue; + } + if (*text == 004 && win == &my_win) { + /* control-D clears the screen */ + werase(my_win.x_win); + getyx(my_win.x_win, my_win.x_line, my_win.x_col); + wrefresh(my_win.x_win); + werase(his_win.x_win); + getyx(his_win.x_win, his_win.x_line, his_win.x_col); + wrefresh(his_win.x_win); + text++; + continue; + } + + /* erase character */ + if ( *text == win->cerase + || *text == 010 /* BS */ + || *text == 0177 /* DEL */ + ) { + wmove(win->x_win, win->x_line, max(--win->x_col, 0)); + getyx(win->x_win, win->x_line, win->x_col); + waddch(win->x_win, ' '); + wmove(win->x_win, win->x_line, win->x_col); + getyx(win->x_win, win->x_line, win->x_col); + text++; + continue; + } + /* + * On word erase search backwards until we find + * the beginning of a word or the beginning of + * the line. + */ + if ( *text == win->werase + || *text == 027 /* ^W */ + ) { + int endcol, xcol, ii, c; + + endcol = win->x_col; + xcol = endcol - 1; + while (xcol >= 0) { + c = readwin(win->x_win, win->x_line, xcol); + if (c != ' ') + break; + xcol--; + } + while (xcol >= 0) { + c = readwin(win->x_win, win->x_line, xcol); + if (c == ' ') + break; + xcol--; + } + wmove(win->x_win, win->x_line, xcol + 1); + for (ii = xcol + 1; ii < endcol; ii++) + waddch(win->x_win, ' '); + wmove(win->x_win, win->x_line, xcol + 1); + getyx(win->x_win, win->x_line, win->x_col); + text++; + continue; + } + /* line kill */ + if ( *text == win->kill + || *text == 025 /* ^U */ + ) { + wmove(win->x_win, win->x_line, 0); + wclrtoeol(win->x_win); + getyx(win->x_win, win->x_line, win->x_col); + text++; + continue; + } + if (*text == '\f') { + if (win == &my_win) + wrefresh(curscr); + text++; + continue; + } + if (*text == '\7') { + write(STDOUT_FILENO, text, 1); + text++; + continue; + } + if (!isprint((unsigned char)*text) && *text != '\t') { + waddch(win->x_win, '^'); + getyx(win->x_win, win->x_line, win->x_col); + cch = (*text & 63) + 64; + waddch(win->x_win, cch); + } else + waddch(win->x_win, (unsigned char)*text); + getyx(win->x_win, win->x_line, win->x_col); + text++; + } + wrefresh(win->x_win); +} + +/* + * Read the character at the indicated position in win + */ +int +readwin(win, line, col) + WINDOW *win; + int line; + int col; +{ + int oldline, oldcol; + int c; + + getyx(win, oldline, oldcol); + wmove(win, line, col); + c = winch(win); + wmove(win, oldline, oldcol); + return (c); +} diff --git a/remote_cmds/talk.tproj/get_addrs.c b/remote_cmds/talk.tproj/get_addrs.c new file mode 100644 index 0000000..e5a71ac --- /dev/null +++ b/remote_cmds/talk.tproj/get_addrs.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/get_addrs.c,v 1.5 2001/12/11 23:51:14 markm Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)get_addrs.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +#include <err.h> +#include <netdb.h> +#include <string.h> + +#include "talk.h" +#include "talk_ctl.h" + +void +get_addrs(my_machine_name, his_machine_name) + char *my_machine_name __unused, *his_machine_name; +{ + struct hostent *hp; + struct servent *sp; + + msg.pid = htonl(getpid()); + + hp = gethostbyname(his_machine_name); + if (hp == NULL) + errx(1, "%s: %s", his_machine_name, hstrerror(h_errno)); + bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length); + if (get_iface(&his_machine_addr, &my_machine_addr) == -1) + err(1, "failed to find my interface address"); + /* find the server's port */ + sp = getservbyname("ntalk", "udp"); + if (sp == 0) + errx(1, "ntalk/udp: service is not registered"); + daemon_port = sp->s_port; +} diff --git a/remote_cmds/talk.tproj/get_iface.c b/remote_cmds/talk.tproj/get_iface.c new file mode 100644 index 0000000..79b7d30 --- /dev/null +++ b/remote_cmds/talk.tproj/get_iface.c @@ -0,0 +1,103 @@ +/* + * Copyright 1994, 1995 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/get_iface.c,v 1.10 2005/03/11 14:17:12 stefanf Exp $"); +#endif + +/* + * From: + * Id: find_interface.c,v 1.1 1995/08/14 16:08:39 wollman Exp + */ + +#include <errno.h> +#include <string.h> + +#include "talk.h" + +/* + * Try to find the interface address that is used to route an IP + * packet to a remote peer. + */ + +int +get_iface(dst, iface) + struct in_addr *dst; + struct in_addr *iface; +{ + static struct sockaddr_in local; + struct sockaddr_in remote; + socklen_t namelen; + int s, rv; + + memcpy(&remote.sin_addr, dst, sizeof remote.sin_addr); + remote.sin_port = htons(60000); + remote.sin_family = AF_INET; + remote.sin_len = sizeof remote; + + local.sin_addr.s_addr = htonl(INADDR_ANY); + local.sin_port = htons(60000); + local.sin_family = AF_INET; + local.sin_len = sizeof local; + + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s < 0) + return -1; + + do { + rv = bind(s, (struct sockaddr *)&local, sizeof local); + local.sin_port = htons(ntohs(local.sin_port) + 1); + } while(rv < 0 && errno == EADDRINUSE); + + if (rv < 0) { + close(s); + return -1; + } + + do { + rv = connect(s, (struct sockaddr *)&remote, sizeof remote); + remote.sin_port = htons(ntohs(remote.sin_port) + 1); + } while(rv < 0 && errno == EADDRINUSE); + + if (rv < 0) { + close(s); + return -1; + } + + namelen = sizeof local; + rv = getsockname(s, (struct sockaddr *)&local, &namelen); + close(s); + if (rv < 0) + return -1; + + memcpy(iface, &local.sin_addr, sizeof local.sin_addr); + return 0; +} diff --git a/remote_cmds/talk.tproj/get_names.c b/remote_cmds/talk.tproj/get_names.c new file mode 100644 index 0000000..24acab1 --- /dev/null +++ b/remote_cmds/talk.tproj/get_names.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/get_names.c,v 1.9 2004/06/14 22:34:13 bms Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)get_names.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +#include <sys/param.h> + +#include <err.h> +#include <pwd.h> +#include <stdlib.h> +#include <string.h> + +#include "talk.h" + +extern CTL_MSG msg; + +static void +usage(void) +{ + fprintf(stderr, "usage: talk person [ttyname]\n"); + exit(1); +} + +/* + * Determine the local and remote user, tty, and machines + */ +void +get_names(argc, argv) + int argc; + char *argv[]; +{ + char hostname[MAXHOSTNAMELEN]; + char *his_name, *my_name; + char *my_machine_name, *his_machine_name; + const char *his_tty; + char *cp; + + if (argc < 2 ) + usage(); + if (!isatty(0)) + errx(1, "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) + errx(1, "you don't exist. Go away"); + my_name = pw->pw_name; + } + gethostname(hostname, sizeof (hostname)); + my_machine_name = hostname; + /* check for, and strip out, the machine name of the target */ + for (cp = argv[1]; *cp && !index("@:!", *cp); cp++) + ; + if (*cp == '\0') { + /* this is a local to local talk */ + his_name = argv[1]; + my_machine_name = his_machine_name = "localhost"; + } else { + if (*cp++ == '@') { + /* user@host */ + his_name = argv[1]; + his_machine_name = cp; + } else { + /* host!user or host:user */ + his_name = cp; + his_machine_name = argv[1]; + } + *--cp = '\0'; + } + if (argc > 2) + his_tty = argv[2]; /* tty name is arg 2 */ + else + his_tty = ""; + get_addrs(my_machine_name, his_machine_name); + /* + * Initialize the message template. + */ + msg.vers = TALK_VERSION; + msg.addr.sa_family = htons(AF_INET); + msg.ctl_addr.sa_family = htons(AF_INET); + msg.id_num = htonl(0); + strncpy(msg.l_name, my_name, NAME_SIZE); + msg.l_name[NAME_SIZE - 1] = '\0'; + strncpy(msg.r_name, his_name, NAME_SIZE); + msg.r_name[NAME_SIZE - 1] = '\0'; + strncpy(msg.r_tty, his_tty, TTY_SIZE); + msg.r_tty[TTY_SIZE - 1] = '\0'; +} diff --git a/remote_cmds/talk.tproj/init_disp.c b/remote_cmds/talk.tproj/init_disp.c new file mode 100644 index 0000000..c6a02ef --- /dev/null +++ b/remote_cmds/talk.tproj/init_disp.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/init_disp.c,v 1.14 2004/04/19 21:37:28 cognet Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94"; +#endif +#endif /* __APPLE__ */ + +/* + * Initialization code for the display package, + * as well as the signal handling routines. + */ + +#include <sys/stat.h> +#ifdef __APPLE__ +#include <sys/ioctl.h> +#endif + +#include <err.h> +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> +#include <termios.h> + +#include "talk.h" + +extern volatile sig_atomic_t gotwinch; + +/* + * Make sure the callee can write to the screen + */ +void +check_writeable() +{ + char *tty; + struct stat sb; + + if ((tty = ttyname(STDERR_FILENO)) == NULL) + err(1, "ttyname"); + if (stat(tty, &sb) < 0) + err(1, "%s", tty); + if (!(sb.st_mode & S_IWGRP)) + errx(1, "The callee cannot write to this terminal, use \"mesg y\"."); +} + +/* + * Set up curses, catch the appropriate signals, + * and build the various windows. + */ +void +init_display() +{ + struct sigaction sa; + + if (initscr() == NULL) + errx(1, "Terminal type unset or lacking necessary features."); + (void) sigaction(SIGTSTP, (struct sigaction *)0, &sa); + sigaddset(&sa.sa_mask, SIGALRM); + (void) sigaction(SIGTSTP, &sa, (struct sigaction *)0); + curses_initialized = 1; + clear(); + refresh(); + noecho(); + crmode(); + signal(SIGINT, sig_sent); + signal(SIGPIPE, sig_sent); + signal(SIGWINCH, sig_winch); + /* curses takes care of ^Z */ + my_win.x_nlines = LINES / 2; + my_win.x_ncols = COLS; + my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); + idlok(my_win.x_win, TRUE); + scrollok(my_win.x_win, TRUE); + wclear(my_win.x_win); + + his_win.x_nlines = LINES / 2 - 1; + his_win.x_ncols = COLS; + his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols, + my_win.x_nlines+1, 0); + idlok(my_win.x_win, TRUE); + scrollok(his_win.x_win, TRUE); + wclear(his_win.x_win); + + line_win = newwin(1, COLS, my_win.x_nlines, 0); +#if defined(hline) || defined(whline) || defined(NCURSES_VERSION) + whline(line_win, 0, COLS); +#else + box(line_win, '-', '-'); +#endif + wrefresh(line_win); + /* let them know we are working on it */ + current_state = "No connection yet"; +} + +/* + * Trade edit characters with the other talk. By agreement + * the first three characters each talk transmits after + * connection are the three edit characters. + */ +void +set_edit_chars() +{ + char buf[3]; + int cc; + struct termios tio; + + tcgetattr(0, &tio); + my_win.cerase = tio.c_cc[VERASE]; + my_win.kill = tio.c_cc[VKILL]; + my_win.werase = tio.c_cc[VWERASE]; + if (my_win.cerase == (char)_POSIX_VDISABLE) + my_win.kill = CERASE; + if (my_win.kill == (char)_POSIX_VDISABLE) + my_win.kill = CKILL; + if (my_win.werase == (char)_POSIX_VDISABLE) + my_win.werase = CWERASE; + buf[0] = my_win.cerase; + buf[1] = my_win.kill; + buf[2] = my_win.werase; + cc = write(sockt, buf, sizeof(buf)); + if (cc != sizeof(buf) ) + p_error("Lost the connection"); + cc = read(sockt, buf, sizeof(buf)); + if (cc != sizeof(buf) ) + p_error("Lost the connection"); + his_win.cerase = buf[0]; + his_win.kill = buf[1]; + his_win.werase = buf[2]; +} + +/* ARGSUSED */ +void +sig_sent(signo) + int signo __unused; +{ + + message("Connection closing. Exiting"); + quit(); +} + +void +sig_winch(int dummy) +{ + + gotwinch = 1; +} + +/* + * All done talking...hang up the phone and reset terminal thingy's + */ +void +quit() +{ + + if (curses_initialized) { + wmove(his_win.x_win, his_win.x_nlines-1, 0); + wclrtoeol(his_win.x_win); + wrefresh(his_win.x_win); + endwin(); + } + if (invitation_waiting) + send_delete(); + exit(0); +} + +/* + * If we get SIGWINCH, recompute both window sizes and refresh things. + */ +void +resize_display(void) +{ + struct winsize ws; + + if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) < 0 || + (ws.ws_row == LINES && ws.ws_col == COLS)) + return; + + /* Update curses' internal state with new window size. */ + resizeterm(ws.ws_row, ws.ws_col); + + /* + * Resize each window but wait to refresh the screen until + * everything has been drawn so the cursor is in the right spot. + */ + my_win.x_nlines = LINES / 2; + my_win.x_ncols = COLS; + wresize(my_win.x_win, my_win.x_nlines, my_win.x_ncols); + mvwin(my_win.x_win, 0, 0); + clearok(my_win.x_win, TRUE); + + his_win.x_nlines = LINES / 2 - 1; + his_win.x_ncols = COLS; + wresize(his_win.x_win, his_win.x_nlines, his_win.x_ncols); + mvwin(his_win.x_win, my_win.x_nlines + 1, 0); + clearok(his_win.x_win, TRUE); + + wresize(line_win, 1, COLS); + mvwin(line_win, my_win.x_nlines, 0); +#if defined(NCURSES_VERSION) || defined(whline) + whline(line_win, '-', COLS); +#else + wmove(line_win, my_win.x_nlines, 0); + box(line_win, '-', '-'); +#endif + + /* Now redraw the screen. */ + wrefresh(his_win.x_win); + wrefresh(line_win); + wrefresh(my_win.x_win); +} diff --git a/remote_cmds/talk.tproj/invite.c b/remote_cmds/talk.tproj/invite.c new file mode 100644 index 0000000..b8562b2 --- /dev/null +++ b/remote_cmds/talk.tproj/invite.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/invite.c,v 1.9 2003/01/01 18:49:00 schweikh Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)invite.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <protocols/talkd.h> + +#include <err.h> +#include <errno.h> +#include <setjmp.h> +#include <signal.h> + +#include "talk_ctl.h" +#include "talk.h" + +/* + * There wasn't an invitation waiting, so send a request containing + * our sockt address to the remote talk daemon so it can invite + * him + */ + +/* + * The msg.id's for the invitations + * on the local and remote machines. + * These are used to delete the + * invitations. + */ +int local_id, remote_id; +jmp_buf invitebuf; + +void +invite_remote() +{ + int new_sockt; + struct itimerval itimer; + CTL_RESPONSE response; + + itimer.it_value.tv_sec = RING_WAIT; + itimer.it_value.tv_usec = 0; + itimer.it_interval = itimer.it_value; + if (listen(sockt, 5) != 0) + p_error("Error on attempt to listen for caller"); +#ifdef MSG_EOR + /* copy new style sockaddr to old, swap family (short in old) */ + msg.addr = *(struct osockaddr *)&my_addr; /* XXX new to old style*/ + msg.addr.sa_family = htons(my_addr.sin_family); +#else + msg.addr = *(struct sockaddr *)&my_addr; +#endif + msg.id_num = htonl(-1); /* an impossible id_num */ + invitation_waiting = 1; + announce_invite(); + /* + * Shut off the automatic messages for a while, + * so we can use the interupt timer to resend the invitation + */ + end_msgs(); + setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); + message("Waiting for your party to respond"); + signal(SIGALRM, re_invite); + (void) setjmp(invitebuf); + while ((new_sockt = accept(sockt, 0, 0)) < 0) { + if (errno == EINTR) + continue; + p_error("Unable to connect with your party"); + } + close(sockt); + sockt = new_sockt; + + /* + * Have the daemons delete the invitations now that we + * have connected. + */ + current_state = "Waiting for your party to respond"; + start_msgs(); + + msg.id_num = htonl(local_id); + ctl_transact(my_machine_addr, msg, DELETE, &response); + msg.id_num = htonl(remote_id); + ctl_transact(his_machine_addr, msg, DELETE, &response); + invitation_waiting = 0; +} + +/* + * Routine called on interupt to re-invite the callee + */ +/* ARGSUSED */ +void +re_invite(signo) + int signo __unused; +{ + + message("Ringing your party again"); + waddch(my_win.x_win, '\n'); + if (current_line < my_win.x_nlines - 1) + current_line++; + /* force a re-announce */ + msg.id_num = htonl(remote_id + 1); + announce_invite(); + longjmp(invitebuf, 1); +} + +static const char *answers[] = { + "answer #0", /* SUCCESS */ + "Your party is not logged on", /* NOT_HERE */ + "Target machine is too confused to talk to us", /* FAILED */ + "Target machine does not recognize us", /* MACHINE_UNKNOWN */ + "Your party is refusing messages", /* PERMISSION_REFUSED */ + "Target machine can not handle remote talk", /* UNKNOWN_REQUEST */ + "Target machine indicates protocol mismatch", /* BADVERSION */ + "Target machine indicates protocol botch (addr)",/* BADADDR */ + "Target machine indicates protocol botch (ctl_addr)",/* BADCTLADDR */ +}; +#define NANSWERS (sizeof (answers) / sizeof (answers[0])) + +/* + * Transmit the invitation and process the response + */ +void +announce_invite() +{ + CTL_RESPONSE response; + + current_state = "Trying to connect to your party's talk daemon"; + ctl_transact(his_machine_addr, msg, ANNOUNCE, &response); + remote_id = response.id_num; + if (response.answer != SUCCESS) { + if (response.answer < NANSWERS) + message(answers[response.answer]); + quit(); + } + /* leave the actual invitation on my talk daemon */ + current_state = "Trying to connect to local talk daemon"; + ctl_transact(my_machine_addr, msg, LEAVE_INVITE, &response); + local_id = response.id_num; +} + +/* + * Tell the daemon to remove your invitation + */ +void +send_delete() +{ + + msg.type = DELETE; + /* + * This is just an extra clean up, so just send it + * and don't wait for an answer + */ + msg.id_num = htonl(remote_id); + daemon_addr.sin_addr = his_machine_addr; + if (sendto(ctl_sockt, &msg, sizeof (msg), 0, + (struct sockaddr *)&daemon_addr, + sizeof (daemon_addr)) != sizeof(msg)) + 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)) + warn("send_delete (local)"); +} diff --git a/remote_cmds/talk.tproj/io.c b/remote_cmds/talk.tproj/io.c new file mode 100644 index 0000000..644c28b --- /dev/null +++ b/remote_cmds/talk.tproj/io.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/io.c,v 1.16 2004/05/10 15:52:16 cognet Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +/* + * This file contains the I/O handling and the exchange of + * edit characters. This connection itself is established in + * ctl.c + */ + +#include <sys/filio.h> +#ifdef __APPLE__ +#include <sys/ioctl.h> +#endif + +#include <errno.h> +#include <signal.h> +#include <netdb.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "talk.h" +#include "talk_ctl.h" + +#define A_LONG_TIME 10000000 + +volatile sig_atomic_t gotwinch = 0; + +/* + * The routine to do the actual talking + */ +void +talk() +{ + struct hostent *hp, *hp2; + int nb; + fd_set read_set, read_template; + char buf[BUFSIZ], **addr, *his_machine_name; + struct timeval wait; + + 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; + + /* + * Wait on both the other process (sockt_mask) and + * standard input ( STDIN_MASK ) + */ + FD_ZERO(&read_template); + FD_SET(sockt, &read_template); + FD_SET(fileno(stdin), &read_template); + for (;;) { + read_set = read_template; + wait.tv_sec = A_LONG_TIME; + wait.tv_usec = 0; + nb = select(sockt + 1, &read_set, 0, 0, &wait); + if (gotwinch) { + resize_display(); + gotwinch = 0; + } + if (nb <= 0) { + if (errno == EINTR) { + read_set = read_template; + continue; + } + /* panic, we don't know what happened */ + p_error("Unexpected error from select"); + quit(); + } + if (FD_ISSET(sockt, &read_set)) { + /* There is data on sockt */ + nb = read(sockt, buf, sizeof buf); + if (nb <= 0) { + message("Connection closed. Exiting"); + quit(); + } + display(&his_win, buf, nb); + } + if (FD_ISSET(fileno(stdin), &read_set)) { + /* + * We can't make the tty non_blocking, because + * curses's output routines would screw up + */ + int i; + ioctl(0, FIONREAD, (void *) &nb); + if (nb > sizeof buf) + nb = sizeof buf; + nb = read(STDIN_FILENO, buf, nb); + display(&my_win, buf, nb); + /* might lose data here because sockt is non-blocking */ + for (i = 0; i < nb; ++i) + if (buf[i] == '\r') + buf[i] = '\n'; + write(sockt, buf, nb); + } + } +} + +/* + * p_error prints the system error message on the standard location + * on the screen and then exits. (i.e. a curses version of perror) + */ +void +p_error(string) + const char *string; +{ + wmove(my_win.x_win, current_line, 0); + wprintw(my_win.x_win, "[%s : %s (%d)]\n", + string, strerror(errno), errno); + wrefresh(my_win.x_win); + move(LINES-1, 0); + refresh(); + quit(); +} + +/* + * Display string in the standard location + */ +void +message(string) + const char *string; +{ + wmove(my_win.x_win, current_line, 0); + wprintw(my_win.x_win, "[%s]\n", string); + if (current_line < my_win.x_nlines - 1) + current_line++; + wrefresh(my_win.x_win); +} diff --git a/remote_cmds/talk.tproj/look_up.c b/remote_cmds/talk.tproj/look_up.c new file mode 100644 index 0000000..3fd003f --- /dev/null +++ b/remote_cmds/talk.tproj/look_up.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/look_up.c,v 1.8 2005/02/09 09:13:36 stefanf Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)look_up.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <protocols/talkd.h> + +#include <errno.h> +#include <string.h> + +#include "talk_ctl.h" +#include "talk.h" + +/* + * See if the local daemon has an invitation for us. + */ +int +check_local() +{ + CTL_RESPONSE response; + CTL_RESPONSE *rp = &response; + struct sockaddr addr; + + /* the rest of msg was set up in get_names */ +#ifdef MSG_EOR + /* copy new style sockaddr to old, swap family (short in old) */ + msg.ctl_addr = *(struct osockaddr *)&ctl_addr; + msg.ctl_addr.sa_family = htons(ctl_addr.sin_family); +#else + msg.ctl_addr = *(struct sockaddr *)&ctl_addr; +#endif + /* must be initiating a talk */ + if (!look_for_invite(rp)) + return (0); + /* + * There was an invitation waiting for us, + * so connect with the other (hopefully waiting) party + */ + current_state = "Waiting to connect with caller"; + do { + if (rp->addr.sa_family != AF_INET) + p_error("Response uses invalid network address"); + (void)memcpy(&addr, &rp->addr.sa_family, sizeof(addr)); + addr.sa_family = rp->addr.sa_family; + addr.sa_len = sizeof(addr); + errno = 0; + if (connect(sockt, &addr, sizeof(addr)) != -1) + return (1); + } while (errno == EINTR); + if (errno == ECONNREFUSED) { + /* + * The caller gave up, but his invitation somehow + * was not cleared. Clear it and initiate an + * invitation. (We know there are no newer invitations, + * the talkd works LIFO.) + */ + ctl_transact(his_machine_addr, msg, DELETE, rp); + close(sockt); + open_sockt(); + return (0); + } + p_error("Unable to connect with initiator"); + /*NOTREACHED*/ + return (0); +} + +/* + * Look for an invitation on 'machine' + */ +int +look_for_invite(rp) + CTL_RESPONSE *rp; +{ + current_state = "Checking for invitation on caller's machine"; + ctl_transact(his_machine_addr, msg, LOOK_UP, rp); + /* the switch is for later options, such as multiple invitations */ + switch (rp->answer) { + + case SUCCESS: + msg.id_num = htonl(rp->id_num); + return (1); + + default: + /* there wasn't an invitation waiting for us */ + return (0); + } +} diff --git a/remote_cmds/talk.tproj/msgs.c b/remote_cmds/talk.tproj/msgs.c new file mode 100644 index 0000000..f8cb59a --- /dev/null +++ b/remote_cmds/talk.tproj/msgs.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/msgs.c,v 1.6 2001/12/11 23:51:14 markm Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)msgs.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +/* + * A package to display what is happening every MSG_INTERVAL seconds + * if we are slow connecting. + */ + +#include <signal.h> + +#include "talk.h" + +#define MSG_INTERVAL 4 + +const char *current_state; +int current_line = 0; + +/* ARGSUSED */ +void +disp_msg(signo) + int signo __unused; +{ + message(current_state); +} + +void +start_msgs() +{ + struct itimerval itimer; + + message(current_state); + signal(SIGALRM, disp_msg); + itimer.it_value.tv_sec = itimer.it_interval.tv_sec = MSG_INTERVAL; + itimer.it_value.tv_usec = itimer.it_interval.tv_usec = 0; + setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); +} + +void +end_msgs() +{ + struct itimerval itimer; + + timerclear(&itimer.it_value); + timerclear(&itimer.it_interval); + setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); + signal(SIGALRM, SIG_DFL); +} diff --git a/remote_cmds/talk.tproj/talk.1 b/remote_cmds/talk.tproj/talk.1 new file mode 100644 index 0000000..bf105bb --- /dev/null +++ b/remote_cmds/talk.tproj/talk.1 @@ -0,0 +1,172 @@ +.\" Copyright (c) 1983, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)talk.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/talk/talk.1,v 1.20 2005/02/13 22:25:24 ru Exp $ +.\" +.Dd August 21, 2008 +.Dt TALK 1 +.Os +.Sh NAME +.Nm talk +.Nd talk to another user +.Sh SYNOPSIS +.Nm +.Ar person +.Op Ar ttyname +.Sh DESCRIPTION +The +.Nm +utility is a visual communication program which copies lines from your +terminal to that of another user. +.Pp +Options available: +.Bl -tag -width ttyname +.It Ar person +If you wish to talk to someone on your own machine, then +.Ar person +is just the person's login name. +If you wish to talk to a user on +another host, then +.Ar person +is of the form +.Ql user@host +or +.Ql host!user +or +.Ql host:user . +.It Ar ttyname +If you wish to talk to a user who is logged in more than once, the +.Ar ttyname +argument may be used to indicate the appropriate terminal +name, where +.Ar ttyname +is of the form +.Ql ttyXX . +.El +.Pp +When first called, +.Nm +sends the message +.Bd -literal -offset indent -compact +Message from TalkDaemon@his_machine... +talk: connection requested by your_name@your_machine. +talk: respond with: talk your_name@your_machine +.Ed +.Pp +to the user you wish to talk to. +At this point, the recipient +of the message should reply by typing +.Pp +.Dl talk \ your_name@your_machine +.Pp +It does not matter from which machine the recipient replies, as +long as his login-name is the same. +Once communication is established, +the two parties may type simultaneously, with their output appearing +in separate windows. +Typing control-L +.Ql ^L +will cause the screen to +be reprinted. +Typing control-D +.Ql ^D +will clear both parts of your screen to be cleared, while +the control-D character will be sent to the remote side +(and just displayed by this +.Nm +client). +Your erase, kill, and word kill characters will +behave normally. +To exit, just type your interrupt character; +.Nm +then moves the cursor to the bottom of the screen and restores the +terminal to its previous state. +.Pp +Permission to talk may be denied or granted by use of the +.Xr mesg 1 +command. +At the outset talking is allowed. +.Sh CONFIGURATION +The +.Nm +utility relies on the +.Nm talkd +system daemon. See +.Xr talkd 8 +for information about enabling +.Nm talkd . +.Sh FILES +.Bl -tag -width /var/run/utmpx -compact +.It Pa /etc/hosts +to find the recipient's machine +.It Pa /var/run/utmpx +to find the recipient's tty +.El +.Sh SEE ALSO +.Xr mail 1 , +.Xr mesg 1 , +.Xr wall 1 , +.Xr who 1 , +.Xr write 1 , +.Xr talkd 8 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.2 . +.Pp +In +.Fx 5.3 , +the default behaviour of +.Nm +was changed to treat local-to-local talk requests as originating +and terminating at +.Em localhost . +Before this change, it was required that the hostname (as per +.Xr gethostname 3 ) +resolved to a valid IPv4 address (via +.Xr gethostbyname 3 ) , +making +.Nm +unsuitable for use in configurations where +.Xr talkd 8 +was bound to the loopback interface (normally for security reasons). +.Sh BUGS +The version of +.Nm +released with +.Bx 4.3 +uses a protocol that +is incompatible with the protocol used in the version released with +.Bx 4.2 . +.Pp +Multibyte characters are not recognized. diff --git a/remote_cmds/talk.tproj/talk.c b/remote_cmds/talk.tproj/talk.c new file mode 100644 index 0000000..d86e770 --- /dev/null +++ b/remote_cmds/talk.tproj/talk.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#ifndef __APPLE__ +__FBSDID("$FreeBSD: src/usr.bin/talk/talk.c,v 1.11 2002/08/19 03:07:56 jmallett Exp $"); + +#ifndef lint +static const char sccsid[] = "@(#)talk.c 8.1 (Berkeley) 6/6/93"; +#endif +#endif /* __APPLE__ */ + +#ifndef lint +__attribute__((__used__)) +static const char copyright[] = +"@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif + +#include <locale.h> + +#include "talk.h" + +/* + * talk: A visual form of write. Using sockets, a two way + * connection is set up between the two people talking. + * With the aid of curses, the screen is split into two + * windows, and each users text is added to the window, + * one character at a time... + * + * Written by Kipp Hickman + * + * Modified to run under 4.1a by Clem Cole and Peter Moore + * Modified to run between hosts by Peter Moore, 8/19/82 + * Modified to run under 4.1c by Peter Moore 3/17/83 + * Fixed to not run with unwriteable terminals MRVM 28/12/94 + */ + +int +main(argc, argv) + int argc; + char *argv[]; +{ + (void) setlocale(LC_CTYPE, ""); + + get_names(argc, argv); +#ifndef __APPLE__ + setproctitle(""); +#endif + check_writeable(); + init_display(); + open_ctl(); + open_sockt(); + start_msgs(); + if (!check_local()) + invite_remote(); + end_msgs(); + set_edit_chars(); + talk(); + return 0; +} diff --git a/remote_cmds/talk.tproj/talk.h b/remote_cmds/talk.tproj/talk.h new file mode 100644 index 0000000..7f3bcf4 --- /dev/null +++ b/remote_cmds/talk.tproj/talk.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)talk.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD: src/usr.bin/talk/talk.h,v 1.5 2004/04/19 21:37:29 cognet Exp $ + */ + +#include <sys/cdefs.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <protocols/talkd.h> +#include <curses.h> +#include <unistd.h> + +extern int sockt; +extern int curses_initialized; +extern int invitation_waiting; + +extern const char *current_state; +extern int current_line; + +typedef struct xwin { + WINDOW *x_win; + int x_nlines; + int x_ncols; + int x_line; + int x_col; + char kill; + char cerase; + char werase; +} xwin_t; + +extern xwin_t my_win; +extern xwin_t his_win; +extern WINDOW *line_win; + +extern void announce_invite(void); +extern int check_local(void); +extern void check_writeable(void); +extern void ctl_transact(struct in_addr,CTL_MSG,int,CTL_RESPONSE *); +extern void disp_msg(int); +extern void display(xwin_t *, char *, int); +extern void end_msgs(void); +extern void get_addrs(char *, char *); +extern int get_iface(struct in_addr *, struct in_addr *); +extern void get_names(int, char **); +extern void init_display(void); +extern void invite_remote(void); +extern int look_for_invite(CTL_RESPONSE *); +extern int max(int, int); +extern void message(const char *); +extern void open_ctl(void); +extern void open_sockt(void); +extern void p_error(const char *); +extern void print_addr(struct sockaddr_in); +extern void quit(void); +extern int readwin(WINDOW *, int, int); +extern void re_invite(int); +extern void send_delete(void); +extern void set_edit_chars(void); +extern void sig_sent(int); +extern void sig_winch(int); +extern void start_msgs(void); +extern void talk(void); +extern void resize_display(void); diff --git a/remote_cmds/talk.tproj/talk_ctl.h b/remote_cmds/talk.tproj/talk_ctl.h new file mode 100644 index 0000000..91c75d0 --- /dev/null +++ b/remote_cmds/talk.tproj/talk_ctl.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)talk_ctl.h 8.1 (Berkeley) 6/6/93 + */ + +extern struct sockaddr_in daemon_addr; +extern struct sockaddr_in ctl_addr; +extern struct sockaddr_in my_addr; +extern struct in_addr my_machine_addr; +extern struct in_addr his_machine_addr; +extern u_short daemon_port; +extern int ctl_sockt; +extern CTL_MSG msg; |