]> arthur.barton.de Git - netatalk.git/blobdiff - etc/atalkd/config.c
Several small fixes, from Riccardo Magliocchetti
[netatalk.git] / etc / atalkd / config.c
index e0e3e0da709d4d70f5a88b1c03cea02de7be5106..4005d6995631e8256608262dc457300a7623f5b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: config.c,v 1.15 2008-11-14 10:29:08 didg Exp $
+ * $Id: config.c,v 1.20 2009-10-29 11:35:58 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved. See COPYRIGHT.
@@ -67,11 +67,18 @@ char *strchr (), *strrchr ();
 #define IFF_SLAVE 0
 #endif /* IFF_SLAVE */
 
-int    router(), dontroute(), seed(), phase(), net(), addr(), zone(), noallmulti();
+int router(struct interface *iface, char **av);
+int dontroute(struct interface *iface, char **av);
+int seed(struct interface *iface, char **av);
+int phase(struct interface *iface, char **av); 
+int net(struct interface *iface, char **av);
+int addr(struct interface *iface, char **av); 
+int zone(struct interface *iface, char **av);
+int noallmulti(struct interface *iface, char **av);
 
 static const struct param {
     char       *p_name;
-    int                (*p_func)();
+    int                (*p_func)(struct interface *iface, char **av);
 } params[] = {
     { "router", router },
     { "dontroute", dontroute },
@@ -85,7 +92,7 @@ static const struct param {
 
 #define ARGV_CHUNK_SIZE 128
 #define MAXLINELEN 2048
-char **parseline(const char *line)
+static char **parseline(const char *line)
 {
     const char  *p;
     int                  argc = 0;
@@ -165,7 +172,7 @@ char **parseline(const char *line)
     return argv;
 }
 
-void freeline( char **argv )
+static void freeline( char **argv )
 {
     char **tmp = argv;
 
@@ -178,8 +185,7 @@ void freeline( char **argv )
     }
 }
 
-int writeconf( cf )
-    char       *cf;
+int writeconf(char *cf)
 {
     struct stat                st;
     char               *path, *p, newpath[ MAXPATHLEN ], line[ MAXLINELEN ];
@@ -321,8 +327,7 @@ int writeconf( cf )
  * zone for an interface is the first zone encountered for that
  * interface.
  */
-int readconf( cf )
-    char               *cf;
+int readconf(char *cf)
 {
     struct ifreq       ifr;
     struct interface   *iface, *niface;
@@ -474,9 +479,7 @@ read_conf_err:
     return -1;
 }
 
-int noallmulti( iface, av )
-    struct interface   *iface;
-    char               **av _U_;
+int noallmulti( struct interface *iface, char **av _U_)
 {
     /* Linux specific, no effect on other platforms */
     iface->i_flags &= !IFACE_ALLMULTI;
@@ -485,9 +488,7 @@ int noallmulti( iface, av )
 }
        
 /*ARGSUSED*/
-int router( iface, av )
-    struct interface   *iface;
-    char               **av _U_;
+int router(struct interface *iface, char **av _U_)
 {
     /* make sure "-router" and "-dontroute" aren't both on the same line. */
     if (iface->i_flags & IFACE_DONTROUTE) {
@@ -509,9 +510,7 @@ int router( iface, av )
 }
 
 /*ARGSUSED*/
-int dontroute( iface, av )
-    struct interface   *iface;
-    char               **av _U_;
+int dontroute(struct interface *iface, char **av _U_)
 {
     /* make sure "-router" and "-dontroute" aren't both on the same line. */
     if (iface->i_flags & IFACE_RSEED) {
@@ -524,9 +523,7 @@ int dontroute( iface, av )
 }
 
 /*ARGSUSED*/
-int seed( iface, av )
-    struct interface   *iface;
-    char               **av _U_;
+int seed( struct interface *iface, char **av _U_)
 {
     /*
      * Check to be sure "-seed" is before "-zone". we keep the old
@@ -542,9 +539,7 @@ int seed( iface, av )
     return( 1 );
 }
 
-int phase( iface, av )
-    struct interface   *iface;
-    char               **av;
+int phase(struct interface *iface, char **av)
 {
     int                        n;
     char               *pnum;
@@ -570,9 +565,7 @@ int phase( iface, av )
     return( 2 );
 }
 
-int net( iface, av )
-    struct interface   *iface;
-    char               **av;
+int net(struct interface *iface, char **av)
 {
     char               *nrange;
     char               *stop;
@@ -583,7 +576,7 @@ int net( iface, av )
        return -1;
     }
 
-    if (( stop = strchr( nrange, '-' )) != 0 ) {
+    if (( stop = strchr( nrange, '-' )) != NULL ) {
        stop++;
     }
     net = atoi( nrange );
@@ -598,7 +591,7 @@ int net( iface, av )
     }
 
     if ( iface->i_flags & IFACE_PHASE1 ) {
-       if ( stop != 0 ) {
+       if ( stop != NULL ) {
            fprintf( stderr, "Phase 1 doesn't use an address range.\n" );
            return -1;
        }
@@ -611,7 +604,7 @@ int net( iface, av )
        iface->i_rt->rt_firstnet = iface->i_rt->rt_lastnet = htons( net );
     } else if ( iface->i_flags & IFACE_PHASE2 ) {
        iface->i_rt->rt_firstnet = htons( net );
-       if ( stop != 0 ) {
+       if ( stop != NULL ) {
            net = atoi( stop );
            if ( net < 0 || net >= 0xffff ) {
                fprintf( stderr, "Bad network: %d\n", net );
@@ -640,9 +633,7 @@ int net( iface, av )
     return( 2 );
 }
 
-int addr( iface, av )
-    struct interface   *iface;
-    char               **av;
+int addr(struct interface *iface, char **av)
 {
     if ( av[ 0 ] == NULL ) {
        fprintf( stderr, "No address.\n" );
@@ -676,9 +667,7 @@ int addr( iface, av )
     return( 2 );
 }
 
-int zone( iface, av )
-    struct interface   *iface;
-    char               **av;
+int zone(struct interface *iface, char **av)
 {
     struct ziptab      *zt;
     char               *zname;
@@ -689,7 +678,7 @@ int zone( iface, av )
     }
 
     /* codepage conversion */
-    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, CH_MAC, av[0], strlen(av[0]), &zname)) {
+    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, CH_MAC, av[0], -1, &zname)) {
        zname = strdup(av[0]);
     }
 
@@ -724,7 +713,7 @@ int zone( iface, av )
  * Get the configuration from the kernel. Only called if there's no
  * configuration.
  */
-int getifconf()
+int getifconf(void)
 {
     struct interface   *iface, *niface;
     struct ifreq        ifr;
@@ -804,8 +793,7 @@ int getifconf()
  * the interface structure and have it updated nicely.
  */
 
-struct interface *newiface( name )
-    const char         *name;
+struct interface *newiface( const char *name)
 {
     struct interface   *niface;
 
@@ -829,11 +817,12 @@ struct interface *newiface( name )
 }
 
 #ifdef __svr4__
-int plumb()
+int plumb(void)
 {
     struct interface   *iface;
-    char               device[ MAXPATHLEN + 1], *p;
+    char               device[ MAXPATHLEN + 1], *p, *t;
     int                        fd, ppa;
+    int                        digits = 0;
 
     for ( iface = interfaces; iface != NULL; iface = iface->i_next ) {
        if ( strcmp( iface->i_name, LOOPIFACE ) == 0 ) {
@@ -842,7 +831,16 @@ int plumb()
 
        strcpy( device, "/dev/" );
        strcat( device, iface->i_name );
-       if (( p = strpbrk( device, "0123456789" )) == NULL ) {
+       for (t = device; *t != '\0' ; ++t) {
+           if (isdigit(*t) == 0) {
+               p = t + 1;
+           }
+           else {
+               digits++;
+           }
+       }
+
+       if (digits == 0) {
            LOG(log_error, logtype_atalkd, "plumb: invalid device: %s", device );
            return -1;
        }
@@ -873,6 +871,8 @@ int plumb()
        }
 
        LOG(log_info, logtype_atalkd, "plumbed %s%d", device, ppa );
+
+    close(fd);
     }
 
     return( 0 );