|
|
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: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)ctl.c 5.6 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: /* ! 25: * This file handles haggling with the various talk daemons to ! 26: * get a socket to talk to. sockt is opened and connected in ! 27: * the progress ! 28: */ ! 29: ! 30: #include "talk_ctl.h" ! 31: ! 32: struct sockaddr_in daemon_addr = { sizeof(daemon_addr), AF_INET }; ! 33: struct sockaddr_in ctl_addr = { sizeof(ctl_addr), AF_INET }; ! 34: struct sockaddr_in my_addr = { sizeof(my_addr), AF_INET }; ! 35: ! 36: /* inet addresses of the two machines */ ! 37: struct in_addr my_machine_addr; ! 38: struct in_addr his_machine_addr; ! 39: ! 40: u_short daemon_port; /* port number of the talk daemon */ ! 41: ! 42: int ctl_sockt; ! 43: int sockt; ! 44: int invitation_waiting = 0; ! 45: ! 46: CTL_MSG msg; ! 47: ! 48: open_sockt() ! 49: { ! 50: int length; ! 51: ! 52: my_addr.sin_addr = my_machine_addr; ! 53: my_addr.sin_port = 0; ! 54: sockt = socket(AF_INET, SOCK_STREAM, 0); ! 55: if (sockt <= 0) ! 56: p_error("Bad socket"); ! 57: if (bind(sockt, &my_addr, sizeof(my_addr)) != 0) ! 58: p_error("Binding local socket"); ! 59: length = sizeof(my_addr); ! 60: if (getsockname(sockt, &my_addr, &length) == -1) ! 61: p_error("Bad address for socket"); ! 62: } ! 63: ! 64: /* open the ctl socket */ ! 65: open_ctl() ! 66: { ! 67: int length; ! 68: ! 69: ctl_addr.sin_port = 0; ! 70: ctl_addr.sin_addr = my_machine_addr; ! 71: ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0); ! 72: if (ctl_sockt <= 0) ! 73: p_error("Bad socket"); ! 74: if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr), 0) != 0) ! 75: p_error("Couldn't bind to control socket"); ! 76: length = sizeof(ctl_addr); ! 77: if (getsockname(ctl_sockt, &ctl_addr, &length) == -1) ! 78: p_error("Bad address for ctl socket"); ! 79: } ! 80: ! 81: /* print_addr is a debug print routine */ ! 82: print_addr(addr) ! 83: struct sockaddr_in addr; ! 84: { ! 85: int i; ! 86: ! 87: printf("addr = %x, port = %o, family = %o zero = ", ! 88: addr.sin_addr, addr.sin_port, addr.sin_family); ! 89: for (i = 0; i<8;i++) ! 90: printf("%o ", (int)addr.sin_zero[i]); ! 91: putchar('\n'); ! 92: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.