Annotation of 43BSD/old/talk/ctl.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  */
                      6: 
                      7: #ifndef lint
                      8: static char sccsid[] = "@(#)ctl.c      5.1 (Berkeley) 6/6/85";
                      9: #endif not lint
                     10: 
                     11: /*
                     12:  * This file handles haggling with the various talk daemons to
                     13:  * get a socket to talk to. sockt is opened and connected in
                     14:  * the progress
                     15:  */
                     16: 
                     17: #include "talk_ctl.h"
                     18: 
                     19: struct sockaddr_in daemon_addr = { AF_INET };
                     20: struct sockaddr_in ctl_addr = { AF_INET };
                     21: struct sockaddr_in my_addr = { AF_INET };
                     22: 
                     23:     /* inet addresses of the two machines */
                     24: struct in_addr my_machine_addr;
                     25: struct in_addr his_machine_addr;
                     26: 
                     27: u_short daemon_port;   /* port number of the talk daemon */
                     28: 
                     29: int    ctl_sockt;
                     30: int    sockt;
                     31: int    invitation_waiting = 0;
                     32: 
                     33: CTL_MSG msg;
                     34: 
                     35: open_sockt()
                     36: {
                     37:     int length;
                     38: 
                     39:     my_addr.sin_addr = my_machine_addr;
                     40:     my_addr.sin_port = 0;
                     41:     sockt = socket(AF_INET, SOCK_STREAM, 0);
                     42:     if (sockt <= 0)
                     43:        p_error("Bad socket");
                     44:     if (bind(sockt, &my_addr, sizeof(my_addr)) != 0)
                     45:        p_error("Binding local socket");
                     46:     length = sizeof(my_addr);
                     47:     if (getsockname(sockt, &my_addr, &length) == -1)
                     48:        p_error("Bad address for socket");
                     49: }
                     50: 
                     51: /* open the ctl socket */
                     52: open_ctl() 
                     53: {
                     54:     int length;
                     55: 
                     56:     ctl_addr.sin_port = 0;
                     57:     ctl_addr.sin_addr = my_machine_addr;
                     58:     ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
                     59:     if (ctl_sockt <= 0)
                     60:        p_error("Bad socket");
                     61:     if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr), 0) != 0)
                     62:        p_error("Couldn't bind to control socket");
                     63:     length = sizeof(ctl_addr);
                     64:     if (getsockname(ctl_sockt, &ctl_addr, &length) == -1)
                     65:        p_error("Bad address for ctl socket");
                     66: }
                     67: 
                     68: /* print_addr is a debug print routine */
                     69: print_addr(addr)
                     70: struct sockaddr_in addr;
                     71: {
                     72:     int i;
                     73: 
                     74:     printf("addr = %x, port = %o, family = %o zero = ",
                     75:            addr.sin_addr, addr.sin_port, addr.sin_family);
                     76:     for (i = 0; i<8;i++)
                     77:        printf("%o ", (int)addr.sin_zero[i]);
                     78:     putchar('\n');
                     79: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.