home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-B.05 / NETKIT-B / NetKit-B-0.05 / talk / ctl.c,v < prev    next >
Encoding:
Text File  |  1994-07-16  |  4.0 KB  |  139 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     florian:1.1; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    94.07.16.09.38.38;    author florian;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19. 1.1
  20. log
  21. @Initial revision
  22. @
  23. text
  24. @/*
  25.  * Copyright (c) 1983 Regents of the University of California.
  26.  * All rights reserved.
  27.  *
  28.  * Redistribution and use in source and binary forms, with or without
  29.  * modification, are permitted provided that the following conditions
  30.  * are met:
  31.  * 1. Redistributions of source code must retain the above copyright
  32.  *    notice, this list of conditions and the following disclaimer.
  33.  * 2. Redistributions in binary form must reproduce the above copyright
  34.  *    notice, this list of conditions and the following disclaimer in the
  35.  *    documentation and/or other materials provided with the distribution.
  36.  * 3. All advertising materials mentioning features or use of this software
  37.  *    must display the following acknowledgement:
  38.  *    This product includes software developed by the University of
  39.  *    California, Berkeley and its contributors.
  40.  * 4. Neither the name of the University nor the names of its contributors
  41.  *    may be used to endorse or promote products derived from this software
  42.  *    without specific prior written permission.
  43.  *
  44.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  45.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  46.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  47.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  48.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  49.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  50.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  54.  * SUCH DAMAGE.
  55.  */
  56.  
  57. #ifndef lint
  58. /*static char sccsid[] = "from: @@(#)ctl.c    5.7 (Berkeley) 3/1/91";*/
  59. static char rcsid[] = "$Id: ctl.c,v 1.2 1993/08/01 18:07:55 mycroft Exp $";
  60. #endif /* not lint */
  61.  
  62. /*
  63.  * This file handles haggling with the various talk daemons to
  64.  * get a socket to talk to. sockt is opened and connected in
  65.  * the progress
  66.  */
  67.  
  68. #include <sys/types.h>
  69. #include <sys/socket.h>
  70. #include <protocols/talkd.h>
  71. #include <netinet/in.h>
  72. #include "talk.h"
  73. #include "talk_ctl.h"
  74.  
  75. struct    sockaddr_in daemon_addr = { sizeof(daemon_addr), AF_INET };
  76. struct    sockaddr_in ctl_addr = { sizeof(ctl_addr), AF_INET };
  77. struct    sockaddr_in my_addr = { sizeof(my_addr), AF_INET };
  78.  
  79.     /* inet addresses of the two machines */
  80. struct    in_addr my_machine_addr;
  81. struct    in_addr his_machine_addr;
  82.  
  83. u_short daemon_port;    /* port number of the talk daemon */
  84.  
  85. int    ctl_sockt;
  86. int    sockt;
  87. int    invitation_waiting = 0;
  88.  
  89. CTL_MSG msg;
  90.  
  91. open_sockt()
  92. {
  93.     int length;
  94.  
  95.     my_addr.sin_addr = my_machine_addr;
  96.     my_addr.sin_port = 0;
  97.     sockt = socket(AF_INET, SOCK_STREAM, 0);
  98.     if (sockt <= 0)
  99.         p_error("Bad socket");
  100.     if (bind(sockt, (struct sockaddr *)&my_addr, sizeof(my_addr)) != 0)
  101.         p_error("Binding local socket");
  102.     length = sizeof(my_addr);
  103.     if (getsockname(sockt, (struct sockaddr *)&my_addr, &length) == -1)
  104.         p_error("Bad address for socket");
  105. }
  106.  
  107. /* open the ctl socket */
  108. open_ctl() 
  109. {
  110.     int length;
  111.  
  112.     ctl_addr.sin_port = 0;
  113.     ctl_addr.sin_addr = my_machine_addr;
  114.     ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
  115.     if (ctl_sockt <= 0)
  116.         p_error("Bad socket");
  117.     if (bind(ctl_sockt,
  118.         (struct sockaddr *)&ctl_addr, sizeof(ctl_addr)) != 0)
  119.         p_error("Couldn't bind to control socket");
  120.     length = sizeof(ctl_addr);
  121.     if (getsockname(ctl_sockt,
  122.         (struct sockaddr *)&ctl_addr, &length) == -1)
  123.         p_error("Bad address for ctl socket");
  124. }
  125.  
  126. /* print_addr is a debug print routine */
  127. print_addr(addr)
  128.     struct sockaddr_in addr;
  129. {
  130.     int i;
  131.  
  132.     printf("addr = %x, port = %o, family = %o zero = ",
  133.         addr.sin_addr, addr.sin_port, addr.sin_family);
  134.     for (i = 0; i<8;i++)
  135.     printf("%o ", (int)addr.sin_zero[i]);
  136.     putchar('\n');
  137. }
  138. @
  139.