1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #include "talk_ctl.h" 41 #include <locale.h> 42 43 #ifdef SYSV 44 #define bcmp(a, b, c) memcmp((a), (b), (c)) 45 #define bcopy(a, b, c) memcpy((b), (a), (c)) 46 #endif /* SYSV */ 47 48 struct hostent *gethostbyname(); 49 struct servent *getservbyname(); 50 51 void 52 get_addrs(my_machine_name, rem_machine_name) 53 char *my_machine_name; 54 char *rem_machine_name; 55 { 56 struct hostent *hp; 57 struct servent *sp; 58 59 msg.pid = getpid(); 60 61 /* look up the address of the local host */ 62 63 hp = gethostbyname(my_machine_name); 64 65 if (hp == (struct hostent *) 0) { 66 fprintf(stderr, 67 gettext("This machine doesn't exist. Boy, am I confused!\n")); 68 exit(1); 69 } 70 71 if (hp->h_addrtype != AF_INET) { 72 fprintf(stderr, 73 gettext("Protocol mix up with local machine address\n")); 74 exit(1); 75 } 76 77 bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length); 78 79 /* if on the same machine, then simply copy */ 80 81 if (bcmp((char *)&rem_machine_name, (char *)&my_machine_name, 82 sizeof (rem_machine_name)) == 0) { 83 bcopy((char *)&my_machine_addr, (char *)&rem_machine_addr, 84 sizeof (rem_machine_name)); 85 } else { 86 87 if ((rem_machine_addr.s_addr = 88 (unsigned long)inet_addr(rem_machine_name)) == -1) { 89 90 /* look up the address of the recipient's machine */ 91 92 hp = gethostbyname(rem_machine_name); 93 94 if (hp == (struct hostent *) 0) { 95 fprintf(stderr, 96 gettext("%s is an unknown host\n"), rem_machine_name); 97 exit(1); 98 } 99 100 if (hp->h_addrtype != AF_INET) { 101 fprintf(stderr, 102 gettext("Protocol mix up with remote machine address\n")); 103 exit(1); 104 } 105 106 bcopy(hp->h_addr, (char *) &rem_machine_addr, hp->h_length); 107 } 108 } 109 110 111 /* find the daemon portal */ 112 113 #ifdef NTALK 114 sp = getservbyname("ntalk", "udp"); 115 #else 116 sp = getservbyname("talk", "udp"); 117 #endif 118 119 if (strcmp(sp->s_proto, "udp") != 0) { 120 fprintf(stderr, gettext("Protocol mix up with talk daemon\n")); 121 exit(1); 122 } 123 124 if (sp == 0) { 125 p_error( 126 gettext("This machine doesn't support a tcp talk daemon")); 127 exit(1); 128 } 129 130 daemon_port = sp->s_port; 131 } 132