|
|
1.1 ! root 1: /* $Header: ctl.c 1.4 83/06/09 23:37:01 moore Exp $ */ ! 2: ! 3: /* This file handles haggling with the various talk daemons to ! 4: get a socket to talk to. sockt is opened and connected in ! 5: the progress ! 6: */ ! 7: ! 8: #include "talk_ctl.h" ! 9: ! 10: struct sockaddr_in daemon_addr = { AF_INET }; ! 11: struct sockaddr_in ctl_addr = { AF_INET }; ! 12: struct sockaddr_in my_addr = { AF_INET }; ! 13: ! 14: /* inet addresses of the two machines */ ! 15: struct in_addr my_machine_addr; ! 16: struct in_addr his_machine_addr; ! 17: ! 18: u_short daemon_port; /* port number of the talk daemon */ ! 19: ! 20: int ctl_sockt; ! 21: int sockt; ! 22: int invitation_waiting = 0; ! 23: ! 24: CTL_MSG msg; ! 25: ! 26: open_sockt() ! 27: { ! 28: int length; ! 29: ! 30: my_addr.sin_addr = my_machine_addr; ! 31: my_addr.sin_port = 0; ! 32: ! 33: sockt = socket(AF_INET, SOCK_STREAM, 0, 0); ! 34: ! 35: if (sockt <= 0) { ! 36: p_error("Bad socket"); ! 37: } ! 38: ! 39: if ( bind(sockt, &my_addr, sizeof(my_addr)) != 0) { ! 40: p_error("Binding local socket"); ! 41: } ! 42: ! 43: length = sizeof(my_addr); ! 44: ! 45: if (getsockname(sockt, &my_addr, &length) == -1) { ! 46: p_error("Bad address for socket"); ! 47: } ! 48: } ! 49: ! 50: /* open the ctl socket */ ! 51: ! 52: open_ctl() ! 53: { ! 54: int length; ! 55: ! 56: ctl_addr.sin_port = 0; ! 57: ctl_addr.sin_addr = my_machine_addr; ! 58: ! 59: ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0, 0); ! 60: ! 61: if (ctl_sockt <= 0) { ! 62: p_error("Bad socket"); ! 63: } ! 64: ! 65: if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr), 0) != 0) { ! 66: p_error("Couldn't bind to control socket"); ! 67: } ! 68: ! 69: length = sizeof(ctl_addr); ! 70: if (getsockname(ctl_sockt, &ctl_addr, &length) == -1) { ! 71: p_error("Bad address for ctl socket"); ! 72: } ! 73: } ! 74: ! 75: /* print_addr is a debug print routine */ ! 76: ! 77: print_addr(addr) ! 78: struct sockaddr_in addr; ! 79: { ! 80: int i; ! 81: ! 82: printf("addr = %x, port = %o, family = %o zero = ", ! 83: addr.sin_addr, addr.sin_port, addr.sin_family); ! 84: ! 85: for (i = 0; i<8;i++) { ! 86: printf("%o ", (int)addr.sin_zero[i]); ! 87: } ! 88: putchar('\n'); ! 89: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.