snmp_transport.h

00001 #ifndef _SNMP_TRANSPORT_H
00002 #define _SNMP_TRANSPORT_H
00003 
00004 #include <sys/types.h>
00005 #include <net-snmp/library/asn1.h>
00006 
00007 #ifdef __cplusplus
00008 extern          "C" {
00009 #endif
00010 
00011 /*  Some transport-type constants.  */
00012 
00013 #ifndef NETSNMP_STREAM_QUEUE_LEN
00014 #define NETSNMP_STREAM_QUEUE_LEN        5
00015 #endif
00016 
00017 /*  Some transport-type flags.  */
00018 
00019 #define         NETSNMP_TRANSPORT_FLAG_STREAM   0x01
00020 #define         NETSNMP_TRANSPORT_FLAG_LISTEN   0x02
00021 #define         NETSNMP_TRANSPORT_FLAG_TUNNELED 0x04
00022 #define         NETSNMP_TRANSPORT_FLAG_HOSTNAME 0x80  /* for fmtaddr hook */
00023 
00024 /*  The standard SNMP domains.  */
00025 
00026 extern oid      netsnmpUDPDomain[];     /*      = { 1, 3, 6, 1, 6, 1, 1 };  */
00027 extern oid      netsnmpCLNSDomain[];    /*      = { 1, 3, 6, 1, 6, 1, 2 };  */
00028 extern oid      netsnmpCONSDomain[];    /*      = { 1, 3, 6, 1, 6, 1, 3 };  */
00029 extern oid      netsnmpDDPDomain[];     /*      = { 1, 3, 6, 1, 6, 1, 4 };  */
00030 extern oid      netsnmpIPXDomain[];     /*      = { 1, 3, 6, 1, 6, 1, 5 };  */
00031 extern size_t   netsnmpUDPDomain_len;
00032 extern size_t   netsnmpCLNSDomain_len;
00033 extern size_t   netsnmpCONSDomain_len;
00034 extern size_t   netsnmpDDPDomain_len;
00035 extern size_t   netsnmpIPXDomain_len;
00036 
00037 /*  Structure which defines the transport-independent API.  */
00038 
00039 typedef struct netsnmp_transport_s {
00040     /*  The transport domain object identifier.  */
00041 
00042     const oid      *domain;
00043     int             domain_length;  /*  In sub-IDs, not octets.  */
00044 
00045     /*  Local transport address (in relevant SNMP-style encoding).  */
00046     
00047     unsigned char  *local;
00048     int             local_length;   /*  In octets.  */
00049 
00050     /*  Remote transport address (in relevant SNMP-style encoding).  */
00051 
00052     unsigned char  *remote;
00053     int             remote_length;  /*  In octets.  */
00054 
00055     /*  The actual socket.  */
00056     
00057     int             sock;
00058 
00059     /*  Flags (see #definitions above).  */
00060 
00061     unsigned int    flags;
00062 
00063     /*  Protocol-specific opaque data pointer.  */
00064 
00065     void           *data;
00066     int             data_length;
00067 
00068     /*  Maximum size of PDU that can be sent/received by this transport.  */
00069 
00070     size_t          msgMaxSize;
00071 
00072     /*  Callbacks.  Arguments are:
00073      *          
00074      *              "this" pointer, fd, buf, size, *opaque, *opaque_length  
00075      */
00076 
00077     int             (*f_recv)   (struct netsnmp_transport_s *, void *,
00078                                  int, void **, int *);
00079     int             (*f_send)   (struct netsnmp_transport_s *, void *,
00080                                  int, void **, int *);
00081     int             (*f_close)  (struct netsnmp_transport_s *);
00082 
00083     /*  This callback is only necessary for stream-oriented transports.  */
00084 
00085     int             (*f_accept) (struct netsnmp_transport_s *);
00086 
00087     /*  Optional callback to format a transport address.  */
00088 
00089     char           *(*f_fmtaddr)(struct netsnmp_transport_s *, void *,
00090                                  int);
00091 } netsnmp_transport;
00092 
00093 typedef struct netsnmp_transport_list_s {
00094     netsnmp_transport *transport;
00095     struct netsnmp_transport_list_s *next;
00096 } netsnmp_transport_list;
00097 
00098 typedef struct netsnmp_tdomain_s {
00099     const oid      *name;
00100     size_t          name_length;
00101     const char    **prefix;
00102     netsnmp_transport *(*f_create_from_tstring) (const char *, int);
00103     netsnmp_transport *(*f_create_from_ostring) (const u_char *,  size_t, int);
00104 
00105     struct netsnmp_tdomain_s *next;
00106 } netsnmp_tdomain;
00107 
00108 
00109 /*  Some utility functions.  */
00110 
00111 int netsnmp_transport_add_to_list(netsnmp_transport_list **transport_list,
00112                                   netsnmp_transport *transport);
00113 int netsnmp_transport_remove_from_list(netsnmp_transport_list **transport_list,
00114                                        netsnmp_transport *transport);
00115 
00116 
00117 /*
00118  * Return an exact (deep) copy of t, or NULL if there is a memory allocation
00119  * problem (for instance).
00120  */
00121 
00122 netsnmp_transport *netsnmp_transport_copy(netsnmp_transport *t);
00123 
00124 
00125 /*  Free an netsnmp_transport.  */
00126 
00127 void            netsnmp_transport_free(netsnmp_transport *t);
00128 
00129 
00130 /*
00131  * If the passed oid (in_oid, in_len) corresponds to a supported transport
00132  * domain, return 1; if not return 0.  If out_oid is not NULL and out_len is
00133  * not NULL, then the "internal" oid which should be used to identify this
00134  * domain (e.g. in pdu->tDomain etc.) is written to *out_oid and its length to
00135  * *out_len.
00136  */
00137 
00138 int             netsnmp_tdomain_support(const oid *in_oid, size_t in_len,
00139                                         const oid **out_oid, size_t *out_len);
00140 
00141 int             netsnmp_tdomain_register(netsnmp_tdomain *domain);
00142     
00143 int             netsnmp_tdomain_unregister(netsnmp_tdomain *domain);
00144 
00145 void            netsnmp_clear_tdomain_list(void);
00146 
00147 void            netsnmp_tdomain_init(void);
00148 
00149 netsnmp_transport *netsnmp_tdomain_transport(const char *string,
00150                                              int local,
00151                                              const char
00152                                              *default_domain);
00153 
00154 netsnmp_transport *netsnmp_tdomain_transport_oid(const oid * dom,
00155                                                  size_t dom_len,
00156                                                  const u_char * o,
00157                                                  size_t o_len,
00158                                                  int local);
00159 
00160 #ifdef __cplusplus
00161 }
00162 #endif
00163 #endif/*_SNMP_TRANSPORT_H*/

net-snmpに対してSat Sep 5 13:14:25 2009に生成されました。  doxygen 1.4.7