1 /*- 2 * Copyright (c) 1983, 1985 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)get_names.c 5.1 (Berkeley) 6/6/85"; 10 #endif not lint 11 12 #include "talk.h" 13 #include "ctl.h" 14 15 char *getlogin(), *ttyname(), *rindex(); 16 17 extern CTL_MSG msg; 18 19 struct hostent *gethostbyname(); 20 21 /* 22 * Determine the local and remote user, tty, and machines 23 */ 24 get_names(argc, argv) 25 int argc; 26 char *argv[]; 27 { 28 char hostname[HOST_NAME_LENGTH]; 29 char *his_name; 30 char *my_name; 31 char *my_machine_name; 32 char *his_machine_name; 33 char *my_tty; 34 char *his_tty; 35 char *ptr; 36 37 if (argc < 2 ) { 38 printf("Usage: talk user [ttyname]\n"); 39 exit(-1); 40 } 41 if (!isatty(0)) { 42 printf("Standard input must be a tty, not a pipe or a file\n"); 43 exit(-1); 44 } 45 my_name = getlogin(); 46 if (my_name == NULL) { 47 printf("You don't exist. Go away.\n"); 48 exit(-1); 49 } 50 gethostname(hostname, sizeof (hostname)); 51 my_machine_name = hostname; 52 my_tty = rindex(ttyname(0), '/') + 1; 53 /* check for, and strip out, the machine name of the target */ 54 for (ptr = argv[1]; *ptr != '\0' && *ptr != '@' && *ptr != ':' && 55 *ptr != '!' && *ptr != '.'; ptr++) 56 ; 57 if (*ptr == '\0') { 58 /* this is a local to local talk */ 59 his_name = argv[1]; 60 his_machine_name = my_machine_name; 61 } else { 62 if (*ptr == '@') { 63 /* user@host */ 64 his_name = argv[1]; 65 his_machine_name = ptr + 1; 66 } else { 67 /* host.user or host!user or host:user */ 68 his_name = ptr + 1; 69 his_machine_name = argv[1]; 70 } 71 *ptr = '\0'; 72 } 73 if (argc > 2) 74 his_tty = argv[2]; /* tty name is arg 2 */ 75 else 76 his_tty = ""; 77 get_addrs(my_machine_name, his_machine_name); 78 /* Load these useful values into the standard message header */ 79 msg.id_num = 0; 80 strncpy(msg.l_name, my_name, NAME_SIZE); 81 msg.l_name[NAME_SIZE - 1] = '\0'; 82 strncpy(msg.r_name, his_name, NAME_SIZE); 83 msg.r_name[NAME_SIZE - 1] = '\0'; 84 strncpy(msg.r_tty, his_tty, TTY_SIZE); 85 msg.r_tty[TTY_SIZE - 1] = '\0'; 86 } 87