8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / talk / ctl.c
blob0aa6dd53db4fb01d1e28502f54e7a81eff699f8c
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"
43 * This file handles haggling with the various talk daemons to
44 * get a socket to talk to. sockt is opened and connected in
45 * the progress
48 #include "talk_ctl.h"
49 #include <libintl.h>
51 struct sockaddr_in daemon_addr = { AF_INET };
52 struct sockaddr_in ctl_addr = { AF_INET };
53 struct sockaddr_in my_addr = { AF_INET };
55 /* inet addresses of the two machines */
56 struct in_addr my_machine_addr;
57 struct in_addr rem_machine_addr;
59 u_short daemon_port; /* port number of the talk daemon */
61 int ctl_sockt;
62 int sockt;
63 int invitation_waiting = 0;
65 CTL_MSG msg;
67 void
68 open_sockt()
70 socklen_t length;
72 my_addr.sin_addr = my_machine_addr;
73 my_addr.sin_port = 0;
75 sockt = socket(AF_INET, SOCK_STREAM, 0);
77 if (sockt <= 0) {
78 p_error(gettext("Bad socket"));
81 if (bind(sockt, (struct sockaddr *)&my_addr, sizeof (my_addr)) != 0) {
82 p_error(gettext("Binding local socket"));
85 length = (socklen_t) sizeof (my_addr);
87 if (getsockname(sockt, (struct sockaddr *)&my_addr, &length) == -1) {
88 p_error(gettext("Bad address for socket"));
92 /* open the ctl socket */
94 void
95 open_ctl()
97 socklen_t length;
99 ctl_addr.sin_port = 0;
100 ctl_addr.sin_addr = my_machine_addr;
102 ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
104 if (ctl_sockt <= 0) {
105 p_error(gettext("Bad socket"));
108 if (bind(ctl_sockt, (struct sockaddr *)&ctl_addr, sizeof (ctl_addr))
109 != 0) {
110 p_error(gettext("Couldn't bind to control socket"));
113 length = (socklen_t) sizeof (ctl_addr);
114 if (getsockname(ctl_sockt, (struct sockaddr *)&ctl_addr, &length)
115 == -1) {
116 p_error(gettext("Bad address for ctl socket"));
120 /* print_addr is a debug print routine */
122 void
123 print_addr(addr)
124 struct sockaddr_in addr;
126 int i;
128 printf("addr = %x, port = %o, family = %o zero = ",
129 addr.sin_addr, (int)addr.sin_port, addr.sin_family);
131 for (i = 0; i < 8; i++) {
132 printf("%o ", (int)addr.sin_zero[i]);
134 putchar('\n');