2003-10-16 10:22:09 +04:00
|
|
|
/* $NetBSD: common.c,v 1.26 2003/10/16 06:30:11 itojun Exp $ */
|
1995-11-28 22:43:04 +03:00
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
1994-05-18 05:25:21 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-05-17 08:13:48 +04:00
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-17 08:13:48 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-05 19:11:58 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-17 08:13:48 +04:00
|
|
|
#ifndef lint
|
1997-10-05 19:11:58 +04:00
|
|
|
#if 0
|
1997-10-05 15:52:17 +04:00
|
|
|
static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95";
|
1997-10-05 19:11:58 +04:00
|
|
|
#else
|
2003-10-16 10:22:09 +04:00
|
|
|
__RCSID("$NetBSD: common.c,v 1.26 2003/10/16 06:30:11 itojun Exp $");
|
1997-10-05 19:11:58 +04:00
|
|
|
#endif
|
1994-05-17 08:13:48 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
1997-10-05 15:52:17 +04:00
|
|
|
#include <sys/time.h>
|
1994-05-18 05:25:21 +04:00
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
1997-10-05 19:11:58 +04:00
|
|
|
#include <arpa/inet.h>
|
1994-05-18 05:25:21 +04:00
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2000-08-09 18:28:50 +04:00
|
|
|
#include <ifaddrs.h>
|
1994-05-18 05:25:21 +04:00
|
|
|
#include "lp.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* Routines and data common to all the line printer functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *AF; /* accounting file */
|
1994-05-18 05:25:21 +04:00
|
|
|
long BR; /* baud rate if lp is a tty */
|
|
|
|
char *CF; /* name of cifplot filter (per job) */
|
|
|
|
char *DF; /* name of tex filter (per job) */
|
|
|
|
long DU; /* daeomon user-id */
|
|
|
|
long FC; /* flags to clear if lp is a tty */
|
|
|
|
char *FF; /* form feed string */
|
|
|
|
long FS; /* flags to set if lp is a tty */
|
|
|
|
char *GF; /* name of graph(1G) filter (per job) */
|
|
|
|
long HL; /* print header last */
|
|
|
|
char *IF; /* name of input filter (created per job) */
|
1994-05-17 08:13:48 +04:00
|
|
|
char *LF; /* log file for error messages */
|
1994-05-18 05:25:21 +04:00
|
|
|
char *LO; /* lock file name */
|
|
|
|
char *LP; /* line printer device name */
|
|
|
|
long MC; /* maximum number of copies allowed */
|
1995-10-03 18:02:17 +03:00
|
|
|
char *MS; /* stty flags to set if lp is a tty */
|
1994-05-18 05:25:21 +04:00
|
|
|
long MX; /* maximum number of blocks to copy */
|
|
|
|
char *NF; /* name of ditroff filter (per job) */
|
1994-05-17 08:13:48 +04:00
|
|
|
char *OF; /* name of output filter (created once) */
|
1994-05-18 05:25:21 +04:00
|
|
|
char *PF; /* name of vrast filter (per job) */
|
|
|
|
long PL; /* page length */
|
|
|
|
long PW; /* page width */
|
|
|
|
long PX; /* page width in pixels */
|
|
|
|
long PY; /* page length in pixels */
|
1994-05-17 08:13:48 +04:00
|
|
|
char *RF; /* name of fortran text filter (per job) */
|
1994-05-18 05:25:21 +04:00
|
|
|
char *RG; /* resricted group */
|
|
|
|
char *RM; /* remote machine name */
|
|
|
|
char *RP; /* remote printer name */
|
|
|
|
long RS; /* restricted to those with local accounts */
|
|
|
|
long RW; /* open LP for reading and writing */
|
|
|
|
long SB; /* short banner instead of normal header */
|
|
|
|
long SC; /* suppress multiple copies */
|
|
|
|
char *SD; /* spool directory */
|
|
|
|
long SF; /* suppress FF on each print job */
|
|
|
|
long SH; /* suppress header page */
|
|
|
|
char *ST; /* status file name */
|
1994-05-17 08:13:48 +04:00
|
|
|
char *TF; /* name of troff filter (per job) */
|
|
|
|
char *TR; /* trailer string to be output when Q empties */
|
1994-05-18 05:25:21 +04:00
|
|
|
char *VF; /* name of vplot filter (per job) */
|
|
|
|
long XC; /* flags to clear for local mode */
|
|
|
|
long XS; /* flags to set for local mode */
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
char line[BUFSIZ];
|
1997-10-05 15:52:17 +04:00
|
|
|
int remote; /* true if sending files to a remote host */
|
1994-05-18 05:25:21 +04:00
|
|
|
|
1995-10-03 18:02:17 +03:00
|
|
|
extern uid_t uid, euid;
|
|
|
|
|
2002-07-14 19:27:58 +04:00
|
|
|
static int compar(const void *, const void *);
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
/*
|
1997-10-05 15:52:17 +04:00
|
|
|
* Create a TCP connection to host "rhost" at port "rport".
|
|
|
|
* If rport == 0, then use the printer service port.
|
1994-05-17 08:13:48 +04:00
|
|
|
* Most of this code comes from rcmd.c.
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
int
|
2002-07-14 19:27:58 +04:00
|
|
|
getport(char *rhost, int rport)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2000-01-27 08:39:50 +03:00
|
|
|
struct addrinfo hints, *res, *r;
|
1999-09-26 14:32:27 +04:00
|
|
|
u_int timo = 1;
|
|
|
|
int s, lport = IPPORT_RESERVED - 1;
|
2000-01-27 08:39:50 +03:00
|
|
|
int error;
|
2000-02-18 06:53:16 +03:00
|
|
|
int refuse, trial;
|
2000-04-25 06:34:49 +04:00
|
|
|
char pbuf[NI_MAXSERV];
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the host address and port number to connect to.
|
|
|
|
*/
|
|
|
|
if (rhost == NULL)
|
|
|
|
fatal("no remote host to connect to");
|
2000-01-27 08:39:50 +03:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = PF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
2000-04-25 06:34:49 +04:00
|
|
|
if (rport)
|
|
|
|
snprintf(pbuf, sizeof(pbuf), "%d", rport);
|
|
|
|
else
|
|
|
|
snprintf(pbuf, sizeof(pbuf), "printer");
|
|
|
|
error = getaddrinfo(rhost, pbuf, &hints, &res);
|
2000-01-27 08:39:50 +03:00
|
|
|
if (error)
|
|
|
|
fatal("printer/tcp: %s", gai_strerror(error));
|
1994-05-17 08:13:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try connecting to the server.
|
|
|
|
*/
|
2000-02-18 06:53:16 +03:00
|
|
|
retry:
|
2000-01-27 08:39:50 +03:00
|
|
|
s = -1;
|
2000-02-18 06:53:16 +03:00
|
|
|
refuse = trial = 0;
|
2000-01-27 08:39:50 +03:00
|
|
|
for (r = res; r; r = r->ai_next) {
|
2000-02-18 06:53:16 +03:00
|
|
|
trial++;
|
|
|
|
retryport:
|
2000-01-27 08:39:50 +03:00
|
|
|
seteuid(euid);
|
|
|
|
s = rresvport_af(&lport, r->ai_family);
|
|
|
|
seteuid(uid);
|
|
|
|
if (s < 0)
|
|
|
|
return(-1);
|
|
|
|
if (connect(s, r->ai_addr, r->ai_addrlen) < 0) {
|
|
|
|
error = errno;
|
|
|
|
(void)close(s);
|
|
|
|
s = -1;
|
|
|
|
errno = error;
|
|
|
|
if (errno == EADDRINUSE) {
|
|
|
|
lport--;
|
2000-02-18 06:53:16 +03:00
|
|
|
goto retryport;
|
|
|
|
} else if (errno == ECONNREFUSED)
|
|
|
|
refuse++;
|
2000-01-27 08:39:50 +03:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
break;
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
2000-02-18 06:53:16 +03:00
|
|
|
if (s < 0 && trial == refuse && timo <= 16) {
|
|
|
|
sleep(timo);
|
|
|
|
timo *= 2;
|
|
|
|
goto retry;
|
|
|
|
}
|
2000-01-27 08:39:50 +03:00
|
|
|
if (res)
|
|
|
|
freeaddrinfo(res);
|
1994-05-17 08:13:48 +04:00
|
|
|
return(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Getline reads a line from the control file cfp, removes tabs, converts
|
|
|
|
* new-line to null and leaves it in line.
|
|
|
|
* Returns 0 at EOF or the number of characters read.
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
int
|
2002-07-14 19:27:58 +04:00
|
|
|
getline(FILE *cfp)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-10-05 19:11:58 +04:00
|
|
|
int linel = 0, c;
|
|
|
|
char *lp = line;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
1997-10-05 19:11:58 +04:00
|
|
|
while ((c = getc(cfp)) != '\n' && linel+1<sizeof(line)) {
|
1994-05-17 08:13:48 +04:00
|
|
|
if (c == EOF)
|
|
|
|
return(0);
|
|
|
|
if (c == '\t') {
|
|
|
|
do {
|
|
|
|
*lp++ = ' ';
|
|
|
|
linel++;
|
1997-10-05 19:11:58 +04:00
|
|
|
} while ((linel & 07) != 0 && linel+1 < sizeof(line));
|
1994-05-17 08:13:48 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*lp++ = c;
|
|
|
|
linel++;
|
|
|
|
}
|
|
|
|
*lp++ = '\0';
|
|
|
|
return(linel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the current directory and make a list of daemon files sorted by
|
|
|
|
* creation time.
|
|
|
|
* Return the number of entries and a pointer to the list.
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
int
|
2002-07-14 19:27:58 +04:00
|
|
|
getq(struct queue **namelist[])
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1997-10-05 19:11:58 +04:00
|
|
|
struct dirent *d;
|
2003-10-16 10:22:09 +04:00
|
|
|
struct queue *q, **queue, **nqueue;
|
1994-05-17 08:13:48 +04:00
|
|
|
struct stat stbuf;
|
|
|
|
DIR *dirp;
|
1999-09-26 14:32:27 +04:00
|
|
|
u_int nitems, arraysz;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
2001-04-05 17:30:02 +04:00
|
|
|
dirp = opendir(SD);
|
|
|
|
seteuid(uid);
|
|
|
|
if (dirp == NULL)
|
1994-05-17 08:13:48 +04:00
|
|
|
return(-1);
|
|
|
|
if (fstat(dirp->dd_fd, &stbuf) < 0)
|
|
|
|
goto errdone;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Estimate the array size by taking the size of the directory file
|
|
|
|
* and dividing it by a multiple of the minimum size entry.
|
|
|
|
*/
|
1999-09-26 14:32:27 +04:00
|
|
|
arraysz = (int)(stbuf.st_size / 24);
|
1994-05-17 08:13:48 +04:00
|
|
|
queue = (struct queue **)malloc(arraysz * sizeof(struct queue *));
|
|
|
|
if (queue == NULL)
|
|
|
|
goto errdone;
|
|
|
|
|
|
|
|
nitems = 0;
|
|
|
|
while ((d = readdir(dirp)) != NULL) {
|
|
|
|
if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
|
|
|
|
continue; /* daemon control files only */
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
2001-04-05 17:30:02 +04:00
|
|
|
if (stat(d->d_name, &stbuf) < 0) {
|
|
|
|
seteuid(uid);
|
1994-05-17 08:13:48 +04:00
|
|
|
continue; /* Doesn't exist */
|
2001-04-05 17:30:02 +04:00
|
|
|
}
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1994-05-17 08:13:48 +04:00
|
|
|
q = (struct queue *)malloc(sizeof(time_t)+strlen(d->d_name)+1);
|
|
|
|
if (q == NULL)
|
|
|
|
goto errdone;
|
|
|
|
q->q_time = stbuf.st_mtime;
|
1996-12-09 12:57:40 +03:00
|
|
|
strcpy(q->q_name, d->d_name); /* XXX: strcpy is safe */
|
1994-05-17 08:13:48 +04:00
|
|
|
/*
|
|
|
|
* Check to make sure the array has space left and
|
|
|
|
* realloc the maximum size.
|
|
|
|
*/
|
|
|
|
if (++nitems > arraysz) {
|
2003-10-16 10:22:09 +04:00
|
|
|
nqueue = (struct queue **)realloc(queue,
|
|
|
|
arraysz * 2 * sizeof(struct queue *));
|
|
|
|
if (nqueue == NULL)
|
1994-05-17 08:13:48 +04:00
|
|
|
goto errdone;
|
2003-10-16 10:22:09 +04:00
|
|
|
queue = nqueue;
|
|
|
|
arraysz *= 2;
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
|
|
|
queue[nitems-1] = q;
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
if (nitems)
|
|
|
|
qsort(queue, nitems, sizeof(struct queue *), compar);
|
|
|
|
*namelist = queue;
|
|
|
|
return(nitems);
|
|
|
|
|
|
|
|
errdone:
|
|
|
|
closedir(dirp);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare modification times.
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
static int
|
2002-07-14 19:27:58 +04:00
|
|
|
compar(const void *p1, const void *p2)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
1994-05-18 05:25:21 +04:00
|
|
|
if ((*(struct queue **)p1)->q_time < (*(struct queue **)p2)->q_time)
|
1994-05-17 08:13:48 +04:00
|
|
|
return(-1);
|
1994-05-18 05:25:21 +04:00
|
|
|
if ((*(struct queue **)p1)->q_time > (*(struct queue **)p2)->q_time)
|
1994-05-17 08:13:48 +04:00
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out whether the local machine is the same
|
|
|
|
* as the remote machine (RM) entry (if it exists).
|
|
|
|
*/
|
|
|
|
char *
|
2002-07-14 19:27:58 +04:00
|
|
|
checkremote(void)
|
1994-05-17 08:13:48 +04:00
|
|
|
{
|
2000-08-09 18:28:50 +04:00
|
|
|
char lname[NI_MAXHOST], rname[NI_MAXHOST];
|
|
|
|
struct addrinfo hints, *res, *res0;
|
1994-05-17 08:13:48 +04:00
|
|
|
static char errbuf[128];
|
2000-01-27 08:39:50 +03:00
|
|
|
int error;
|
2000-08-09 18:28:50 +04:00
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
|
#ifdef NI_WITHSCOPEID
|
|
|
|
const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
|
|
|
|
#else
|
|
|
|
const int niflags = NI_NUMERICHOST;
|
|
|
|
#endif
|
|
|
|
#ifdef __KAME__
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
struct sockaddr_in6 *sin6p;
|
|
|
|
#endif
|
1994-05-17 08:13:48 +04:00
|
|
|
|
2000-08-09 18:28:50 +04:00
|
|
|
remote = 0; /* assume printer is local on failure */
|
2000-01-27 08:39:50 +03:00
|
|
|
|
2000-08-09 18:28:50 +04:00
|
|
|
if (RM == NULL)
|
|
|
|
return NULL;
|
1994-05-17 08:13:48 +04:00
|
|
|
|
2000-08-09 18:28:50 +04:00
|
|
|
/* get the local interface addresses */
|
|
|
|
if (getifaddrs(&ifap) < 0) {
|
|
|
|
(void)snprintf(errbuf, sizeof(errbuf),
|
|
|
|
"unable to get local interface address: %s",
|
|
|
|
strerror(errno));
|
|
|
|
return errbuf;
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
|
2000-08-09 18:28:50 +04:00
|
|
|
/* get the remote host addresses (RM) */
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_flags = AI_CANONNAME;
|
|
|
|
hints.ai_family = PF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
res = NULL;
|
|
|
|
error = getaddrinfo(RM, NULL, &hints, &res0);
|
|
|
|
if (error) {
|
|
|
|
(void)snprintf(errbuf, sizeof(errbuf),
|
|
|
|
"unable to resolve remote machine %s: %s",
|
|
|
|
RM, gai_strerror(error));
|
|
|
|
freeifaddrs(ifap);
|
|
|
|
return errbuf;
|
|
|
|
}
|
2000-01-27 08:39:50 +03:00
|
|
|
|
2000-08-09 18:28:50 +04:00
|
|
|
remote = 1; /* assume printer is remote */
|
|
|
|
|
|
|
|
for (res = res0; res; res = res->ai_next) {
|
|
|
|
if (getnameinfo(res->ai_addr, res->ai_addrlen,
|
|
|
|
rname, sizeof(rname), NULL, 0, niflags) != 0)
|
|
|
|
continue;
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
|
|
#ifdef __KAME__
|
|
|
|
sin6p = (struct sockaddr_in6 *)ifa->ifa_addr;
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET6 &&
|
|
|
|
ifa->ifa_addr->sa_len == sizeof(sin6) &&
|
|
|
|
IN6_IS_ADDR_LINKLOCAL(&sin6p->sin6_addr) &&
|
|
|
|
*(u_int16_t *)&sin6p->sin6_addr.s6_addr[2]) {
|
|
|
|
/* kame scopeid hack */
|
|
|
|
memcpy(&sin6, ifa->ifa_addr, sizeof(sin6));
|
|
|
|
sin6.sin6_scope_id =
|
|
|
|
ntohs(*(u_int16_t *)&sin6p->sin6_addr.s6_addr[2]);
|
|
|
|
sin6.sin6_addr.s6_addr[2] = 0;
|
|
|
|
sin6.sin6_addr.s6_addr[3] = 0;
|
|
|
|
if (getnameinfo((struct sockaddr *)&sin6,
|
|
|
|
sin6.sin6_len, lname, sizeof(lname),
|
|
|
|
NULL, 0, niflags) != 0)
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len,
|
|
|
|
lname, sizeof(lname), NULL, 0, niflags) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(rname, lname) == 0) {
|
|
|
|
remote = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|
2000-08-09 18:28:50 +04:00
|
|
|
done:
|
|
|
|
freeaddrinfo(res0);
|
|
|
|
freeifaddrs(ifap);
|
1997-10-05 15:52:17 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sleep n milliseconds */
|
|
|
|
void
|
2002-07-14 19:27:58 +04:00
|
|
|
delay(int n)
|
1997-10-05 15:52:17 +04:00
|
|
|
{
|
2002-09-19 03:27:25 +04:00
|
|
|
struct timespec tdelay;
|
1997-10-05 15:52:17 +04:00
|
|
|
|
|
|
|
if (n <= 0 || n > 10000)
|
|
|
|
fatal("unreasonable delay period (%d)", n);
|
|
|
|
tdelay.tv_sec = n / 1000;
|
2002-09-19 03:27:25 +04:00
|
|
|
tdelay.tv_nsec = (n % 1000) * 1000000;
|
|
|
|
nanosleep(&tdelay, NULL);
|
1994-05-17 08:13:48 +04:00
|
|
|
}
|