2004-10-10 Paul Jakma <paul@dishone.st>

	* version.h.in: (pid_output*) add const qualifier.
	* command.h: Change DEFUN func to take const char *[] rather
          than char **, to begin process of fixing compile warnings in lib/.
          Nearly all other changes in this commit follow from this change.
        * buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
          const void * and cast an automatic const char *p to it.
          (buffer_putstr) add const
        * command.c: (zencrypt) const qualifier
          (cmd_execute_command_real) ditto
          (cmd_execute_command_strict) ditto
          (config_log_file) ditto.
          Fix leak of getcwd() returned string.
        * memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
        * distribute.{c,h}: Update with const qualifier.
          (distribute_free) use MTYPE_DISTRIBUTE_IFNAME
          (distribute_lookup) Cast to char *, note that it's ok.
          (distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
          (distribute_get)  Cast to char *, note that it's ok.
        * filter.c: Update with const qualifier.
        * if.{c,h}: ditto.
        * if_rmap.{c,h}: ditto.
          (if_rmap_lookup) Cast to char *, note that it's ok.
          (if_rmap_get) ditto.
        * log.{c,h}: Update with const qualifier.
        * plist.{c,h}: ditto.
        * routemap.{c,h}: ditto.
        * smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
        * sockopt.c: (getsockopt_cmsg_data) add return for error case.
        * vty.c: Update with const qualifier.
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 05317db..dc8fae8 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,7 +1,35 @@
-2004-10-05 Paul Jakma <paul@dishone.st>
+2004-10-10 Paul Jakma <paul@dishone.st>
 
 	* version.h.in: (pid_output*) add const qualifier.
-
+	* command.h: Change DEFUN func to take const char *[] rather
+          than char **, to begin process of fixing compile warnings in lib/.
+          Nearly all other changes in this commit follow from this change.
+        * buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
+          const void * and cast an automatic const char *p to it.
+          (buffer_putstr) add const
+        * command.c: (zencrypt) const qualifier
+          (cmd_execute_command_real) ditto
+          (cmd_execute_command_strict) ditto
+          (config_log_file) ditto. 
+          Fix leak of getcwd() returned string.
+        * memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
+        * distribute.{c,h}: Update with const qualifier.
+          (distribute_free) use MTYPE_DISTRIBUTE_IFNAME
+          (distribute_lookup) Cast to char *, note that it's ok.
+          (distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
+          (distribute_get)  Cast to char *, note that it's ok.
+        * filter.c: Update with const qualifier.
+        * if.{c,h}: ditto.
+        * if_rmap.{c,h}: ditto.
+          (if_rmap_lookup) Cast to char *, note that it's ok.
+          (if_rmap_get) ditto.
+        * log.{c,h}: Update with const qualifier.
+        * plist.{c,h}: ditto.
+        * routemap.{c,h}: ditto.
+        * smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
+        * sockopt.c: (getsockopt_cmsg_data) add return for error case.
+        * vty.c: Update with const qualifier.
+          
 2004-10-08 Hasso Tepper <hasso at quagga.net>
 
 	* routemap.c, routemap.h: Make some string arguments const.
diff --git a/lib/buffer.c b/lib/buffer.c
index 6fd9a2b..904b4aa 100644
--- a/lib/buffer.c
+++ b/lib/buffer.c
@@ -149,10 +149,10 @@
 
 /* Write data to buffer. */
 int
-buffer_write (struct buffer *b, void *ptr, size_t size)
+buffer_write (struct buffer *b, const void *p, size_t size)
 {
   struct buffer_data *data;
-
+  const char *ptr = p;
   data = b->tail;
   b->length += size;
 
@@ -205,7 +205,7 @@
 
 /* Put string to the buffer. */
 int
-buffer_putstr (struct buffer *b, char *c)
+buffer_putstr (struct buffer *b, const char *c)
 {
   size_t size;
 
diff --git a/lib/buffer.h b/lib/buffer.h
index eaf4b88..9d453b1 100644
--- a/lib/buffer.h
+++ b/lib/buffer.h
@@ -63,11 +63,11 @@
 
 /* Buffer prototypes. */
 struct buffer *buffer_new (size_t);
-int buffer_write (struct buffer *, void *, size_t);
+int buffer_write (struct buffer *, const void *, size_t);
 void buffer_free (struct buffer *);
 char *buffer_getstr (struct buffer *);
 int buffer_putc (struct buffer *, u_char);
-int buffer_putstr (struct buffer *, char *);
+int buffer_putstr (struct buffer *, const char *);
 void buffer_reset (struct buffer *);
 int buffer_flush_all (struct buffer *, int);
 int buffer_flush_vty_all (struct buffer *, int, int, int);
diff --git a/lib/command.c b/lib/command.c
index 2766a35..168fe56 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -432,7 +432,7 @@
     }
 }
 
-char *zencrypt (char *passwd)
+char *zencrypt (const char *passwd)
 {
   char salt[6];
   struct timeval tv;
@@ -1932,7 +1932,7 @@
   struct cmd_element *matched_element;
   unsigned int matched_count, incomplete_count;
   int argc;
-  char *argv[CMD_ARGC_MAX];
+  const char *argv[CMD_ARGC_MAX];
   enum match_type match = 0;
   int varflag;
   char *command;
@@ -2111,7 +2111,7 @@
   struct cmd_element *matched_element;
   unsigned int matched_count, incomplete_count;
   int argc;
-  char *argv[CMD_ARGC_MAX];
+  const char *argv[CMD_ARGC_MAX];
   int varflag;
   enum match_type match = 0;
   char *command;
@@ -2983,22 +2983,38 @@
        "Logging filename\n")
 {
   int ret;
-  char *cwd;
-  char *fullpath;
-
+  char *p = NULL;
+  const char *fullpath;
+  
   /* Path detection. */
   if (! IS_DIRECTORY_SEP (*argv[0]))
     {
-      cwd = getcwd (NULL, MAXPATHLEN);
-      fullpath = XMALLOC (MTYPE_TMP,
-			  strlen (cwd) + strlen (argv[0]) + 2);
-      sprintf (fullpath, "%s/%s", cwd, argv[0]);
+      char cwd[MAXPATHLEN+1];
+      cwd[MAXPATHLEN] = '\0';
+      
+      if (getcwd (cwd, MAXPATHLEN) == NULL)
+        {
+          zlog_err ("config_log_file: Unable to alloc mem!");
+          return CMD_WARNING;
+        }
+      
+      if ( (p = XMALLOC (MTYPE_TMP, strlen (cwd) + strlen (argv[0]) + 2))
+          == NULL)
+        {
+          zlog_err ("config_log_file: Unable to alloc mem!");
+          return CMD_WARNING;
+        }
+      sprintf (p, "%s/%s", cwd, argv[0]);
+      fullpath = p;
     }
   else
     fullpath = argv[0];
 
   ret = zlog_set_file (NULL, ZLOG_FILE, fullpath);
 
+  if (p)
+    XFREE (MTYPE_TMP, p);
+
   if (!ret)
     {
       vty_out (vty, "can't open logfile %s\n", argv[0]);
diff --git a/lib/command.h b/lib/command.h
index 9e727cf..0f806c8 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -129,7 +129,7 @@
 struct cmd_element 
 {
   const char *string;			/* Command specification by string. */
-  int (*func) (struct cmd_element *, struct vty *, int, char **);
+  int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
   const char *doc;			/* Documentation of this command. */
   int daemon;                   /* Daemon to which this command belong. */
   vector strvec;		/* Pointing out each description vector. */
@@ -166,15 +166,15 @@
 
 /* DEFUN for vty command interafce. Little bit hacky ;-). */
 #define DEFUN(funcname, cmdname, cmdstr, helpstr) \
-  int funcname (struct cmd_element *, struct vty *, int, char **); \
+  int funcname (struct cmd_element *, struct vty *, int, const char *[]); \
   struct cmd_element cmdname = \
   { \
-    cmdstr, \
-    funcname, \
-    helpstr \
+    .string = cmdstr, \
+    .func = funcname, \
+    .doc = helpstr \
   }; \
   int funcname \
-  (struct cmd_element *self, struct vty *vty, int argc, char **argv)
+  (struct cmd_element *self, struct vty *vty, int argc, const char *argv[])
 
 /* DEFUN_NOSH for commands that vtysh should ignore */
 #define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
@@ -304,8 +304,8 @@
 extern struct cmd_element config_quit_cmd;
 extern struct cmd_element config_help_cmd;
 extern struct cmd_element config_list_cmd;
-int config_exit (struct cmd_element *, struct vty *, int, char **);
-int config_help (struct cmd_element *, struct vty *, int, char **);
+int config_exit (struct cmd_element *, struct vty *, int, const char *[]);
+int config_help (struct cmd_element *, struct vty *, int, const char *[]);
 char *host_config_file ();
 void host_config_set (char *);
 
diff --git a/lib/distribute.c b/lib/distribute.c
index 78de4bf..48eb040 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -51,7 +51,7 @@
 distribute_free (struct distribute *dist)
 {
   if (dist->ifname)
-    free (dist->ifname);
+    XFREE (MTYPE_DISTRIBUTE_IFNAME, dist->ifname);
 
   if (dist->list[DISTRIBUTE_IN])
     free (dist->list[DISTRIBUTE_IN]);
@@ -68,12 +68,13 @@
 
 /* Lookup interface's distribute list. */
 struct distribute *
-distribute_lookup (char *ifname)
+distribute_lookup (const char *ifname)
 {
   struct distribute key;
   struct distribute *dist;
 
-  key.ifname = ifname;
+  /* temporary reference */
+  key.ifname = (char *)ifname;
 
   dist = hash_lookup (disthash, &key);
   
@@ -99,7 +100,7 @@
 
   dist = distribute_new ();
   if (arg->ifname)
-    dist->ifname = strdup (arg->ifname);
+    dist->ifname = XSTRDUP (MTYPE_DISTRIBUTE_IFNAME, arg->ifname);
   else
     dist->ifname = NULL;
   return dist;
@@ -107,12 +108,13 @@
 
 /* Make new distribute list and push into hash. */
 struct distribute *
-distribute_get (char *ifname)
+distribute_get (const char *ifname)
 {
   struct distribute key;
 
-  key.ifname = ifname;
-
+  /* temporary reference */
+  key.ifname = (char *)ifname;
+  
   return hash_get (disthash, &key, distribute_hash_alloc);
 }
 
@@ -144,7 +146,8 @@
 
 /* Set access-list name to the distribute list. */
 struct distribute *
-distribute_list_set (char *ifname, enum distribute_type type, char *alist_name)
+distribute_list_set (const char *ifname, enum distribute_type type, 
+                     const char *alist_name)
 {
   struct distribute *dist;
 
@@ -172,8 +175,8 @@
 /* Unset distribute-list.  If matched distribute-list exist then
    return 1. */
 int
-distribute_list_unset (char *ifname, enum distribute_type type, 
-		       char *alist_name)
+distribute_list_unset (const char *ifname, enum distribute_type type, 
+		       const char *alist_name)
 {
   struct distribute *dist;
 
@@ -221,8 +224,8 @@
 
 /* Set access-list name to the distribute list. */
 struct distribute *
-distribute_list_prefix_set (char *ifname, enum distribute_type type,
-			    char *plist_name)
+distribute_list_prefix_set (const char *ifname, enum distribute_type type,
+			    const char *plist_name)
 {
   struct distribute *dist;
 
@@ -250,8 +253,8 @@
 /* Unset distribute-list.  If matched distribute-list exist then
    return 1. */
 int
-distribute_list_prefix_unset (char *ifname, enum distribute_type type,
-			      char *plist_name)
+distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
+			      const char *plist_name)
 {
   struct distribute *dist;
 
diff --git a/lib/distribute.h b/lib/distribute.h
index 330126b..77bb875 100644
--- a/lib/distribute.h
+++ b/lib/distribute.h
@@ -47,7 +47,7 @@
 void distribute_list_reset (void);
 void distribute_list_add_hook (void (*) (struct distribute *));
 void distribute_list_delete_hook (void (*) (struct distribute *));
-struct distribute *distribute_lookup (char *);
+struct distribute *distribute_lookup (const char *);
 int config_write_distribute (struct vty *);
 int config_show_distribute (struct vty *);
 
diff --git a/lib/filter.c b/lib/filter.c
index ee3dbc0..9817c07 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -569,7 +569,7 @@
 }
 
 int
-vty_access_list_remark_unset (struct vty *vty, afi_t afi, char *name)
+vty_access_list_remark_unset (struct vty *vty, afi_t afi, const char *name)
 {
   struct access_list *access;
 
@@ -594,7 +594,7 @@
 }
 
 int
-filter_set_cisco (struct vty *vty, char *name_str, char *type_str,
+filter_set_cisco (struct vty *vty, const char *name_str, const char *type_str,
 		  const char *addr_str, const char *addr_mask_str,
 		  const char *mask_str, const char *mask_mask_str,
 		  int extended, int set)
@@ -1596,7 +1596,7 @@
 
 /* show access-list command. */
 int
-filter_show (struct vty *vty, char *name, afi_t afi)
+filter_show (struct vty *vty, const char *name, afi_t afi)
 {
   struct access_list *access;
   struct access_master *master;
diff --git a/lib/if.c b/lib/if.c
index 8fbaa76..259b842 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -123,7 +123,7 @@
 }
 
 struct interface *
-if_create (char *name, int namelen)
+if_create (const char *name, int namelen)
 {
   struct interface *ifp;
 
@@ -208,7 +208,7 @@
 
 /* Interface existance check by interface name. */
 struct interface *
-if_lookup_by_name (char *name)
+if_lookup_by_name (const char *name)
 {
   struct listnode *node;
   struct interface *ifp;
@@ -320,7 +320,7 @@
 /* Get interface by name if given name interface doesn't exist create
    one. */
 struct interface *
-if_get_by_name (char *name)
+if_get_by_name (const char *name)
 {
   struct interface *ifp;
 
diff --git a/lib/if.h b/lib/if.h
index 47e992c..0f088a9 100644
--- a/lib/if.h
+++ b/lib/if.h
@@ -183,12 +183,12 @@
 /* Prototypes. */
 int if_cmp_func (struct interface *, struct interface *);
 struct interface *if_new (void);
-struct interface *if_create (char *name, int namelen);
+struct interface *if_create (const char *name, int namelen);
 struct interface *if_lookup_by_index (unsigned int);
-struct interface *if_lookup_by_name (char *);
+struct interface *if_lookup_by_name (const char *);
 struct interface *if_lookup_exact_address (struct in_addr);
 struct interface *if_lookup_address (struct in_addr);
-struct interface *if_get_by_name (char *);
+struct interface *if_get_by_name (const char *);
 void if_delete (struct interface *);
 int if_is_up (struct interface *);
 int if_is_running (struct interface *);
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index 0f3fa9c..3f95af3 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -58,12 +58,13 @@
 }
 
 struct if_rmap *
-if_rmap_lookup (char *ifname)
+if_rmap_lookup (const char *ifname)
 {
   struct if_rmap key;
   struct if_rmap *if_rmap;
 
-  key.ifname = ifname;
+  /* temporary copy */
+  key.ifname = (char *)ifname;
 
   if_rmap = hash_lookup (ifrmaphash, &key);
   
@@ -94,11 +95,12 @@
 }
 
 struct if_rmap *
-if_rmap_get (char *ifname)
+if_rmap_get (const char *ifname)
 {
   struct if_rmap key;
 
-  key.ifname = ifname;
+  /* temporary copy */
+  key.ifname = (char *)ifname;
 
   return (struct if_rmap *) hash_get (ifrmaphash, &key, if_rmap_hash_alloc);
 }
@@ -124,7 +126,8 @@
 }
 
 struct if_rmap *
-if_rmap_set (char *ifname, enum if_rmap_type type, char *routemap_name)
+if_rmap_set (const char *ifname, enum if_rmap_type type, 
+             const char *routemap_name)
 {
   struct if_rmap *if_rmap;
 
@@ -150,7 +153,8 @@
 }
 
 int
-if_rmap_unset (char *ifname, enum if_rmap_type type, char *routemap_name)
+if_rmap_unset (const char *ifname, enum if_rmap_type type, 
+               const char *routemap_name)
 {
   struct if_rmap *if_rmap;
 
diff --git a/lib/if_rmap.h b/lib/if_rmap.h
index a9355ab..540d68f 100644
--- a/lib/if_rmap.h
+++ b/lib/if_rmap.h
@@ -41,7 +41,7 @@
 void if_rmap_reset (void);
 void if_rmap_hook_add (void (*) (struct if_rmap *));
 void if_rmap_hook_delete (void (*) (struct if_rmap *));
-struct if_rmap *if_rmap_lookup (char *);
+struct if_rmap *if_rmap_lookup (const char *);
 int config_write_if_rmap (struct vty *);
 
 #endif /* _ZEBRA_IF_RMAP_H */
diff --git a/lib/log.c b/lib/log.c
index bbe6e99..375730f 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -366,7 +366,7 @@
 }
 
 int
-zlog_set_file (struct zlog *zl, int flags, char *filename)
+zlog_set_file (struct zlog *zl, int flags, const char *filename)
 {
   FILE *fp;
   mode_t oldumask;
diff --git a/lib/log.h b/lib/log.h
index e2eeb82..9f6ec3b 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -112,7 +112,7 @@
 void zlog_reset_flag (struct zlog *zl, int flags);
 
 /* Set zlog filename. */
-int zlog_set_file (struct zlog *zl, int flags, char *filename);
+int zlog_set_file (struct zlog *zl, int flags, const char *filename);
 int zlog_reset_file (struct zlog *zl);
 
 /* Rotate log. */
diff --git a/lib/memory.c b/lib/memory.c
index 8b311ae..bef0997 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -239,6 +239,8 @@
   { MTYPE_ROUTE_TABLE,        "Route table     " },
   { MTYPE_ROUTE_NODE,         "Route node      " },
   { MTYPE_RIB,                "RIB             " },
+  { MTYPE_DISTRIBUTE,         "Distribute list " },
+  { MTYPE_DISTRIBUTE_IFNAME,  "Dist-list ifname" },
   { MTYPE_NEXTHOP,            "Nexthop         " },
   { MTYPE_LINK_LIST,          "Link List       " },
   { MTYPE_LINK_NODE,          "Link Node       " },
diff --git a/lib/memory.h b/lib/memory.h
index c2d595a..2f403a1 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -75,7 +75,9 @@
   MTYPE_ROUTE_MAP_COMPILED,
 
   MTYPE_RIB,
+  
   MTYPE_DISTRIBUTE,
+  MTYPE_DISTRIBUTE_IFNAME,
   MTYPE_ZLOG,
   MTYPE_ZCLIENT,
   MTYPE_NEXTHOP,
diff --git a/lib/plist.c b/lib/plist.c
index ef2fffc..3520f82 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -126,7 +126,7 @@
 
 /* Lookup prefix_list from list of prefix_list by name. */
 struct prefix_list *
-prefix_list_lookup (afi_t afi, char *name)
+prefix_list_lookup (afi_t afi, const char *name)
 {
   struct prefix_list *plist;
   struct prefix_master *master;
@@ -182,7 +182,7 @@
 /* Insert new prefix list to list of prefix_list.  Each prefix_list
    is sorted by the name. */
 static struct prefix_list *
-prefix_list_insert (afi_t afi, char *name)
+prefix_list_insert (afi_t afi, const char *name)
 {
   unsigned int i;
   long number;
@@ -272,7 +272,7 @@
 }
 
 static struct prefix_list *
-prefix_list_get (afi_t afi, char *name)
+prefix_list_get (afi_t afi, const char *name)
 {
   struct prefix_list *plist;
 
@@ -647,7 +647,7 @@
 }
 
 static int
-vty_invalid_prefix_range (struct vty *vty, char *prefix)
+vty_invalid_prefix_range (struct vty *vty, const char *prefix)
 {
   vty_out (vty, "%% Invalid prefix range for %s, make sure: len < ge-value <= le-value%s",
            prefix, VTY_NEWLINE);
@@ -655,9 +655,9 @@
 }
 
 static int
-vty_prefix_list_install (struct vty *vty, afi_t afi,
-			 char *name, char *seq, char *typestr,
-			 char *prefix, char *ge, char *le)
+vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name, 
+                         const char *seq, const char *typestr,
+			 const char *prefix, const char *ge, const char *le)
 {
   int ret;
   enum prefix_list_type type;
@@ -774,9 +774,9 @@
 }
 
 static int
-vty_prefix_list_uninstall (struct vty *vty, afi_t afi,
-			   char *name, char *seq, char *typestr,
-			   char *prefix, char *ge, char *le)
+vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name, 
+                           const char *seq, const char *typestr,
+			   const char *prefix, const char *ge, const char *le)
 {
   int ret;
   enum prefix_list_type type;
@@ -878,7 +878,7 @@
 }
 
 static int
-vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, char *name)
+vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
 {
   struct prefix_list *plist;
 
@@ -982,8 +982,8 @@
 }
 
 static int
-vty_show_prefix_list (struct vty *vty, afi_t afi, char *name,
-		      char *seq, enum display_type dtype)
+vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
+		      const char *seq, enum display_type dtype)
 {
   struct prefix_list *plist;
   struct prefix_master *master;
@@ -1026,8 +1026,8 @@
 }
 
 static int
-vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, char *name, 
-			     char *prefix, enum display_type type)
+vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name, 
+			     const char *prefix, enum display_type type)
 {
   struct prefix_list *plist;
   struct prefix_list_entry *pentry;
@@ -1098,7 +1098,8 @@
 }
 
 static int
-vty_clear_prefix_list (struct vty *vty, afi_t afi, char *name, char *prefix)
+vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name, 
+                       const char *prefix)
 {
   struct prefix_master *master;
   struct prefix_list *plist;
diff --git a/lib/plist.h b/lib/plist.h
index 9a9eb71..01ac987 100644
--- a/lib/plist.h
+++ b/lib/plist.h
@@ -67,7 +67,7 @@
 void prefix_list_add_hook (void (*func) (struct prefix_list *));
 void prefix_list_delete_hook (void (*func) (struct prefix_list *));
 
-struct prefix_list *prefix_list_lookup (afi_t, char *);
+struct prefix_list *prefix_list_lookup (afi_t, const char *);
 enum prefix_list_type prefix_list_apply (struct prefix_list *, void *);
 
 struct stream *
diff --git a/lib/routemap.c b/lib/routemap.c
index 748aa2c..cd231be 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -57,9 +57,9 @@
   struct route_map *head;
   struct route_map *tail;
 
-  void (*add_hook) (char *);
-  void (*delete_hook) (char *);
-  void (*event_hook) (route_map_event_t, char *); 
+  void (*add_hook) (const char *);
+  void (*delete_hook) (const char *);
+  void (*event_hook) (route_map_event_t, const char *); 
 };
 
 /* Master list of route map. */
@@ -75,7 +75,7 @@
 /* New route map allocation. Please note route map's name must be
    specified. */
 static struct route_map *
-route_map_new (char *name)
+route_map_new (const char *name)
 {
   struct route_map *new;
 
@@ -86,7 +86,7 @@
 
 /* Add new name to route_map. */
 static struct route_map *
-route_map_add (char *name)
+route_map_add (const char *name)
 {
   struct route_map *map;
   struct route_map_list *list;
@@ -147,7 +147,7 @@
 
 /* Lookup route map by route map name string. */
 struct route_map *
-route_map_lookup_by_name (char *name)
+route_map_lookup_by_name (const char *name)
 {
   struct route_map *map;
 
@@ -160,7 +160,7 @@
 /* Lookup route map.  If there isn't route map create one and return
    it. */
 struct route_map *
-route_map_get (char *name)
+route_map_get (const char *name)
 {
   struct route_map *map;
 
@@ -241,7 +241,7 @@
 }
 
 int
-vty_show_route_map (struct vty *vty, char *name)
+vty_show_route_map (struct vty *vty, const char *name)
 {
   struct route_map *map;
 
@@ -852,19 +852,19 @@
 }
 
 void
-route_map_add_hook (void (*func) (char *))
+route_map_add_hook (void (*func) (const char *))
 {
   route_map_master.add_hook = func;
 }
 
 void
-route_map_delete_hook (void (*func) (char *))
+route_map_delete_hook (void (*func) (const char *))
 {
   route_map_master.delete_hook = func;
 }
 
 void
-route_map_event_hook (void (*func) (route_map_event_t, char *))
+route_map_event_hook (void (*func) (route_map_event_t, const char *))
 {
   route_map_master.event_hook = func;
 }
diff --git a/lib/routemap.h b/lib/routemap.h
index a6f3c5d..73874d6 100644
--- a/lib/routemap.h
+++ b/lib/routemap.h
@@ -185,16 +185,16 @@
 
 /* Lookup route map by name. */
 struct route_map *
-route_map_lookup_by_name (char *name);
+route_map_lookup_by_name (const char *name);
 
 /* Apply route map to the object. */
 route_map_result_t
 route_map_apply (struct route_map *map, struct prefix *, 
 		 route_map_object_t object_type, void *object);
 
-void route_map_add_hook (void (*func) (char *));
-void route_map_delete_hook (void (*func) (char *));
-void route_map_event_hook (void (*func) (route_map_event_t, char *));
+void route_map_add_hook (void (*func) (const char *));
+void route_map_delete_hook (void (*func) (const char *));
+void route_map_event_hook (void (*func) (route_map_event_t, const char *));
 
 
 #endif /* _ZEBRA_ROUTEMAP_H */
diff --git a/lib/smux.c b/lib/smux.c
index 7e0a2ec..5831b81 100644
--- a/lib/smux.c
+++ b/lib/smux.c
@@ -61,7 +61,7 @@
 
 /* SMUX password. */
 char *smux_passwd;
-char *smux_default_passwd = "";
+const char *smux_default_passwd = "";
 
 /* SMUX read threads. */
 struct thread *smux_read_thread;
@@ -160,9 +160,9 @@
 }
 
 void
-smux_oid_dump (char *prefix, oid *oid, size_t oid_len)
+smux_oid_dump (const char *prefix, oid *oid, size_t oid_len)
 {
-  int i;
+  unsigned int i;
   int first = 1;
   char buf[MAX_OID_LEN * 3];
 
@@ -1004,7 +1004,7 @@
 	   struct trap_object *trapobj, size_t trapobjlen,
 	   unsigned int tick, u_char sptrap)
 {
-  int i;
+  unsigned int i;
   u_char buf[BUFSIZ];
   u_char *ptr;
   int len, length;
@@ -1249,7 +1249,7 @@
 }
 
 int
-smux_str2oid (char *str, oid *oid, size_t *oid_len)
+smux_str2oid (const char *str, oid *oid, size_t *oid_len)
 {
   int len;
   int val;
@@ -1303,7 +1303,7 @@
 }
 
 int
-smux_peer_oid (struct vty *vty, char *oid_str, char *passwd_str)
+smux_peer_oid (struct vty *vty, const char *oid_str, const char *passwd_str)
 {
   int ret;
   oid oid[MAX_OID_LEN];
@@ -1319,6 +1319,7 @@
   if (smux_oid && smux_oid != smux_default_oid)
     free (smux_oid);
 
+  /* careful, smux_passwd might point to string constant */
   if (smux_passwd && smux_passwd != smux_default_passwd)
     {
       free (smux_passwd);
@@ -1369,10 +1370,12 @@
       smux_oid = smux_default_oid;
       smux_oid_len = smux_default_oid_len;
     }
+  
+  /* careful, smux_passwd might be pointing at string constant */
   if (smux_passwd != smux_default_passwd)
     {
       free (smux_passwd);
-      smux_passwd = smux_default_passwd;
+      smux_passwd = (char *)smux_default_passwd;
     }
   return CMD_SUCCESS;
 }
@@ -1425,7 +1428,7 @@
 config_write_smux (struct vty *vty)
 {
   int first = 1;
-  int i;
+  unsigned int i;
 
   if (smux_oid != smux_default_oid || smux_passwd != smux_default_passwd)
     {
@@ -1482,7 +1485,9 @@
 
   smux_oid = smux_default_oid;
   smux_oid_len = smux_default_oid_len;
-  smux_passwd = smux_default_passwd;
+
+  /* be careful with smux_passwd, points to string constant by default */
+  smux_passwd = (char *)smux_default_passwd;
 
   /* copy callers thread master */
   master = tm;
diff --git a/lib/sockopt.c b/lib/sockopt.c
index 5936d66..c448d30 100644
--- a/lib/sockopt.c
+++ b/lib/sockopt.c
@@ -46,6 +46,8 @@
        cmsg = CMSG_NXTHDR(msgh, cmsg))
     if (cmsg->cmsg_level == level && cmsg->cmsg_type)
       return (ptr = CMSG_DATA(cmsg));
+
+  return NULL;
 }
 
 #ifdef HAVE_IPV6
diff --git a/lib/vty.c b/lib/vty.c
index 42b7e92..d21f38c 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2422,7 +2422,7 @@
 
 /* Set time out value. */
 int
-exec_timeout (struct vty *vty, char *min_str, char *sec_str)
+exec_timeout (struct vty *vty, const char *min_str, const char *sec_str)
 {
   unsigned long timeout = 0;