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 / get_addrs.c,v < prev    next >
Encoding:
Text File  |  1994-08-04  |  3.3 KB  |  109 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.08.04.17.57.24;    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: @@(#)get_addrs.c    5.7 (Berkeley) 3/1/91";*/
  59. static char rcsid[] = "$Id: get_addrs.c,v 1.2 1993/08/01 18:07:52 mycroft Exp $";
  60. #endif /* not lint */
  61.  
  62. #include <sys/types.h>
  63. #include <sys/socket.h>
  64. #include <netinet/in.h>
  65. #include <protocols/talkd.h>
  66. #include <netdb.h>
  67. #include <stdio.h>
  68. #include "talk_ctl.h"
  69.  
  70. get_addrs(my_machine_name, his_machine_name)
  71.     char *my_machine_name, *his_machine_name;
  72. {
  73.     struct hostent *hp;
  74.     struct servent *sp;
  75.  
  76.     msg.pid = htonl(getpid());
  77.     /* look up the address of the local host */
  78.     hp = gethostbyname(my_machine_name);
  79.     if (hp == NULL) {
  80.         fprintf(stderr, "talk: %s: ", my_machine_name);
  81.         herror((char *)NULL);
  82.         exit(-1);
  83.     }
  84.     bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
  85.     /*
  86.      * If the callee is on-machine, just copy the
  87.      * network address, otherwise do a lookup...
  88.      */
  89.     if (strcmp(his_machine_name, my_machine_name)) {
  90.         hp = gethostbyname(his_machine_name);
  91.         if (hp == NULL) {
  92.             fprintf(stderr, "talk: %s: ", his_machine_name);
  93.             herror((char *)NULL);
  94.             exit(-1);
  95.         }
  96.         bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
  97.     } else
  98.         his_machine_addr = my_machine_addr;
  99.     /* find the server's port */
  100.     sp = getservbyname("ntalk", "udp");
  101.     if (sp == 0) {
  102.         fprintf(stderr, "talk: %s/%s: service is not registered.\n",
  103.              "ntalk", "udp");
  104.         exit(-1);
  105.     }
  106.     daemon_port = sp->s_port;
  107. }
  108. @
  109.