Commit | Line | Data |
---|---|---|
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 | |
b36fc510 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
d0aeaf5a DF |
16 | */ |
17 | ||
963ce42e | 18 | #ifndef lint |
b36fc510 | 19 | static char sccsid[] = "@(#)ctl.c 5.4 (Berkeley) %G%"; |
f9ac90b4 | 20 | #endif /* not lint */ |
963ce42e MK |
21 | |
22 | /* | |
23 | * This file handles haggling with the various talk daemons to | |
24 | * get a socket to talk to. sockt is opened and connected in | |
25 | * the progress | |
5c2c7ddb MK |
26 | */ |
27 | ||
28 | #include "talk_ctl.h" | |
29 | ||
963ce42e MK |
30 | struct sockaddr_in daemon_addr = { AF_INET }; |
31 | struct sockaddr_in ctl_addr = { AF_INET }; | |
32 | struct sockaddr_in my_addr = { AF_INET }; | |
5c2c7ddb | 33 | |
4fa2ac2d | 34 | /* inet addresses of the two machines */ |
963ce42e MK |
35 | struct in_addr my_machine_addr; |
36 | struct in_addr his_machine_addr; | |
5c2c7ddb MK |
37 | |
38 | u_short daemon_port; /* port number of the talk daemon */ | |
39 | ||
963ce42e MK |
40 | int ctl_sockt; |
41 | int sockt; | |
42 | int invitation_waiting = 0; | |
5c2c7ddb MK |
43 | |
44 | CTL_MSG msg; | |
45 | ||
46 | open_sockt() | |
47 | { | |
4fa2ac2d | 48 | int length; |
5c2c7ddb | 49 | |
4fa2ac2d KM |
50 | my_addr.sin_addr = my_machine_addr; |
51 | my_addr.sin_port = 0; | |
52 | sockt = socket(AF_INET, SOCK_STREAM, 0); | |
53 | if (sockt <= 0) | |
54 | p_error("Bad socket"); | |
55 | if (bind(sockt, &my_addr, sizeof(my_addr)) != 0) | |
56 | p_error("Binding local socket"); | |
57 | length = sizeof(my_addr); | |
58 | if (getsockname(sockt, &my_addr, &length) == -1) | |
59 | p_error("Bad address for socket"); | |
5c2c7ddb MK |
60 | } |
61 | ||
963ce42e | 62 | /* open the ctl socket */ |
5c2c7ddb MK |
63 | open_ctl() |
64 | { | |
4fa2ac2d | 65 | int length; |
5c2c7ddb | 66 | |
4fa2ac2d KM |
67 | ctl_addr.sin_port = 0; |
68 | ctl_addr.sin_addr = my_machine_addr; | |
69 | ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0); | |
70 | if (ctl_sockt <= 0) | |
71 | p_error("Bad socket"); | |
72 | if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr), 0) != 0) | |
73 | p_error("Couldn't bind to control socket"); | |
74 | length = sizeof(ctl_addr); | |
75 | if (getsockname(ctl_sockt, &ctl_addr, &length) == -1) | |
76 | p_error("Bad address for ctl socket"); | |
5c2c7ddb MK |
77 | } |
78 | ||
79 | /* print_addr is a debug print routine */ | |
5c2c7ddb | 80 | print_addr(addr) |
4fa2ac2d | 81 | struct sockaddr_in addr; |
5c2c7ddb | 82 | { |
4fa2ac2d | 83 | int i; |
5c2c7ddb | 84 | |
4fa2ac2d KM |
85 | printf("addr = %x, port = %o, family = %o zero = ", |
86 | addr.sin_addr, addr.sin_port, addr.sin_family); | |
87 | for (i = 0; i<8;i++) | |
5c2c7ddb | 88 | printf("%o ", (int)addr.sin_zero[i]); |
4fa2ac2d | 89 | putchar('\n'); |
5c2c7ddb | 90 | } |