* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.6 (Berkeley) %G%";
* Routing Table Management Daemon
int supplier
= -1; /* process should supply updates */
int gateway
= 0; /* 1 if we are a gateway to parts beyond */
struct rip
*msg
= (struct rip
*)packet
;
openlog("routed", LOG_PID
| LOG_ODELAY
, LOG_DAEMON
);
setlogmask(LOG_UPTO(LOG_WARNING
));
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
);
while (argc
> 0 && **argv
== '-') {
if (strcmp(*argv
, "-s") == 0) {
if (strcmp(*argv
, "-q") == 0) {
if (strcmp(*argv
, "-t") == 0) {
setlogmask(LOG_UPTO(LOG_DEBUG
));
if (strcmp(*argv
, "-d") == 0) {
setlogmask(LOG_UPTO(LOG_DEBUG
));
if (strcmp(*argv
, "-g") == 0) {
"usage: routed [ -s ] [ -q ] [ -t ] [ -g ]\n");
ioctl(t
, TIOCNOTTY
, (char *)0);
* Any extra argument is considered
* Collect an initial view of the world by
* checking the interface configuration 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);
/* 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
))
omask
= sigblock(sigmask(SIGALRM
));
getsocket(domain
, type
, sin
)
if ((s
= socket(domain
, type
, 0)) < 0) {
syslog(LOG_ERR
, "socket: %m");
if (setsockopt(s
, SOL_SOCKET
, SO_BROADCAST
, &on
, sizeof (on
)) < 0) {
syslog(LOG_ERR
, "setsockopt SO_BROADCAST: %m");
if (bind(s
, sin
, sizeof (*sin
), 0) < 0) {
syslog(LOG_ERR
, "bind: %m");