removed support for -r, -h, and rmail
[unix-history] / usr / src / usr.bin / talk / ctl.c
CommitLineData
d0aeaf5a
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
f9ac90b4
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
d0aeaf5a
DF
11 */
12
963ce42e 13#ifndef lint
f9ac90b4
KB
14static char sccsid[] = "@(#)ctl.c 5.3 (Berkeley) %G%";
15#endif /* not lint */
963ce42e
MK
16
17/*
18 * This file handles haggling with the various talk daemons to
19 * get a socket to talk to. sockt is opened and connected in
20 * the progress
5c2c7ddb
MK
21 */
22
23#include "talk_ctl.h"
24
963ce42e
MK
25struct sockaddr_in daemon_addr = { AF_INET };
26struct sockaddr_in ctl_addr = { AF_INET };
27struct sockaddr_in my_addr = { AF_INET };
5c2c7ddb 28
4fa2ac2d 29 /* inet addresses of the two machines */
963ce42e
MK
30struct in_addr my_machine_addr;
31struct in_addr his_machine_addr;
5c2c7ddb
MK
32
33u_short daemon_port; /* port number of the talk daemon */
34
963ce42e
MK
35int ctl_sockt;
36int sockt;
37int invitation_waiting = 0;
5c2c7ddb
MK
38
39CTL_MSG msg;
40
41open_sockt()
42{
4fa2ac2d 43 int length;
5c2c7ddb 44
4fa2ac2d
KM
45 my_addr.sin_addr = my_machine_addr;
46 my_addr.sin_port = 0;
47 sockt = socket(AF_INET, SOCK_STREAM, 0);
48 if (sockt <= 0)
49 p_error("Bad socket");
50 if (bind(sockt, &my_addr, sizeof(my_addr)) != 0)
51 p_error("Binding local socket");
52 length = sizeof(my_addr);
53 if (getsockname(sockt, &my_addr, &length) == -1)
54 p_error("Bad address for socket");
5c2c7ddb
MK
55}
56
963ce42e 57/* open the ctl socket */
5c2c7ddb
MK
58open_ctl()
59{
4fa2ac2d 60 int length;
5c2c7ddb 61
4fa2ac2d
KM
62 ctl_addr.sin_port = 0;
63 ctl_addr.sin_addr = my_machine_addr;
64 ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
65 if (ctl_sockt <= 0)
66 p_error("Bad socket");
67 if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr), 0) != 0)
68 p_error("Couldn't bind to control socket");
69 length = sizeof(ctl_addr);
70 if (getsockname(ctl_sockt, &ctl_addr, &length) == -1)
71 p_error("Bad address for ctl socket");
5c2c7ddb
MK
72}
73
74/* print_addr is a debug print routine */
5c2c7ddb 75print_addr(addr)
4fa2ac2d 76 struct sockaddr_in addr;
5c2c7ddb 77{
4fa2ac2d 78 int i;
5c2c7ddb 79
4fa2ac2d
KM
80 printf("addr = %x, port = %o, family = %o zero = ",
81 addr.sin_addr, addr.sin_port, addr.sin_family);
82 for (i = 0; i<8;i++)
5c2c7ddb 83 printf("%o ", (int)addr.sin_zero[i]);
4fa2ac2d 84 putchar('\n');
5c2c7ddb 85}