11590Srgrimes/* 21590Srgrimes * Copyright (c) 1983, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 3087710Smarkm#include <sys/cdefs.h> 3187710Smarkm 3287710Smarkm__FBSDID("$FreeBSD: releng/10.3/usr.bin/talk/get_addrs.c 216370 2010-12-11 08:32:16Z joel $"); 3387710Smarkm 341590Srgrimes#ifndef lint 3587710Smarkmstatic const char sccsid[] = "@(#)get_addrs.c 8.1 (Berkeley) 6/6/93"; 3632503Scharnier#endif 371590Srgrimes 3832503Scharnier#include <err.h> 3932503Scharnier#include <netdb.h> 4014443Sjoerg#include <string.h> 41200418Sdelphij#include <unistd.h> 4287710Smarkm 4314443Sjoerg#include "talk.h" 441590Srgrimes#include "talk_ctl.h" 451590Srgrimes 4614443Sjoergvoid 47178642Sdelphijget_addrs(const char *my_machine_name __unused, const char *his_machine_name) 481590Srgrimes{ 491590Srgrimes struct hostent *hp; 501590Srgrimes struct servent *sp; 511590Srgrimes 521590Srgrimes msg.pid = htonl(getpid()); 5314443Sjoerg 5414443Sjoerg hp = gethostbyname(his_machine_name); 5532503Scharnier if (hp == NULL) 5632503Scharnier errx(1, "%s: %s", his_machine_name, hstrerror(h_errno)); 5714443Sjoerg bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length); 5832503Scharnier if (get_iface(&his_machine_addr, &my_machine_addr) == -1) 5932503Scharnier err(1, "failed to find my interface address"); 601590Srgrimes /* find the server's port */ 611590Srgrimes sp = getservbyname("ntalk", "udp"); 6232503Scharnier if (sp == 0) 6332503Scharnier errx(1, "ntalk/udp: service is not registered"); 641590Srgrimes daemon_port = sp->s_port; 651590Srgrimes} 66