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

Defined functions

get_names defined in line 23; used 1 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1986-03-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 931
Valid CSS Valid XHTML 1.0 Strict