X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/1c15e88899094343f75aeba04122cd96a96b428e..ad7871609881e73855d0b04da49b486cd93efca7:/usr/src/sbin/routed/query/query.c diff --git a/usr/src/sbin/routed/query/query.c b/usr/src/sbin/routed/query/query.c index 62245c14fc..a800388155 100644 --- a/usr/src/sbin/routed/query/query.c +++ b/usr/src/sbin/routed/query/query.c @@ -1,47 +1,68 @@ -/* - * Copyright (c) 1980 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * 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. */ #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1980 Regents of the University of California.\n\ - All rights reserved.\n"; +static char copyright[] = +"@(#) Copyright (c) 1982, 1986, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)query.c 5.11 (Berkeley) 10/10/88"; +static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 6/5/93"; #endif /* not lint */ #include #include #include #include +#include #include +#include +#include +#include #include +#include #include -#include -#include +#include +#include #define WTIME 5 /* Time to wait for all responses */ #define STIME 500000 /* usec to wait for another response */ int s; -int timedout, timeout(); +int timedout; +void timeout(); char packet[MAXPACKETSIZE]; -extern int errno; int nflag; main(argc, argv) @@ -52,11 +73,12 @@ main(argc, argv) extern int optind; int ch, cc, count, bits; struct sockaddr from; + struct sigaction sigact; int fromlen = sizeof(from), size = 32*1024; struct timeval shorttime; while ((ch = getopt(argc, argv, "n")) != EOF) - switch((char)ch) { + switch (ch) { case 'n': nflag++; break; @@ -91,10 +113,14 @@ usage: printf("usage: query [-n] hosts...\n"); bits = 1 << s; bzero(&shorttime, sizeof(shorttime)); shorttime.tv_usec = STIME; - signal(SIGALRM, timeout); + bzero(&sigact, sizeof(sigact)); + sigact.sa_handler = timeout; + /*sigact.sa_flags = 0; /* no restart */ + if (sigaction(SIGALRM, &sigact, (struct sigaction *)NULL) == -1) + perror("sigaction"); alarm(WTIME); while ((count > 0 && !timedout) || - select(20, &bits, 0, 0, &shorttime) > 0) { + select(20, (fd_set *)&bits, NULL, NULL, &shorttime) > 0) { cc = recvfrom(s, packet, sizeof (packet), 0, &from, &fromlen); if (cc <= 0) { @@ -144,7 +170,7 @@ query(host) msg->rip_nets[0].rip_dst.sa_family = htons(AF_UNSPEC); msg->rip_nets[0].rip_metric = htonl(HOPCNT_INFINITY); if (sendto(s, packet, sizeof (struct rip), 0, - &router, sizeof(router)) < 0) + (struct sockaddr *)&router, sizeof(router)) < 0) perror(host); } @@ -168,8 +194,8 @@ rip_input(from, size) if (nflag) printf("%s:\n", inet_ntoa(from->sin_addr)); else { - hp = gethostbyaddr(&from->sin_addr, sizeof (struct in_addr), - AF_INET); + hp = gethostbyaddr((char *)&from->sin_addr, + sizeof (struct in_addr), AF_INET); name = hp == 0 ? "???" : hp->h_name; printf("%s(%s):\n", name, inet_ntoa(from->sin_addr)); } @@ -214,7 +240,7 @@ rip_input(from, size) goto host; } else { host: - hp = gethostbyaddr(&sin->sin_addr, + hp = gethostbyaddr((char *)&sin->sin_addr, sizeof (struct in_addr), AF_INET); if (hp) name = hp->h_name; @@ -242,6 +268,7 @@ rip_input(from, size) } } +void timeout() { timedout = 1;