* Copyright (c) 1985 The Regents of the University of California.
* This file includes significant work done at Cornell University by
* Bill Nesheim. That work included by permission.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
* 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
"@(#) Copyright (c) 1985 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.11 (Berkeley) 2/26/91";
* XNS Routing Information Protocol Daemon
int supplier
= -1; /* process should supply updates */
struct rip
*msg
= (struct rip
*) &packet
[sizeof (struct idp
)];
void hup(), fkexit(), timer();
while (argc
> 0 && **argv
== '-') {
if (strcmp(*argv
, "-s") == 0) {
if (strcmp(*argv
, "-q") == 0) {
if (strcmp(*argv
, "-R") == 0) {
if (strcmp(*argv
, "-t") == 0) {
if (strcmp(*argv
, "-g") == 0) {
if (strcmp(*argv
, "-l") == 0) {
"usage: xnsrouted [ -s ] [ -q ] [ -t ] [ -g ] [ -l ]\n");
openlog("XNSrouted", LOG_PID
, LOG_DAEMON
);
ns_anynet
.s_net
[0] = -1; ns_anynet
.s_net
[1] = -1;
addr
.sns_len
= sizeof(addr
);
addr
.sns_port
= htons(IDPPORT_RIF
);
s
= getsocket(SOCK_DGRAM
, 0, &addr
);
* Any extra argument is considered
* Collect an initial view of the world by
* snooping in the kernel. Then, send a request packet on all
* directly connected networks to find out what
/* request the state of the world */
msg
->rip_cmd
= htons(RIPCMD_REQUEST
);
msg
->rip_nets
[0].rip_dst
= ns_anynet
;
msg
->rip_nets
[0].rip_metric
= htons(HOPCNT_INFINITY
);
int fromlen
= sizeof (from
), cc
, omask
;
struct idp
*idp
= (struct idp
*)packet
;
cc
= recvfrom(fd
, packet
, sizeof (packet
), 0, &from
, &fromlen
);
if (cc
< 0 && errno
!= EINTR
)
syslog(LOG_ERR
, "recvfrom: %m");
if (tracepackets
> 1 && ftrace
) {
fprintf(ftrace
,"rcv %d bytes on %s ", cc
, xns_ntoa(&idp
->idp_dna
));
fprintf(ftrace
," from %s\n", xns_ntoa(&idp
->idp_sna
));
if (noteremoterequests
&& !ns_neteqnn(idp
->idp_sna
.x_net
, ns_zeronet
)
&& !ns_neteq(idp
->idp_sna
, idp
->idp_dna
))
"net of interface (%s) != net on ether (%s)!\n",
xns_nettoa(idp
->idp_dna
.x_net
),
xns_nettoa(idp
->idp_sna
.x_net
));
/* We get the IDP header in front of the RIF packet*/
cc
-= sizeof (struct idp
);
#define mask(s) (1<<((s)-1))
omask
= sigblock(mask(SIGALRM
));
getsocket(type
, proto
, sns
)
int domain
= sns
->sns_family
;
while ((s
= socket(domain
, type
, proto
)) < 0 && retry
) {
syslog(LOG_ERR
, "socket: %m");
while (bind(s
, (struct sockaddr
*)sns
, sizeof (*sns
)) < 0 && retry
) {
syslog(LOG_ERR
, "bind: %m");
if (setsockopt(s
, 0, SO_HEADERS_ON_INPUT
, &on
, sizeof(on
))) {
syslog(LOG_ERR
, "setsockopt SEE HEADERS: %m");
if (setsockopt(s
, 0, SO_DEFAULT_HEADERS
, &idp
, sizeof(idp
))) {
syslog(LOG_ERR
, "setsockopt SET HEADER: %m");
if (setsockopt(s
, SOL_SOCKET
, SO_BROADCAST
, &on
, sizeof (on
)) < 0) {
syslog(LOG_ERR
, "setsockopt SO_BROADCAST: %m");
* Fork and exit on EMT-- for profiling.