|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 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. ! 16: */ ! 17: ! 18: #ifndef lint ! 19: static char sccsid[] = "@(#)ctl.c 5.4 (Berkeley) 6/29/88"; ! 20: #endif /* not lint */ ! 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 ! 26: */ ! 27: ! 28: #include "talk_ctl.h" ! 29: ! 30: struct sockaddr_in daemon_addr = { AF_INET }; ! 31: struct sockaddr_in ctl_addr = { AF_INET }; ! 32: struct sockaddr_in my_addr = { AF_INET }; ! 33: ! 34: /* inet addresses of the two machines */ ! 35: struct in_addr my_machine_addr; ! 36: struct in_addr his_machine_addr; ! 37: ! 38: u_short daemon_port; /* port number of the talk daemon */ ! 39: ! 40: int ctl_sockt; ! 41: int sockt; ! 42: int invitation_waiting = 0; ! 43: ! 44: CTL_MSG msg; ! 45: ! 46: open_sockt() ! 47: { ! 48: int length; ! 49: ! 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"); ! 60: } ! 61: ! 62: /* open the ctl socket */ ! 63: open_ctl() ! 64: { ! 65: int length; ! 66: ! 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"); ! 77: } ! 78: ! 79: /* print_addr is a debug print routine */ ! 80: print_addr(addr) ! 81: struct sockaddr_in addr; ! 82: { ! 83: int i; ! 84: ! 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++) ! 88: printf("%o ", (int)addr.sin_zero[i]); ! 89: putchar('\n'); ! 90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.