static char sccsid
[] = "@(#)main.c 4.1 %G%";
* Routing Table Management Daemon
int supplier
= -1; /* process should supply updates */
struct rip
*msg
= (struct rip
*)packet
;
for (cc
= 0; cc
< 10; cc
++)
{ int t
= open("/dev/tty", 2);
ioctl(t
, TIOCNOTTY
, (char *)0);
traceon("/etc/routerlog");
* We use two sockets. One for which outgoing
* packets are routed and for which they're not.
* The latter allows us to delete routing table
* entries in the kernel for network interfaces
* attached to our host which we believe are down
* while still polling it to see when/if it comes
* back up. With the new ipc interface we'll be
* able to specify ``don't route'' as an option
* to send, but until then we utilize a second port.
sp
= getservbyname("router", "udp");
fprintf(stderr
, "routed: udp/router: unknown service\n");
routingaddr
.sin_family
= AF_INET
;
routingaddr
.sin_port
= htons(sp
->s_port
);
noroutingaddr
.sin_family
= AF_INET
;
noroutingaddr
.sin_port
= htons(sp
->s_port
+ 1);
s
= socket(SOCK_DGRAM
, 0, &routingaddr
, 0);
snoroute
= socket(SOCK_DGRAM
, 0, &noroutingaddr
, SO_DONTROUTE
);
while (argc
> 0 && **argv
== '-') {
if (!strcmp(*argv
, "-s") == 0) {
if (!strcmp(*argv
, "-q") == 0) {
fprintf(stderr
, "usage: routed [ -s ] [ -q ]\n");
* Collect an initial view of the world by
* snooping in the kernel and the gateway kludge
* file. Then, send a request packet on all
* directly connected networks to find out what
msg
->rip_cmd
= RIPCMD_REQUEST
;
msg
->rip_nets
[0].rip_dst
.sa_family
= AF_UNSPEC
;
msg
->rip_nets
[0].rip_metric
= HOPCNT_INFINITY
;
ibits
= (1 << s
) | (1 << snoroute
);
n
= select(32, &ibits
, 0, INFINITY
);
if (ibits
& (1 << snoroute
))
cc
= receive(fd
, &from
, packet
, sizeof (packet
));
if (cc
< 0 && errno
!= EINTR
)