]> arthur.barton.de Git - netatalk.git/blobdiff - etc/atalkd/main.c
autoconf POSIX.1 sys/wait.h check
[netatalk.git] / etc / atalkd / main.c
index a05e908f413772396d455063c2eabc961e42a178..64f81948d09f9a96b73c5fceef2024c5b9cf2803 100644 (file)
@@ -1,21 +1,42 @@
 /*
+ * $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>
 
@@ -41,7 +62,7 @@
 #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
@@ -101,6 +126,12 @@ char               *version = VERSION;
 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)
@@ -114,14 +145,14 @@ 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);
@@ -130,7 +161,7 @@ static void atalkd_exit(const int i)
 
 #if !defined( ibm032 ) && !defined( _IBMR2 )
     void
-#endif ibm032 _IBMR2
+#endif /* ibm032 _IBMR2 */
 as_timer()
 {
     struct sockaddr_at sat;
@@ -487,7 +518,7 @@ as_timer()
        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;
@@ -635,7 +666,7 @@ as_timer()
 
 #ifdef DEBUG
     consistency();
-#endif DEBUG
+#endif /* DEBUG */
 }
 
 #ifdef DEBUG
@@ -672,11 +703,11 @@ consistency()
        }
     }
 }
-#endif DEBUG
+#endif /* DEBUG */
 
 #if !defined( ibm032 ) && !defined( _IBMR2 )
     void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
 as_debug()
 {
     struct interface   *iface;
@@ -780,7 +811,7 @@ as_debug()
  */
 #if !defined( ibm032 ) && !defined( _IBMR2 )
     void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
 as_down()
 {
     struct interface   *iface;
@@ -812,7 +843,7 @@ as_down()
     atalkd_exit( 0 );
 }
 
-main( ac, av )
+int main( ac, av )
     int                ac;
     char       **av;
 {
@@ -985,7 +1016,7 @@ main( ac, av )
        fprintf(stderr, "can't establish STREAMS plumbing, exiting.\n" );
        atalkd_exit( 1 );
     }
-#endif __svr4__
+#endif /* __svr4__ */
 
     /* delete pre-existing interface addresses. */
 #ifdef SIOCDIFADDR
@@ -994,11 +1025,11 @@ main( ac, av )
 #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
@@ -1038,9 +1069,9 @@ main( ac, av )
 
 #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 );
 
@@ -1057,12 +1088,12 @@ main( ac, av )
        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;
@@ -1139,16 +1170,16 @@ main( ac, av )
                                    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);
@@ -1156,15 +1187,15 @@ main( ac, av )
 
 #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__ */
                    }
                }
            }
@@ -1177,7 +1208,7 @@ main( ac, av )
  * and rtmp_packet()) to set the initial "bootstrapping" address
  * on an interface.
  */
-bootaddr( iface )
+void bootaddr( iface )
     struct interface   *iface;
 {
     if ( iface == 0 ) {
@@ -1233,7 +1264,7 @@ bootaddr( iface )
  * 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;
@@ -1275,7 +1306,7 @@ setaddr( iface, phase, net, node, first, last )
 
 #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;
@@ -1297,22 +1328,22 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last));
 
     /* 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;
@@ -1330,11 +1361,11 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last));
 #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 );
        }
     }
@@ -1352,8 +1383,8 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last));
     nfds++;
 }
 
-ifconfig( iname, cmd, sa )
-    char               *iname;
+int ifconfig( iname, cmd, sa )
+    const char         *iname;
     unsigned long      cmd;
     struct sockaddr_at *sa;
 {
@@ -1378,7 +1409,7 @@ ifconfig( iname, cmd, sa )
     return( 0 );
 }
 
-dumpconfig( iface )
+void dumpconfig( iface )
     struct interface   *iface;
 {
     struct list                *l;
@@ -1415,7 +1446,7 @@ dumpconfig( iface )
 }
 
 #ifdef DEBUG
-dumproutes()
+void dumproutes()
 {
     struct interface   *iface;
     struct rtmptab     *rtmp;
@@ -1463,7 +1494,7 @@ dumproutes()
     fflush( stdout );
 }
 
-dumpzones()
+void dumpzones()
 {
     struct interface   *iface;
     struct rtmptab     *rtmp;
@@ -1490,4 +1521,4 @@ dumpzones()
     printf( "\n" );
     fflush( stdout );
 }
-#endif DEBUG
+#endif /* DEBUG */