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

	* (global) more const'ification.
	* sockunion.c: (sockunion_su2str) buffer should be sized
          SU_ADDRSTRLEN.
          (sockunion_log) do not return stack variables, strdup buf before
          return.
        * vty.h: Fix up the VTY_GET_INTEGER macros. Testing caller supplied
          values against ULONG_MAX is daft, when caller probably has passed
          a type that can not hold ULONG_MAX. use a temporary long instead.
          Add VTY_GET_LONG, make VTY_GET_INTEGER_RANGE use it, make
	  VTY_GET_INTEGER a define for VTY_GET_INTEGER_RANGE.
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 9a01f63..1e6f51c 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,16 @@
+2004-10-13 Paul Jakma <paul@dishone.st>
+
+	* (global) more const'ification.
+	* sockunion.c: (sockunion_su2str) buffer should be sized
+          SU_ADDRSTRLEN.
+          (sockunion_log) do not return stack variables, strdup buf before
+          return.
+        * vty.h: Fix up the VTY_GET_INTEGER macros. Testing caller supplied
+          values against ULONG_MAX is daft, when caller probably has passed
+          a type that can not hold ULONG_MAX. use a temporary long instead.
+          Add VTY_GET_LONG, make VTY_GET_INTEGER_RANGE use it, make
+	  VTY_GET_INTEGER a define for VTY_GET_INTEGER_RANGE.
+
 2004-10-11 Hasso Tepper <hasso at quagga.net>
 
 	* command.h: Sync DEFUNSH with other macros.
diff --git a/lib/command.c b/lib/command.c
index 168fe56..0e61e0d 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -78,7 +78,7 @@
 /* Utility function to concatenate argv argument into a single string
    with inserting ' ' character between each argument.  */
 char *
-argv_concat (char **argv, int argc, int shift)
+argv_concat (const char **argv, int argc, int shift)
 {
   int i;
   int len;
diff --git a/lib/command.h b/lib/command.h
index a838734..8faf534 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -286,7 +286,7 @@
 void install_element (enum node_type, struct cmd_element *);
 void sort_node ();
 
-char *argv_concat (char **, int, int);
+char *argv_concat (const char **, int, int);
 vector cmd_make_strvec (const char *);
 void cmd_free_strvec (vector);
 vector cmd_describe_command ();
diff --git a/lib/sockunion.c b/lib/sockunion.c
index eb29ced..78e02f2 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -175,7 +175,7 @@
 }
 
 union sockunion *
-sockunion_str2su (char *str)
+sockunion_str2su (const char *str)
 {
   int ret;
   union sockunion *su;
@@ -211,7 +211,7 @@
 char *
 sockunion_su2str (union sockunion *su)
 {
-  char str[INET6_ADDRSTRLEN];
+  char str[SU_ADDRSTRLEN];
 
   switch (su->sa.sa_family)
     {
@@ -314,7 +314,7 @@
       snprintf (buf, SU_ADDRSTRLEN, "af_unknown %d ", su->sa.sa_family);
       break;
     }
-  return buf;
+  return (strdup (buf));
 }
 
 /* sockunion_connect returns
@@ -676,7 +676,7 @@
 #ifdef HAVE_IPV6
     case AF_INET6:
       {
-	char buf [64];
+	char buf [SU_ADDRSTRLEN];
 
 	printf ("%s\n", inet_ntop (AF_INET6, &(su->sin6.sin6_addr),
 				 buf, sizeof (buf)));
diff --git a/lib/sockunion.h b/lib/sockunion.h
index 92e536c..738df06 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -93,7 +93,7 @@
 int sockunion_same (union sockunion *, union sockunion *);
 
 char *sockunion_su2str (union sockunion *su);
-union sockunion *sockunion_str2su (char *str);
+union sockunion *sockunion_str2su (const char *str);
 struct in_addr sockunion_get_in_addr (union sockunion *su);
 int sockunion_accept (int sock, union sockunion *);
 int sockunion_stream_socket (union sockunion *);
diff --git a/lib/vty.h b/lib/vty.h
index ffaad35..c5c8c3b 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -158,30 +158,33 @@
 #define PRINTF_ATTRIBUTE(a,b)
 #endif /* __GNUC__ */
 
-/* Utility macro to convert VTY argument to unsigned integer.  */
-#define VTY_GET_INTEGER(NAME,V,STR)                              \
-{                                                                \
-  char *endptr = NULL;                                           \
-  (V) = strtoul ((STR), &endptr, 10);                            \
-  if ((V) == ULONG_MAX || *endptr != '\0')                       \
-    {                                                            \
+/* Utility macros to convert VTY argument to unsigned long or integer. */
+#define VTY_GET_LONG(NAME,V,STR) \
+{ \
+  char *endptr = NULL; \
+  (V) = strtoul ((STR), &endptr, 10); \
+  if (*endptr != '\0' || (V) == ULONG_MAX) \
+    { \
       vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
-      return CMD_WARNING;                                        \
-    }                                                            \
+      return CMD_WARNING; \
+    } \
 }
 
-#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX)                \
-{                                                                \
-  char *endptr = NULL;                                           \
-  (V) = strtoul ((STR), &endptr, 10);                            \
-  if ((V) == ULONG_MAX || *endptr != '\0'                        \
-      || (V) < (MIN) || (V) > (MAX))                             \
-    {                                                            \
+#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
+{ \
+  unsigned long tmpl; \
+  VTY_GET_LONG(NAME, tmpl, STR) \
+  if ( tmpl < (MIN) || tmpl > (MAX)) \
+    { \
       vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
-      return CMD_WARNING;                                        \
-    }                                                            \
+      return CMD_WARNING; \
+    } \
+  (V) = tmpl; \
 }
 
+#define VTY_GET_INTEGER(NAME,V,STR) \
+  VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
+
 /* Exported variables */
 extern char integrate_default[];