|
|
1.1 root 1: /* $Header: get_names.c 1.2 83/03/26 14:35:54 moore Exp $ */
2:
3: #include "talk.h"
4: #include "ctl.h"
5:
6: char *getlogin(), *ttyname(), *rindex();
7:
8: extern CTL_MSG msg;
9:
10: /*
11: * Determine the local and remote user, tty, and machines
12: */
13:
14: struct hostent *gethostbyname();
15:
16: get_names(argc, argv)
17: int argc;
18: char *argv[];
19: {
20: char hostname[HOST_NAME_LENGTH];
21: char *his_name;
22: char *my_name;
23: char *my_machine_name;
24: char *his_machine_name;
25: char *my_tty;
26: char *his_tty;
27: char *ptr;
28: int name_length;
29:
30: if (argc < 2 ) {
31: printf("Usage: talk user [ttyname]\n");
32: exit(-1);
33: }
34: if ( !isatty(0) ) {
35: printf("Standard input must be a tty, not a pipe or a file\n");
36: exit(-1);
37: }
38:
39: my_name = getlogin();
40: if (my_name == NULL) {
41: printf("You don't exist. Go away.\n");
42: exit(-1);
43: }
44:
45: name_length = HOST_NAME_LENGTH;
46: gethostname(hostname, &name_length);
47: my_machine_name = hostname;
48:
49: my_tty = rindex(ttyname(0), '/') + 1;
50:
51: /* check for, and strip out, the machine name
52: of the target */
53:
54: for (ptr = argv[1]; *ptr != '\0' &&
55: *ptr != '@' &&
56: *ptr != ':' &&
57: *ptr != '!' &&
58: *ptr != '.' ; ptr++) {
59: }
60:
61: if (*ptr == '\0') {
62:
63: /* this is a local to local talk */
64:
65: his_name = argv[1];
66: his_machine_name = my_machine_name;
67:
68: } else {
69:
70: if (*ptr == '@') {
71: /* user@host */
72: his_name = argv[1];
73: his_machine_name = ptr + 1;
74: } else {
75: /* host.user or host!user or host:user */
76: his_name = ptr + 1;
77: his_machine_name = argv[1];
78: }
79: *ptr = '\0';
80: }
81:
82:
83: if (argc > 2) {
84: his_tty = argv[2]; /* tty name is arg 2 */
85: } else {
86: his_tty = (char *) 0;
87: }
88:
89: get_addrs(my_machine_name, his_machine_name);
90:
91: /* Load these useful values into the standard message header */
92:
93: msg.id_num = 0;
94:
95: strncpy(msg.l_name, my_name, NAME_SIZE);
96: msg.l_name[NAME_SIZE - 1] = '\0';
97:
98: strncpy(msg.r_name, his_name, NAME_SIZE);
99: msg.r_name[NAME_SIZE - 1] = '\0';
100:
101: strncpy(msg.r_tty, his_tty, TTY_SIZE);
102: msg.r_tty[TTY_SIZE - 1] = '\0';
103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.