Add define for Kirk Smith's USR Courier driver. Change default baud
[unix-history] / usr / src / usr.bin / talk / ctl.c
CommitLineData
d0aeaf5a
DF
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
963ce42e 7#ifndef lint
4fa2ac2d 8static char sccsid[] = "@(#)ctl.c 5.2 (Berkeley) %G%";
d0aeaf5a 9#endif not lint
963ce42e
MK
10
11/*
12 * This file handles haggling with the various talk daemons to
13 * get a socket to talk to. sockt is opened and connected in
14 * the progress
5c2c7ddb
MK
15 */
16
17#include "talk_ctl.h"
18
963ce42e
MK
19struct sockaddr_in daemon_addr = { AF_INET };
20struct sockaddr_in ctl_addr = { AF_INET };
21struct sockaddr_in my_addr = { AF_INET };
5c2c7ddb 22
4fa2ac2d 23 /* inet addresses of the two machines */
963ce42e
MK
24struct in_addr my_machine_addr;
25struct in_addr his_machine_addr;
5c2c7ddb
MK
26
27u_short daemon_port; /* port number of the talk daemon */
28
963ce42e
MK
29int ctl_sockt;
30int sockt;
31int invitation_waiting = 0;
5c2c7ddb
MK
32
33CTL_MSG msg;
34
35open_sockt()
36{
4fa2ac2d 37 int length;
5c2c7ddb 38
4fa2ac2d
KM
39 my_addr.sin_addr = my_machine_addr;
40 my_addr.sin_port = 0;
41 sockt = socket(AF_INET, SOCK_STREAM, 0);
42 if (sockt <= 0)
43 p_error("Bad socket");
44 if (bind(sockt, &my_addr, sizeof(my_addr)) != 0)
45 p_error("Binding local socket");
46 length = sizeof(my_addr);
47 if (getsockname(sockt, &my_addr, &length) == -1)
48 p_error("Bad address for socket");
5c2c7ddb
MK
49}
50
963ce42e 51/* open the ctl socket */
5c2c7ddb
MK
52open_ctl()
53{
4fa2ac2d 54 int length;
5c2c7ddb 55
4fa2ac2d
KM
56 ctl_addr.sin_port = 0;
57 ctl_addr.sin_addr = my_machine_addr;
58 ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
59 if (ctl_sockt <= 0)
60 p_error("Bad socket");
61 if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr), 0) != 0)
62 p_error("Couldn't bind to control socket");
63 length = sizeof(ctl_addr);
64 if (getsockname(ctl_sockt, &ctl_addr, &length) == -1)
65 p_error("Bad address for ctl socket");
5c2c7ddb
MK
66}
67
68/* print_addr is a debug print routine */
5c2c7ddb 69print_addr(addr)
4fa2ac2d 70 struct sockaddr_in addr;
5c2c7ddb 71{
4fa2ac2d 72 int i;
5c2c7ddb 73
4fa2ac2d
KM
74 printf("addr = %x, port = %o, family = %o zero = ",
75 addr.sin_addr, addr.sin_port, addr.sin_family);
76 for (i = 0; i<8;i++)
5c2c7ddb 77 printf("%o ", (int)addr.sin_zero[i]);
4fa2ac2d 78 putchar('\n');
5c2c7ddb 79}