home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume4 / bridge / part02 / ctl.c next >
C/C++ Source or Header  |  1988-05-31  |  2KB  |  92 lines

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