/*
+ * $Id: main.c,v 1.8 2001-09-06 19:04:39 rufustfirefly Exp $
+ *
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
-#include <sys/types.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include <sys/param.h>
#include <sys/socket.h>
#if defined( sun ) && defined( __svr4__ )
#include </usr/ucbinclude/sys/file.h>
-#else sun __svr4__
+#else /* sun __svr4__ */
#include <sys/file.h>
-#endif sun __svr4__
+#endif /* sun __svr4__ */
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ioctl.h>
+
+/* POSIX.1 check */
+#include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
+#endif /* HAVE_SYS_WAIT_H */
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+#endif /* ! WEXITSTATUS */
+#ifndef WIFEXITED
+#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif /* ! WIFEXITED */
+
#include <errno.h>
+#ifdef TRU64
+#include <sys/mbuf.h>
+#include <net/route.h>
+#endif /* TRU64 */
#include <net/if.h>
#include <net/route.h>
#ifdef __svr4__
#include <sys/sockio.h>
#include <termios.h>
-#endif __svr4__
+#endif /* __svr4__ */
#include "interface.h"
#include "gate.h"
#include "rtmp.h"
#include "zip.h"
#include "atserv.h"
+#include "main.h"
+
+/* Forward Declarations */
+int ifconfig(const char *iname, unsigned long cmd, struct sockaddr_at *sa);
/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature */
#ifndef SOCKLEN_T
#define SOCKLEN_T unsigned int
-#endif
+#endif /* SOCKLEN_T */
#ifndef WEXITSTATUS
#define WEXITSTATUS(x) ((x).w_retcode)
-#endif WEXITSTATUS
+#endif /* WEXITSTATUS */
/* linux has a special ioctl for appletalk device destruction. as of
* 2.1.57, SIOCDIFADDR works w/ linux. okay, we need to deal with the
static char *pidfile = _PATH_ATALKDLOCK;
+/* from config.c */
+
+int readconf( char * );
+int getifconf( void );
+int writeconf( char * );
+
/* this is the messiest of the bunch as atalkd can exit pretty much
* everywhere. we delete interfaces here instead of in as_down. */
static void atalkd_exit(const int i)
#if (SIOCDIFADDR != SIOCATALKDIFADDR)
if (!ifconfig(iface->i_name, SIOCATALKDIFADDR, &iface->i_addr))
continue;
-#endif
-#endif
+#endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
+#endif /* SIOCATALKIFADDR */
syslog( LOG_ERR, "difaddr(%u.%u): %m",
ntohs(iface->i_addr.sat_addr.s_net),
iface->i_addr.sat_addr.s_node);
}
}
-#endif
+#endif /* SOPCDOFADDR */
server_unlock(pidfile);
exit(i);
#if !defined( ibm032 ) && !defined( _IBMR2 )
void
-#endif ibm032 _IBMR2
+#endif /* ibm032 _IBMR2 */
as_timer()
{
struct sockaddr_at sat;
if ((iface->i_flags & IFACE_ISROUTER)) {
#ifdef BSD4_4
sat.sat_len = sizeof( struct sockaddr_at );
-#endif BSD4_4
+#endif /* BSD4_4 */
sat.sat_family = AF_APPLETALK;
sat.sat_addr.s_net = ATADDR_ANYNET;
sat.sat_addr.s_node = ATADDR_BCAST;
#ifdef DEBUG
consistency();
-#endif DEBUG
+#endif /* DEBUG */
}
#ifdef DEBUG
}
}
}
-#endif DEBUG
+#endif /* DEBUG */
#if !defined( ibm032 ) && !defined( _IBMR2 )
void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
as_debug()
{
struct interface *iface;
*/
#if !defined( ibm032 ) && !defined( _IBMR2 )
void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
as_down()
{
struct interface *iface;
atalkd_exit( 0 );
}
-main( ac, av )
+int main( ac, av )
int ac;
char **av;
{
fprintf(stderr, "can't establish STREAMS plumbing, exiting.\n" );
atalkd_exit( 1 );
}
-#endif __svr4__
+#endif /* __svr4__ */
/* delete pre-existing interface addresses. */
#ifdef SIOCDIFADDR
#ifdef SIOCATALKDIFADDR
#if (SIOCDIFADDR != SIOCATALKDIFADDR)
ifconfig(iface->i_name, SIOCATALKDIFADDR, &iface->i_addr);
-#endif
-#endif
+#endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
+#endif /* SIOCATALKDIFADDR */
}
}
-#endif
+#endif /* SIOCDIFADDR */
/*
* Disassociate. The child will send itself a signal when it is
#ifdef ultrix
openlog( prog, LOG_PID );
-#else ultrix
+#else /* ultrix */
openlog( prog, LOG_PID, LOG_DAEMON );
-#endif ultrix
+#endif /* ultrix */
syslog( LOG_INFO, "restart (%s)", version );
syslog( LOG_ERR, "route shutdown: %m" );
atalkd_exit( 1 );
}
-#else BSD4_4
+#else /* BSD4_4 */
if (( rtfd = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
syslog( LOG_ERR, "route socket: %m" );
atalkd_exit( 1 );
}
-#endif BSD4_4
+#endif /* BSD4_4 */
memset(&sv, 0, sizeof(sv));
sv.sa_handler = as_down;
iface->i_flags, ap->ap_port, ap->ap_fd );
bprint( Packet, c );
}
-#endif DEBUG
+#endif /* DEBUG */
#ifdef __svr4__
if ( sighold( SIGALRM ) || sighold( SIGUSR1 )) {
syslog( LOG_ERR, "sighold: %m" );
atalkd_exit( 1 );
}
-#else __svr4__
+#else /* __svr4__ */
mask = sigsetmask( sigmask( SIGALRM ) |
sigmask( SIGUSR1 ));
-#endif __svr4__
+#endif /* __svr4__ */
if (( *ap->ap_packet )( ap, &sat, Packet, c ) < 0) {
syslog(LOG_ERR, "ap->ap_packet: %m");
atalkd_exit(1);
#ifdef DEBUG
consistency();
-#endif DEBUG
+#endif /* DEBUG */
#ifdef __svr4__
if ( sigrelse( SIGUSR1 ) || sigrelse( SIGALRM )) {
syslog( LOG_ERR, "sigrelse: %m" );
atalkd_exit( 1 );
}
-#else __svr4__
+#else /* __svr4__ */
sigsetmask( mask );
-#endif __svr4__
+#endif /* __svr4__ */
}
}
}
* and rtmp_packet()) to set the initial "bootstrapping" address
* on an interface.
*/
-bootaddr( iface )
+void bootaddr( iface )
struct interface *iface;
{
if ( iface == 0 ) {
* Change setaddr()
* to manage the i_ports field and the fds for select().
*/
-setaddr( iface, phase, net, node, first, last )
+void setaddr( iface, phase, net, node, first, last )
struct interface *iface;
u_int8_t phase;
u_int16_t net;
#ifdef BSD4_4
iface->i_addr.sat_len = sizeof( struct sockaddr_at );
-#endif BSD4_4
+#endif /* BSD4_4 */
iface->i_addr.sat_family = AF_APPLETALK;
iface->i_addr.sat_addr.s_net = net;
iface->i_addr.sat_addr.s_node = node;
/* open ports */
i = 1; /* enable broadcasts */
-#if defined(__svr4__)
+#ifdef __svr4__
syslog(LOG_INFO, "setsockopt incompatible w/ Solaris STREAMS module.");
-#endif
+#endif /* __svr4__ */
for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
if (( ap->ap_fd = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
syslog( LOG_ERR, "socket: %m" );
atalkd_exit( 1 );
}
-#if !defined(__svr4__)
+#ifndef __svr4__
setsockopt(ap->ap_fd, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i));
-#endif
+#endif /* ! __svr4 */
memset( &sat, 0, sizeof( struct sockaddr_at ));
#ifdef BSD4_4
sat.sat_len = sizeof( struct sockaddr_at );
-#endif BSD4_4
+#endif /* BSD4_4 */
sat.sat_family = AF_APPLETALK;
sat.sat_addr.s_net = iface->i_addr.sat_addr.s_net;
sat.sat_addr.s_node = iface->i_addr.sat_addr.s_node;
#ifdef SIOCATALKDIFADDR
#if (SIOCDIFADDR != SIOCATALKDIFADDR)
ifconfig( iface->i_name, SIOCATALKDIFADDR, &iface->i_addr );
-#endif
-#endif
+#endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
+#endif /* SIOCATALKDIFADDR */
}
}
-#endif
+#endif /* SIOCDIFADDR */
atalkd_exit( 1 );
}
}
nfds++;
}
-ifconfig( iname, cmd, sa )
- char *iname;
+int ifconfig( iname, cmd, sa )
+ const char *iname;
unsigned long cmd;
struct sockaddr_at *sa;
{
return( 0 );
}
-dumpconfig( iface )
+void dumpconfig( iface )
struct interface *iface;
{
struct list *l;
}
#ifdef DEBUG
-dumproutes()
+void dumproutes()
{
struct interface *iface;
struct rtmptab *rtmp;
fflush( stdout );
}
-dumpzones()
+void dumpzones()
{
struct interface *iface;
struct rtmptab *rtmp;
printf( "\n" );
fflush( stdout );
}
-#endif DEBUG
+#endif /* DEBUG */