8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / talk / get_addrs.c
blobbef638be71151d56d78a373ae6b21514735cff6d
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include "talk_ctl.h"
43 #include <locale.h>
45 #ifdef SYSV
46 #define bcmp(a, b, c) memcmp((a), (b), (c))
47 #define bcopy(a, b, c) memcpy((b), (a), (c))
48 #endif /* SYSV */
50 struct hostent *gethostbyname();
51 struct servent *getservbyname();
53 void
54 get_addrs(my_machine_name, rem_machine_name)
55 char *my_machine_name;
56 char *rem_machine_name;
58 struct hostent *hp;
59 struct servent *sp;
61 msg.pid = getpid();
63 /* look up the address of the local host */
65 hp = gethostbyname(my_machine_name);
67 if (hp == (struct hostent *) 0) {
68 fprintf(stderr,
69 gettext("This machine doesn't exist. Boy, am I confused!\n"));
70 exit(1);
73 if (hp->h_addrtype != AF_INET) {
74 fprintf(stderr,
75 gettext("Protocol mix up with local machine address\n"));
76 exit(1);
79 bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
81 /* if on the same machine, then simply copy */
83 if (bcmp((char *)&rem_machine_name, (char *)&my_machine_name,
84 sizeof (rem_machine_name)) == 0) {
85 bcopy((char *)&my_machine_addr, (char *)&rem_machine_addr,
86 sizeof (rem_machine_name));
87 } else {
89 if ((rem_machine_addr.s_addr =
90 (unsigned long)inet_addr(rem_machine_name)) == -1) {
92 /* look up the address of the recipient's machine */
94 hp = gethostbyname(rem_machine_name);
96 if (hp == (struct hostent *) 0) {
97 fprintf(stderr,
98 gettext("%s is an unknown host\n"), rem_machine_name);
99 exit(1);
102 if (hp->h_addrtype != AF_INET) {
103 fprintf(stderr,
104 gettext("Protocol mix up with remote machine address\n"));
105 exit(1);
108 bcopy(hp->h_addr, (char *) &rem_machine_addr, hp->h_length);
113 /* find the daemon portal */
115 #ifdef NTALK
116 sp = getservbyname("ntalk", "udp");
117 #else
118 sp = getservbyname("talk", "udp");
119 #endif
121 if (strcmp(sp->s_proto, "udp") != 0) {
122 fprintf(stderr, gettext("Protocol mix up with talk daemon\n"));
123 exit(1);
126 if (sp == 0) {
127 p_error(
128 gettext("This machine doesn't support a tcp talk daemon"));
129 exit(1);
132 daemon_port = sp->s_port;