www.usr.com/support/gpl/USR9113_release1.0.tar.gz
[bcm963xx.git] / userapps / opensource / net-snmp / snmplib / system.c
old mode 100644 (file)
new mode 100755 (executable)
index 7257115..9fca0f2
@@ -113,6 +113,10 @@ SOFTWARE.
 #include <sys/pstat.h>
 #endif
 
+#if HAVE_SYS_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+
 #include <net-snmp/types.h>
 #include <net-snmp/output_api.h>
 #include <net-snmp/utilities.h>
@@ -892,3 +896,44 @@ mkdirhier(const char *pathname, mode_t mode, int skiplast)
     free(ourcopy);
     return SNMPERR_SUCCESS;
 }
+
+/*
+ * This function was created to differentiate actions
+ * that are appropriate for Linux 2.4 kernels, but not later kernels.
+ *
+ * This function can be used to test kernels on any platform that supports uname().
+ *
+ * If not running a platform that supports uname(), return -1.
+ *
+ * If ospname matches, and the release matches up through the prefix,
+ *  return 0.
+ * If the release is ordered higher, return 1.
+ * Be aware that "ordered higher" is not a guarantee of correctness.
+ */
+int
+netsnmp_os_prematch(const char *ospmname,
+                    const char *ospmrelprefix)
+{
+#if HAVE_SYS_UTSNAME_H
+static int printOSonce = 1;
+  struct utsname utsbuf;
+  if ( 0 != uname(&utsbuf))
+    return -1;
+
+  if (printOSonce) {
+    printOSonce = 0;
+    /* show the four elements that the kernel can be sure of */
+  DEBUGMSGT(("daemonize","sysname '%s',\nrelease '%s',\nversion '%s',\nmachine '%s'\n",
+      utsbuf.sysname, utsbuf.release, utsbuf.version, utsbuf.machine));
+  }
+  if (0 != strcasecmp(utsbuf.sysname, ospmname)) return -1;
+
+  /* Required to match only the leading characters */
+  return strncasecmp(utsbuf.release, ospmrelprefix, strlen(ospmrelprefix));
+
+#else
+
+  return -1;
+
+#endif /* HAVE_SYS_UTSNAME_H */
+}