static char sccsid
[] = "@(#)main.c 4.8 (Berkeley) 7/1/83";
* Routing Table Management Daemon
int supplier
= -1; /* process should supply updates */
struct rip
*msg
= (struct rip
*)packet
;
sp
= getservbyname("router", "udp");
fprintf(stderr
, "routed: router/udp: unknown service\n");
addr
.sin_family
= AF_INET
;
addr
.sin_port
= sp
->s_port
;
s
= getsocket(AF_INET
, SOCK_DGRAM
, &addr
);
bzero(&addr
, sizeof (addr
));
addr
.sin_family
= AF_INET
;
addr
.sin_port
= htons(ntohs(sp
->s_port
) + 1);
snoroute
= getsocket(AF_INET
, SOCK_DGRAM
, &addr
);
while (argc
> 0 && **argv
== '-') {
if (strcmp(*argv
, "-s") == 0) {
if (strcmp(*argv
, "-q") == 0) {
if (strcmp(*argv
, "-t") == 0) {
fprintf(stderr
, "usage: routed [ -s ] [ -q ] [ -t ]\n");
ioctl(t
, TIOCNOTTY
, (char *)0);
* Any extra argument is considered
* 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_vers
= RIPVERSION
;
msg
->rip_nets
[0].rip_dst
.sa_family
= AF_UNSPEC
;
msg
->rip_nets
[0].rip_metric
= HOPCNT_INFINITY
;
msg
->rip_nets
[0].rip_dst
.sa_family
= htons(AF_UNSPEC
);
msg
->rip_nets
[0].rip_metric
= htonl(HOPCNT_INFINITY
);
n
= select(20, &ibits
, 0, 0, 0);
if (ibits
& (1 << snoroute
))
/* handle ICMP redirects */
int fromlen
= sizeof (from
), cc
, omask
;
cc
= recvfrom(fd
, packet
, sizeof (packet
), 0, &from
, &fromlen
);
if (cc
< 0 && errno
!= EINTR
)
if (fromlen
!= sizeof (struct sockaddr_in
))
#define mask(s) (1<<((s)-1))
omask
= sigblock(mask(SIGALRM
));
getsocket(domain
, type
, sin
)
while ((s
= socket(domain
, type
, 0, 0)) < 0 && retry
) {
while (bind(s
, sin
, sizeof (*sin
), 0) < 0 && retry
) {