static char rcsid
[] = "$Header$";
* XNS Routing Information Protocol Daemon
int supplier
= -1; /* process should supply updates */
struct rip
*msg
= (struct rip
*) &packet
[sizeof (struct idp
)];
addr
.sns_port
= htons(IDPPORT_RIF
);
s
= getsocket(SOCK_DGRAM
, 0, &addr
);
while (argc
> 0 && **argv
== '-') {
if (strcmp(*argv
, "-s") == 0) {
if (strcmp(*argv
, "-q") == 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);
* 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
);
xnnet(msg
->rip_nets
[0].rip_dst
[0]) = htonl(DSTNETS_ALL
);
msg
->rip_nets
[0].rip_metric
= htons(HOPCNT_INFINITY
);
n = select(20, &ibits, 0, 0, 0);
/* handle ICMP redirects */
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
)
/* We get the IDP header in front of the RIF packet*/
fprintf(ftrace
,"rcv %d bytes on %s ",
cc
, xns_ntoa(&idp
->idp_dna
));
fprintf(ftrace
," from %s\n", xns_ntoa(&idp
->idp_sna
));
if (ns_netof(idp
->idp_sna
) != ns_netof(idp
->idp_dna
)) {
fprintf(ftrace
, "XNSrouted: net of interface (%d) != net on ether (%d)!\n",
ns_netof(idp
->idp_dna
), ns_netof(idp
->idp_sna
));
cc
-= sizeof (struct idp
);
if (fromlen
!= sizeof (struct sockaddr_ns
))
fprintf(ftrace
, "fromlen is %d instead of %d\n",
fromlen
, sizeof (struct sockaddr_ns
));
#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
))) {
perror("setsockopt SEE HEADERS");
if (setsockopt(s
, 0, SO_DEFAULT_HEADERS
, &idp
, sizeof(idp
))) {
perror("setsockopt SET HEADERS");
if (setsockopt(s
, SOL_SOCKET
, SO_BROADCAST
, &on
, sizeof (on
)) < 0) {
perror("setsockopt SO_BROADCAST");
* Fork and exit on EMT-- for profiling.