ctl.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* $NetBSD: ctl.c,v 1.3 2003/06/11 12:00:22 wiz Exp $ */
  2. /*
  3. * Copyright (c) 1983-2003, Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * + Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * + Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * + Neither the name of the University of California, San Francisco nor
  16. * the names of its contributors may be used to endorse or promote
  17. * products derived from this software without specific prior written
  18. * permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  23. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "bsd.h"
  33. #if defined(TALK_43) || defined(TALK_42)
  34. #include <sys/cdefs.h>
  35. #ifndef lint
  36. #if 0
  37. static char sccsid[] = "@(#)ctl.c 5.2 (Berkeley) 3/13/86";
  38. #else
  39. __RCSID("$NetBSD: ctl.c,v 1.3 2003/06/11 12:00:22 wiz Exp $");
  40. #endif
  41. #endif /* not lint */
  42. /*
  43. * This file handles haggling with the various talk daemons to
  44. * get a socket to talk to. sockt is opened and connected in
  45. * the progress
  46. */
  47. #include "hunt.h"
  48. #include "talk_ctl.h"
  49. struct sockaddr_in daemon_addr = { AF_INET };
  50. struct sockaddr_in ctl_addr = { AF_INET };
  51. /* inet addresses of the two machines */
  52. struct in_addr my_machine_addr;
  53. struct in_addr his_machine_addr;
  54. u_short daemon_port; /* port number of the talk daemon */
  55. int ctl_sockt;
  56. CTL_MSG msg;
  57. /* open the ctl socket */
  58. void
  59. open_ctl()
  60. {
  61. int length;
  62. ctl_addr.sin_port = 0;
  63. ctl_addr.sin_addr = my_machine_addr;
  64. ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
  65. if (ctl_sockt <= 0)
  66. p_error("Bad socket");
  67. if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr)) != 0)
  68. p_error("Couldn't bind to control socket");
  69. length = sizeof(ctl_addr);
  70. if (getsockname(ctl_sockt, (struct sockaddr *) &ctl_addr, &length) < 0)
  71. p_error("Bad address for ctl socket");
  72. }
  73. #endif