[cl-net-snmp-cvs] r16 - trunk

ctian at common-lisp.net ctian at common-lisp.net
Wed May 23 20:08:53 UTC 2007


Author: ctian
Date: Wed May 23 16:08:52 2007
New Revision: 16

Added:
   trunk/lw-dff.lisp
   trunk/net-snmp-dff.lisp
   trunk/net-snmp.h
Modified:
   trunk/asn1.lisp
   trunk/classes.lisp
   trunk/net-snmp.asd
   trunk/package.lisp
Log:
64bit LispWorks support added

Modified: trunk/asn1.lisp
==============================================================================
--- trunk/asn1.lisp	(original)
+++ trunk/asn1.lisp	Wed May 23 16:08:52 2007
@@ -1,12 +1,13 @@
 (in-package :org.net-snmp)
 
-(eval-when (:compile-toplevel :load-toplevel :execute)
+(eval-when (:compile-toplevel :load-toplevel)
   (defclass oid ()
     ((name :type string :reader oid-name :initarg :name)
      (length :type integer :reader oid-length)
      c-oids
      c-oid-len))
 
+  #-lispworks
   (defmethod shared-initialize :after ((instance oid) slot-names &rest initargs)
     (declare (ignore slot-names initargs))
     (with-slots (name length c-oids c-oid-len) instance
@@ -19,18 +20,13 @@
 	    (c-get-node name c-oids c-oid-len))
 	(setf length (mem-ref c-oid-len 'c-size-type)))))
 
-  (defmacro snmp-var->value (var)
-    (let ((v (gensym)))
-      `(let ((,v ,var))
-	 (case (foreign-slot-value ,v 'c-variable-list 'c-type)
-	   ;; ASN_OCTET_STR
-	   (,+asn-octet-str+
-	    (foreign-string-to-lisp
-	     (foreign-slot-value ,v 'c-variable-list 'c-val)
-	     (foreign-slot-value ,v 'c-variable-list 'c-val-len)))
-	   ;; ASN_COUNTER
-	   (,+asn-counter+
-	    (mem-ref (foreign-slot-value ,v 'c-variable-list 'c-val)
-		     :uint32))
-	   (otherwise :others))))))
+  #+lispworks
+  (defmethod shared-initialize :after ((instance oid) slot-names &rest initargs)
+    (declare (ignore slot-names initargs))
+    (with-slots (name length c-oids c-oid-len) instance
+      (progn
+	(setf c-oids (fli:allocate-foreign-object :type 'oid :nelems +max-oid-len+)
+	      c-oid-len (fli:allocate-foreign-object :type 'size-t))
+        (read-objid name c-oids c-oid-len)
+	(setf length (fli:dereference c-oid-len))))))
 

Modified: trunk/classes.lisp
==============================================================================
--- trunk/classes.lisp	(original)
+++ trunk/classes.lisp	Wed May 23 16:08:52 2007
@@ -27,7 +27,8 @@
 	      :initform "public")
    (security-name :reader snmp-security-name
 		  :initarg :security-name
-		  :type string)
+		  :type string
+                  :initform "binghe")
    (security-level :reader snmp-security-level
 		   :initarg :security-level
 		   :type string
@@ -38,9 +39,10 @@
 			:initform :hmac-md5)
    (passphrase :initarg :passphrase
 	       :type string
-	       :initform "binghe")
+	       :initform "01234567")
    c-session))
 
+#-lispworks
 (defmethod shared-initialize :after ((instance snmp-session) slot-names &rest initargs)
   (declare (ignore slot-names initargs))
   (with-slots (peername version c-session) instance
@@ -99,6 +101,49 @@
 			 (error "Error generating Ku from authentication pass phrase.")))))))
 	    (t (error "unknown snmp version!"))))))
 
+#+lispworks
+(defmethod shared-initialize :after ((instance snmp-session) slot-names &rest initargs)
+  (declare (ignore slot-names initargs))
+  (with-slots (peername version c-session) instance
+    (progn
+      (setf c-session (fli:allocate-foreign-object :type 'netsnmp-session))
+      (snmp-sess-init c-session)
+      (setf (fli:foreign-slot-value c-session 'peername) (fli:convert-to-foreign-string peername)
+            (fli:foreign-slot-value c-session 'version) version)
+      (cond ((or (= version +snmp-version-1+)
+		 (= version +snmp-version-2c+))
+	     (with-slots (community) instance
+               (setf (fli:foreign-slot-value c-session 'community) (fli:convert-to-foreign-string community)
+                     (fli:foreign-slot-value c-session 'community-len) (length community))))
+	    ;; SNMPv3 support
+	    ((= version +snmp-version-3+)
+	     (with-slots (security-name security-auth-proto passphrase) instance
+               (progn
+                 (setf (fli:foreign-slot-value c-session 'security-name) (fli:convert-to-foreign-string security-name)
+                       (fli:foreign-slot-value c-session 'security-name-len) (length security-name)
+                       ;; we only support authNoPriv now
+                       (fli:foreign-slot-value c-session 'security-level) +snmp-sec-level-authnopriv+
+                       (fli:foreign-slot-value c-session 'security-auth-key-len) +usm-auth-ku-len+)
+                 (case security-auth-proto
+                   (:hmac-md5
+                    (setf (fli:foreign-slot-value c-session 'security-auth-proto) +usm-hmac-md5-auth-protocol+
+                          (fli:foreign-slot-value c-session 'security-auth-proto-len) +usm-hmac-md5-auth-protocol-len+))
+                   (:hmac-sha1
+                    (setf (fli:foreign-slot-value c-session 'security-auth-proto) +usm-hmac-sha1-auth-protocol+
+                          (fli:foreign-slot-value c-session 'security-auth-proto-len) +usm-hmac-sha1-auth-protocol-len+)))
+                 (fli:with-foreign-string (c-passphrase c-passphrase-len byte-count)
+                     passphrase
+                   (declare (ignore byte-count))
+                   (if (/= (generate-ku (fli:foreign-slot-value c-session 'security-auth-proto)
+                                        (fli:foreign-slot-value c-session 'security-auth-proto-len)
+                                        c-passphrase
+                                        c-passphrase-len
+                                        (fli:foreign-array-pointer (fli:foreign-slot-pointer c-session 'security-auth-key) 0)
+                                        (fli:foreign-slot-pointer c-session 'security-auth-key-len))
+                           +snmp-err-success+)
+                       (error "Error generating Ku from authentication pass phrase."))))))
+	    (t (error "unknown snmp version!"))))))
+
 (defmethod snmp-msg-get ((s snmp-session) (o oid))
   (car (snmp-msg-get-list s (list o))))
 
@@ -108,35 +153,100 @@
 (defmethod snmp-msg-get ((s string) (o string))
   (snmp-msg-get (make-instance 'snmp-session :peername s) o))
 
+(defmethod snmp-msg-get ((s string) (o oid))
+  (snmp-msg-get (make-instance 'snmp-session :peername s) o))
+
+#-lispworks
 (defmethod snmp-msg-get-list ((s snmp-session) (oids list))
   (let ((ss (c-snmp-open (slot-value s 'c-session)))
-	(pdu (c-snmp-pdu-create +snmp-msg-get+))
-	(response (foreign-alloc :pointer :initial-element (null-pointer)))
-	values)
+        (pdu (c-snmp-pdu-create +snmp-msg-get+))
+        (response (foreign-alloc :pointer :initial-element (null-pointer)))
+        values)
     (progn
       ;; 1. fill oids into request pdu
       (dolist (o oids)
-	(let ((real-o (typecase o
-			(oid o)
-			(string (make-instance 'oid :name o))
-			(t (make-instance 'oid :name "")))))
-	  (c-snmp-add-null-var pdu
-			       (slot-value real-o 'c-oids)
-			       (mem-ref (slot-value real-o 'c-oid-len) 'c-size-type))))
+        (let ((real-o (typecase o
+                        (oid o)
+                        (string (make-instance 'oid :name o))
+                        (t (make-instance 'oid :name "")))))
+          (c-snmp-add-null-var pdu
+                               (slot-value real-o 'c-oids)
+                               (mem-ref (slot-value real-o 'c-oid-len) 'c-size-type))))
       ;; 2. get results from response pdu
       (let ((status (c-snmp-synch-response ss pdu response)))
-	(setf values
-	      (if (and (= status +snmp-stat-success+)
-		       (= (foreign-slot-value (mem-aref response :pointer) 'c-snmp-pdu 'c-errstat)
-			  +snmp-err-noerror+))
-		  (loop for vars =  (foreign-slot-value (mem-aref response :pointer)
-							'c-snmp-pdu 'c-variables)
-		     then (foreign-slot-value vars 'c-variable-list 'c-next-variable)
-		     until (null-pointer-p vars)
-		     collect (snmp-var->value vars)))))
+        (setf values
+              (if (and (= status +snmp-stat-success+)
+                       (= (foreign-slot-value (mem-aref response :pointer) 'c-snmp-pdu 'c-errstat)
+                          +snmp-err-noerror+))
+                  (loop for vars =  (foreign-slot-value (mem-aref response :pointer)
+                                                        'c-snmp-pdu 'c-variables)
+                        then (foreign-slot-value vars 'c-variable-list 'c-next-variable)
+                        until (null-pointer-p vars)
+                        collect (snmp-var->value vars)))))
       (c-snmp-pdu-free (mem-aref response :pointer))
       (c-snmp-close ss)
       values)))
 
+#+lispworks
+(defmethod snmp-msg-get-list ((s snmp-session) (oids list))
+  (let ((ss (snmp-open (slot-value s 'c-session)))
+        (pdu (snmp-pdu-create +snmp-msg-get+))
+        values)
+    (fli:with-dynamic-foreign-objects ((response (:pointer netsnmp-pdu)))
+      (progn
+        ;; 1. fill oids into request pdu
+        (dolist (o oids)
+          (let ((real-o (typecase o
+                          (oid o)
+                          (string (make-instance 'oid :name o))
+                          (t (error "unknown oid type")))))
+            (snmp-add-null-var pdu
+                               (slot-value real-o 'c-oids)
+                               (fli:dereference (slot-value real-o 'c-oid-len)))))
+        ;; 2. get results from response pdu
+        (let ((status (snmp-synch-response ss pdu response)))
+          (setf values
+                (if (and (= status +snmp-stat-success+)
+                         (= (fli:foreign-slot-value (fli:dereference response) 'errstat)
+                            +snmp-err-noerror+))
+                    (loop for vars = (fli:foreign-slot-value (fli:dereference response)
+                                                             'variables)
+                          then (fli:foreign-slot-value vars 'next-variable)
+                          until (fli:null-pointer-p vars)
+                          collect (snmp-var->value vars)))))
+        (snmp-free-pdu (fli:dereference response))
+        (snmp-close ss)
+        values))))
+
 (defmethod snmp-msg-get-list ((s string) (oids list))
   (snmp-msg-get-list (make-instance 'snmp-session :peername s) oids))
+
+#-lispworks
+(defun snmp-var->value (v)
+  (case (foreign-slot-value v 'c-variable-list 'c-type)
+    ;; ASN_OCTET_STR
+    (+asn-octet-str+
+     (foreign-string-to-lisp
+      (foreign-slot-value v 'c-variable-list 'c-val)
+      (foreign-slot-value v 'c-variable-list 'c-val-len)))
+    ;; ASN_COUNTER
+    (+asn-counter+
+     (mem-ref (foreign-slot-value v 'c-variable-list 'c-val)
+              :uint32))
+    (otherwise :others)))
+
+#+lispworks
+(defun snmp-var->value (v)
+  (case (fli:foreign-slot-value v 'type)
+    ;; ASN_INTEGER
+    (#x02
+     (fli:dereference
+      (fli:foreign-slot-value (fli:foreign-slot-pointer v 'val)
+                              'integer)))
+    ;; ASN_OCTET_STR
+    (#x04
+     (fli:convert-from-foreign-string
+       (fli:foreign-slot-value (fli:foreign-slot-pointer v 'val)
+                               'string)
+       :length (fli:foreign-slot-value v 'val-len)))
+    (otherwise (fli:foreign-slot-value v 'type))))

Added: trunk/lw-dff.lisp
==============================================================================
--- (empty file)
+++ trunk/lw-dff.lisp	Wed May 23 16:08:52 2007
@@ -0,0 +1,33 @@
+(in-package :org.net-snmp)
+
+(eval-when (:compile-toplevel :load-toplevel)
+  (fli:define-c-typedef (size-t (:foreign-name "size_t"))
+    (:unsigned :long))
+  (fli:define-c-typedef (u-long (:foreign-name "u_long"))
+    (:unsigned :long))
+  (fli:define-c-typedef (oid (:foreign-name "oid")) u-long)
+
+  (fli:define-foreign-function (init-snmp "init_snmp" :source)
+      ;; Page 32 of FLI Manual
+      ((arg-1 (:reference-pass :ef-mb-string)))
+    :result-type :void
+    :language :ansi-c)
+
+  (fli:define-foreign-function (read-objid "read_objid" :source)
+      ((arg-1 (:reference-pass :ef-mb-string))
+       (arg-2 (:pointer oid))
+       (arg-3 (:pointer size-t)))
+    :result-type :int
+    :language :ansi-c)
+
+  (fli:define-foreign-function (get-node "get_node" :source)
+      ((arg-1 (:reference-pass :ef-mb-string))
+       (arg-2 (:pointer oid))
+       (arg-3 (:pointer size-t)))
+    :result-type :int
+    :language :ansi-c))
+
+(eval-when (:load-toplevel)
+  (init-snmp "snmpapp")
+  (format t "Net-SNMP Initialized.~%"))
+

Added: trunk/net-snmp-dff.lisp
==============================================================================
--- (empty file)
+++ trunk/net-snmp-dff.lisp	Wed May 23 16:08:52 2007
@@ -0,0 +1,265 @@
+#| DATE           : 24 May 2007 
+ | USER           : binghe 
+ | PROCESSED FILE : net-snmp.h
+ |#
+
+(in-package :org.net-snmp)
+
+;;; Derived from file : "/home/binghe/cl-net-snmp/net-snmp.h"
+
+(fli:define-c-typedef (u-char (:foreign-name "u_char"))
+                      (:unsigned :char))
+(fli:define-c-typedef (u-short (:foreign-name "u_short"))
+                      (:unsigned :short))
+(fli:define-c-typedef (u-int (:foreign-name "u_int")) (:unsigned :int))
+(fli:define-c-struct (counter64 (:foreign-name "counter64"))
+                     (high u-long)
+                     (low u-long))
+(fli:define-c-struct (variable-list
+                      (:foreign-name "variable_list")
+                      (:forward-reference t)))
+(fli:define-c-typedef (netsnmp-variable-list
+                       (:foreign-name "netsnmp_variable_list"))
+                      (:struct variable-list))
+(fli:define-c-struct (netsnmp-transport-s
+                      (:foreign-name "netsnmp_transport_s")
+                      (:forward-reference t)))
+(fli:define-c-struct (snmp-pdu (:foreign-name "snmp_pdu"))
+                     (version :long)
+                     (command :int)
+                     (reqid :long)
+                     (msgid :long)
+                     (transid :long)
+                     (sessid :long)
+                     (errstat :long)
+                     (errindex :long)
+                     (time u-long)
+                     (flags u-long)
+                     (security-model :int)
+                     (security-level :int)
+                     (msg-parse-model :int)
+                     (transport-data (:pointer :void))
+                     (transport-data-length :int)
+                     (t-domain (:pointer (:const oid)))
+                     (t-domain-len size-t)
+                     (variables (:pointer netsnmp-variable-list))
+                     (community (:pointer u-char))
+                     (community-len size-t)
+                     (enterprise (:pointer oid))
+                     (enterprise-length size-t)
+                     (trap-type :long)
+                     (specific-type :long)
+                     (agent-addr (:c-array (:unsigned :char) 4))
+                     (context-engine-id (:pointer u-char))
+                     (context-engine-idlen size-t)
+                     (context-name (:pointer :char))
+                     (context-name-len size-t)
+                     (security-engine-id (:pointer u-char))
+                     (security-engine-idlen size-t)
+                     (security-name (:pointer :char))
+                     (security-name-len size-t)
+                     (priority :int)
+                     (range-subid :int)
+                     (security-state-ref (:pointer :void)))
+(fli:define-c-typedef (netsnmp-pdu (:foreign-name "netsnmp_pdu"))
+                      (:struct snmp-pdu))
+(fli:define-c-struct (snmp-session
+                      (:foreign-name "snmp_session")
+                      (:forward-reference t)))
+(fli:define-c-typedef (netsnmp-session
+                       (:foreign-name "netsnmp_session"))
+                      (:struct snmp-session))
+(fli:define-c-typedef (snmp-callback (:foreign-name "snmp_callback"))
+                      (:pointer
+                       (:function
+                        (:int
+                         (:pointer netsnmp-session)
+                         :int
+                         (:pointer netsnmp-pdu)
+                         (:pointer :void))
+                        :int)))
+(fli:define-c-typedef (netsnmp-callback
+                       (:foreign-name "netsnmp_callback"))
+                      (:pointer
+                       (:function
+                        (:int
+                         (:pointer netsnmp-session)
+                         :int
+                         (:pointer netsnmp-pdu)
+                         (:pointer :void))
+                        :int)))
+(fli:define-c-struct (snmp-session (:foreign-name "snmp_session"))
+                     (version :long)
+                     (retries :int)
+                     (timeout :long)
+                     (flags u-long)
+                     (subsession (:pointer (:struct snmp-session)))
+                     (next (:pointer (:struct snmp-session)))
+                     (peername (:pointer :char))
+                     (remote-port u-short)
+                     (localname (:pointer :char))
+                     (local-port u-short)
+                     (authenticator
+                      (:pointer
+                       (:function
+                        ((:pointer u-char)
+                         (:pointer size-t)
+                         (:pointer u-char)
+                         size-t)
+                        (:pointer u-char))))
+                     (callback netsnmp-callback)
+                     (callback-magic (:pointer :void))
+                     (s-errno :int)
+                     (s-snmp-errno :int)
+                     (sessid :long)
+                     (community (:pointer u-char))
+                     (community-len size-t)
+                     (rcv-msg-max-size size-t)
+                     (snd-msg-max-size size-t)
+                     (is-authoritative u-char)
+                     (context-engine-id (:pointer u-char))
+                     (context-engine-idlen size-t)
+                     (engine-boots u-int)
+                     (engine-time u-int)
+                     (context-name (:pointer :char))
+                     (context-name-len size-t)
+                     (security-engine-id (:pointer u-char))
+                     (security-engine-idlen size-t)
+                     (security-name (:pointer :char))
+                     (security-name-len size-t)
+                     (security-auth-proto (:pointer oid))
+                     (security-auth-proto-len size-t)
+                     (security-auth-key (:c-array u-char 32))
+                     (security-auth-key-len size-t)
+                     (security-auth-local-key (:pointer u-char))
+                     (security-auth-local-key-len size-t)
+                     (security-priv-proto (:pointer oid))
+                     (security-priv-proto-len size-t)
+                     (security-priv-key (:c-array u-char 32))
+                     (security-priv-key-len size-t)
+                     (security-priv-local-key (:pointer u-char))
+                     (security-priv-local-key-len size-t)
+                     (security-model :int)
+                     (security-level :int)
+                     (security-info (:pointer :void))
+                     (myvoid (:pointer :void)))
+(fli:define-c-typedef (netsnmp-vardata
+                       (:foreign-name "netsnmp_vardata"))
+                      (:union
+                       (integer (:pointer :long))
+                       (string (:pointer u-char))
+                       (objid (:pointer oid))
+                       (bitstring (:pointer u-char))
+                       (counter64 (:pointer (:struct counter64)))))
+(fli:define-c-struct (variable-list (:foreign-name "variable_list"))
+                     (next-variable (:pointer (:struct variable-list)))
+                     (name (:pointer oid))
+                     (name-length size-t)
+                     (type u-char)
+                     (val netsnmp-vardata)
+                     (val-len size-t)
+                     (name-loc (:c-array oid 128))
+                     (buf (:c-array u-char 40))
+                     (data (:pointer :void))
+                     (data-free-hook
+                      (:pointer (:function ((:pointer :void)) :void)))
+                     (index :int))
+(fli:define-foreign-function (snmp-sess-init "snmp_sess_init" :source)
+                             ((arg-1 (:pointer netsnmp-session)))
+                             :result-type
+                             :void
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-open "snmp_open" :source)
+                             ((arg-1 (:pointer netsnmp-session)))
+                             :result-type
+                             (:pointer netsnmp-session)
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-close "snmp_close" :source)
+                             ((arg-1 (:pointer netsnmp-session)))
+                             :result-type
+                             :int
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-close-sessions
+                              "snmp_close_sessions"
+                              :source)
+                             nil
+                             :result-type
+                             :int
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-perror "snmp_perror" :source)
+                             ((arg-1 (:pointer (:const :char))))
+                             :result-type
+                             :void
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-errstring "snmp_errstring" :source)
+                             ((arg-1 :int))
+                             :result-type
+                             (:pointer (:const :char))
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-sess-perror
+                              "snmp_sess_perror"
+                              :source)
+                             ((prog-string (:pointer (:const :char)))
+                              (ss (:pointer netsnmp-session)))
+                             :result-type
+                             :void
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-pdu-create
+                              "snmp_pdu_create"
+                              :source)
+                             ((arg-1 :int))
+                             :result-type
+                             (:pointer netsnmp-pdu)
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-free-pdu "snmp_free_pdu" :source)
+                             ((arg-1 (:pointer netsnmp-pdu)))
+                             :result-type
+                             :void
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-pdu-type "snmp_pdu_type" :source)
+                             ((type :int))
+                             :result-type
+                             (:pointer (:const :char))
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-add-null-var
+                              "snmp_add_null_var"
+                              :source)
+                             ((arg-1 (:pointer netsnmp-pdu))
+                              (arg-2 (:pointer (:const oid)))
+                              (arg-3 size-t))
+                             :result-type
+                             (:pointer netsnmp-variable-list)
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (snmp-synch-response
+                              "snmp_synch_response"
+                              :source)
+                             ((arg-1 (:pointer netsnmp-session))
+                              (arg-2 (:pointer netsnmp-pdu))
+                              (arg-3
+                               (:pointer (:pointer netsnmp-pdu))))
+                             :result-type
+                             :int
+                             :language
+                             :ansi-c)
+(fli:define-foreign-function (generate-ku "generate_Ku" :source)
+                             ((hashtype (:pointer (:const oid)))
+                              (hashtype-len u-int)
+                              (p (:pointer u-char))
+                              (pplen size-t)
+                              (ku (:pointer u-char))
+                              (kulen (:pointer size-t)))
+                             :result-type
+                             :int
+                             :language
+                             :ansi-c)

Modified: trunk/net-snmp.asd
==============================================================================
--- trunk/net-snmp.asd	(original)
+++ trunk/net-snmp.asd	Wed May 23 16:08:52 2007
@@ -2,17 +2,22 @@
 
 (defpackage :net-snmp-system
   (:use :cl :asdf))
-          
+
 (in-package :net-snmp-system)
+
+;;(require "foreign-parser")
+;;(foreign-parser:process-foreign-file "net-snmp.h" :case-sensitive :split-name)
           
 (defsystem net-snmp
   :description "Common Lisp interface for Net-SNMP"
-  :version "0.10"
+  :version "0.50"
   :author "Chun Tian (binghe)"
-  :depends-on (:cffi)
+  ;;:depends-on (:cffi)
   :components ((:file "package")
 	       (:file "constants" :depends-on ("package"))
-	       (:file "typedefs" :depends-on ("constants"))
-	       (:file "asn1" :depends-on ("typedefs"))
-	       (:file "snmp-api" :depends-on ("constants" "typedefs"))
-	       (:file "classes" :depends-on ("snmp-api"))))
+	       #-lispworks (:file "typedefs" :depends-on ("constants"))
+               #+lispworks (:file "lw-dff" :depends-on ("package"))
+               #+lispworks (:file "net-snmp-dff" :depends-on ("package"))
+               #-lispworks (:file "snmp-api" :depends-on ("constants" "typedefs"))
+	       (:file "asn1" :depends-on (#-lispworks "typedefs" #+lispworks "net-snmp-dff"))))
+	       ;;(:file "classes" :depends-on ("snmp-api"))))

Added: trunk/net-snmp.h
==============================================================================
--- (empty file)
+++ trunk/net-snmp.h	Wed May 23 16:08:52 2007
@@ -0,0 +1,309 @@
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+
+struct counter64 {
+  u_long          high;
+  u_long          low;
+};
+
+struct variable_list;
+typedef struct variable_list netsnmp_variable_list;
+struct netsnmp_transport_s;
+
+#define USM_AUTH_KU_LEN     32
+#define USM_PRIV_KU_LEN     32
+#define MIN_OID_LEN	    2
+#define MAX_OID_LEN	    128 /* max subid's in an oid */
+
+/** @typedef struct snmp_pdu to netsnmp_pdu
+ * Typedefs the snmp_pdu struct into netsnmp_pdu */
+/** @struct snmp_pdu
+ * The snmp protocol data unit.
+ */	
+typedef struct snmp_pdu {
+
+  /*
+   * Protocol-version independent fields
+   */
+  /** snmp version */
+  long            version;
+  /** Type of this PDU */	
+  int             command;
+  /** Request id - note: not incremented on retries */
+  long            reqid;  
+  /** Message id for V3 messages note: incremented for each retry */
+  long            msgid;
+  /** Unique ID for incoming transactions */
+  long            transid;
+  /** Session id for AgentX messages */
+  long            sessid;
+  /** Error status (non_repeaters in GetBulk) */
+  long            errstat;
+  /** Error index (max_repetitions in GetBulk) */
+  long            errindex;       
+  /** Uptime */
+  u_long          time;   
+  u_long          flags;
+
+  int             securityModel;
+  /** noAuthNoPriv, authNoPriv, authPriv */
+  int             securityLevel;  
+  int             msgParseModel;
+
+  /**
+   * Transport-specific opaque data.  This replaces the IP-centric address
+   * field.  
+   */
+    
+  void           *transport_data;
+  int             transport_data_length;
+
+  /**
+   * The actual transport domain.  This SHOULD NOT BE FREE()D.  
+   */
+
+  const oid      *tDomain;
+  size_t          tDomainLen;
+
+  netsnmp_variable_list *variables;
+
+
+  /*
+   * SNMPv1 & SNMPv2c fields
+   */
+  /** community for outgoing requests. */
+  u_char         *community;
+  /** length of community name. */
+  size_t          community_len;  
+
+  /*
+   * Trap information
+   */
+  /** System OID */
+  oid            *enterprise;     
+  size_t          enterprise_length;
+  /** trap type */
+  long            trap_type;
+  /** specific type */
+  long            specific_type;
+  /** This is ONLY used for v1 TRAPs  */
+  unsigned char   agent_addr[4];  
+
+  /*
+   *  SNMPv3 fields
+   */
+  /** context snmpEngineID */
+  u_char         *contextEngineID;
+  /** Length of contextEngineID */
+  size_t          contextEngineIDLen;     
+  /** authoritative contextName */
+  char           *contextName;
+  /** Length of contextName */
+  size_t          contextNameLen;
+  /** authoritative snmpEngineID for security */
+  u_char         *securityEngineID;
+  /** Length of securityEngineID */
+  size_t          securityEngineIDLen;    
+  /** on behalf of this principal */
+  char           *securityName;
+  /** Length of securityName. */
+  size_t          securityNameLen;        
+    
+  /*
+   * AgentX fields
+   *      (also uses SNMPv1 community field)
+   */
+  int             priority;
+  int             range_subid;
+    
+  void           *securityStateRef;
+} netsnmp_pdu;
+
+struct snmp_session;
+
+/** @typedef struct snmp_session netsnmp_session
+ * Typedefs the snmp_session struct intonetsnmp_session */
+typedef struct snmp_session netsnmp_session;
+
+typedef int     (*snmp_callback) (int, netsnmp_session *, int,
+				  netsnmp_pdu *, void *);
+typedef int     (*netsnmp_callback) (int, netsnmp_session *, int,
+				     netsnmp_pdu *, void *);
+
+/** @struct snmp_session
+ * The snmp session structure.
+ */
+struct snmp_session {
+  /*
+   * Protocol-version independent fields
+   */
+  /** snmp version */
+  long            version;
+  /** Number of retries before timeout. */
+  int             retries;
+  /** Number of uS until first timeout, then exponential backoff */
+  long            timeout;        
+  u_long          flags;
+  struct snmp_session *subsession;
+  struct snmp_session *next;
+
+  /** Domain name or dotted IP address of default peer */
+  char           *peername;
+  /** UDP port number of peer. */
+  u_short         remote_port;
+  /** My Domain name or dotted IP address, 0 for default */
+  char           *localname;
+  /** My UDP port number, 0 for default, picked randomly */
+  u_short         local_port;     
+  /**
+   * Authentication function or NULL if null authentication is used 
+   */
+  u_char         *(*authenticator) (u_char *, size_t *, u_char *, size_t);
+  /** Function to interpret incoming data */
+  netsnmp_callback callback;      
+  /**
+   * Pointer to data that the callback function may consider important 
+   */
+  void           *callback_magic;
+  /** copy of system errno */
+  int             s_errno;
+  /** copy of library errno */
+  int             s_snmp_errno;   
+  /** Session id - AgentX only */
+  long            sessid; 
+
+  /*
+   * SNMPv1 & SNMPv2c fields
+   */
+  /** community for outgoing requests. */
+  u_char         *community;
+  /** Length of community name. */
+  size_t          community_len;  
+  /**  Largest message to try to receive.  */
+  size_t          rcvMsgMaxSize;
+  /**  Largest message to try to send.  */
+  size_t          sndMsgMaxSize;  
+
+  /*
+   * SNMPv3 fields
+   */
+  /** are we the authoritative engine? */
+  u_char          isAuthoritative;
+  /** authoritative snmpEngineID */
+  u_char         *contextEngineID;
+  /** Length of contextEngineID */
+  size_t          contextEngineIDLen;     
+  /** initial engineBoots for remote engine */
+  u_int           engineBoots;
+  /** initial engineTime for remote engine */
+  u_int           engineTime;
+  /** authoritative contextName */
+  char           *contextName;
+  /** Length of contextName */
+  size_t          contextNameLen;
+  /** authoritative snmpEngineID */
+  u_char         *securityEngineID;
+  /** Length of contextEngineID */
+  size_t          securityEngineIDLen;    
+  /** on behalf of this principal */
+  char           *securityName;
+  /** Length of securityName. */
+  size_t          securityNameLen;
+
+  /** auth protocol oid */
+  oid            *securityAuthProto;
+  /** Length of auth protocol oid */
+  size_t          securityAuthProtoLen;
+  /** Ku for auth protocol XXX */
+  u_char          securityAuthKey[USM_AUTH_KU_LEN];       
+  /** Length of Ku for auth protocol */
+  size_t          securityAuthKeyLen;
+  /** Kul for auth protocol */
+  u_char          *securityAuthLocalKey;       
+  /** Length of Kul for auth protocol XXX */
+  size_t          securityAuthLocalKeyLen;       
+
+  /** priv protocol oid */
+  oid            *securityPrivProto;
+  /** Length of priv protocol oid */
+  size_t          securityPrivProtoLen;
+  /** Ku for privacy protocol XXX */
+  u_char          securityPrivKey[USM_PRIV_KU_LEN];       
+  /** Length of Ku for priv protocol */
+  size_t          securityPrivKeyLen;
+  /** Kul for priv protocol */
+  u_char          *securityPrivLocalKey;       
+  /** Length of Kul for priv protocol XXX */
+  size_t          securityPrivLocalKeyLen;       
+
+  /** snmp security model, v1, v2c, usm */
+  int             securityModel;
+  /** noAuthNoPriv, authNoPriv, authPriv */
+  int             securityLevel;  
+    
+  /**
+   * security module specific 
+   */
+  void           *securityInfo;
+
+  /**
+   * use as you want data 
+   */
+  void           *myvoid;
+};
+
+typedef union {
+  long           *integer;
+  u_char         *string;
+  oid            *objid;
+  u_char         *bitstring;
+  struct counter64 *counter64;
+} netsnmp_vardata;
+
+/** @struct variable_list
+ * The netsnmp variable list binding structure, it's typedef'd to
+ * netsnmp_variable_list.
+ */
+struct variable_list {
+  /** NULL for last variable */
+  struct variable_list *next_variable;    
+  /** Object identifier of variable */
+  oid            *name;   
+  /** number of subid's in name */
+  size_t          name_length;    
+  /** ASN type of variable */
+  u_char          type;   
+  /** value of variable */
+  netsnmp_vardata val;
+  /** the length of the value to be copied into buf */
+  size_t          val_len;
+  /** 90 percentile < 24. */
+  oid             name_loc[MAX_OID_LEN];  
+  /** 90 percentile < 40. */
+  u_char          buf[40];
+  /** (Opaque) hook for additional data */
+  void           *data;
+  /** callback to free above */
+  void            (*dataFreeHook)(void *);    
+  int             index;
+};
+
+void            snmp_sess_init(netsnmp_session *);
+netsnmp_session *snmp_open(netsnmp_session *);
+int             snmp_close(netsnmp_session *);
+int             snmp_close_sessions(void);
+extern void     snmp_perror(const char *);
+const char     *snmp_errstring(int);
+void            snmp_sess_perror(const char *prog_string,
+				 netsnmp_session * ss);
+netsnmp_pdu    *snmp_pdu_create(int);
+void            snmp_free_pdu(netsnmp_pdu *);
+const char *    snmp_pdu_type(int type);
+int             get_node(const char *, oid *, size_t *);
+netsnmp_variable_list *snmp_add_null_var(netsnmp_pdu *, const oid *, size_t);
+int             snmp_synch_response(netsnmp_session *, netsnmp_pdu *,
+				    netsnmp_pdu **);
+int             generate_Ku(const oid * hashtype, u_int hashtype_len,
+                            u_char * P, size_t pplen,
+                            u_char * Ku, size_t * kulen);

Modified: trunk/package.lisp
==============================================================================
--- trunk/package.lisp	(original)
+++ trunk/package.lisp	Wed May 23 16:08:52 2007
@@ -2,7 +2,7 @@
 
 (defpackage :org.net-snmp
   (:nicknames :snmp)
-  (:use :cl :cffi)
+  (:use :cl #-lispworks :cffi)
   (:export
    ;; class
    snmp-session oid
@@ -16,14 +16,13 @@
 
 (in-package :org.net-snmp)
 
-(eval-when (:compile-toplevel :load-toplevel :execute)
-  (define-foreign-library libssl
-    (:unix (:or "libssl.so.0.9.8" "libssl.so"))
-    (t (:default "libssl")))
-  
+#-lispworks
+(eval-when (:compile-toplevel :load-toplevel)
   (define-foreign-library libsnmp
-    (:unix (:or "libsnmp.so.15" "libsnmp.so"))
+    (:unix "libsnmp.so.9")
     (t (:default "libsnmp")))
-  
-  (use-foreign-library libssl)
   (use-foreign-library libsnmp))
+
+#+lispworks
+(eval-when (:compile-toplevel :load-toplevel)
+  (fli:register-module "libsnmp.so.9"))



More information about the Cl-net-snmp-cvs mailing list