* 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 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.
"@(#) Copyright (c) 1985 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.6 (Berkeley) %G%";
* XNS Routing Information Protocol Daemon
int supplier
= -1; /* process should supply updates */
struct rip
*msg
= (struct rip
*) &packet
[sizeof (struct idp
)];
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");
ioctl(t
, TIOCNOTTY
, (char *)0);
openlog("XNSrouted", LOG_PID
, LOG_DAEMON
);
ns_anynet
.s_net
[0] = -1; ns_anynet
.s_net
[1] = -1;
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
)
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
) {
while (bind(s
, sns
, sizeof (*sns
), 0) < 0 && retry
) {
if (setsockopt(s
, 0, SO_HEADERS_ON_INPUT
, &on
, sizeof(on
))) {
syslog("setsockopt SEE HEADERS: %m");
if (setsockopt(s
, 0, SO_DEFAULT_HEADERS
, &idp
, sizeof(idp
))) {
syslog("setsockopt SET HEADER: %m");
if (setsockopt(s
, SOL_SOCKET
, SO_BROADCAST
, &on
, sizeof (on
)) < 0) {
syslog("setsockopt SO_BROADCAST: %m");
* Fork and exit on EMT-- for profiling.