net-snmp
5.4.1
|
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 00023 /* The standard SNMP domains. */ 00024 00025 NETSNMP_IMPORT oid netsnmpUDPDomain[]; /* = { 1, 3, 6, 1, 6, 1, 1 }; */ 00026 NETSNMP_IMPORT oid netsnmpCLNSDomain[]; /* = { 1, 3, 6, 1, 6, 1, 2 }; */ 00027 NETSNMP_IMPORT oid netsnmpCONSDomain[]; /* = { 1, 3, 6, 1, 6, 1, 3 }; */ 00028 NETSNMP_IMPORT oid netsnmpDDPDomain[]; /* = { 1, 3, 6, 1, 6, 1, 4 }; */ 00029 NETSNMP_IMPORT oid netsnmpIPXDomain[]; /* = { 1, 3, 6, 1, 6, 1, 5 }; */ 00030 NETSNMP_IMPORT size_t netsnmpUDPDomain_len; 00031 NETSNMP_IMPORT size_t netsnmpCLNSDomain_len; 00032 NETSNMP_IMPORT size_t netsnmpCONSDomain_len; 00033 NETSNMP_IMPORT size_t netsnmpDDPDomain_len; 00034 NETSNMP_IMPORT size_t netsnmpIPXDomain_len; 00035 00036 /* Structure which defines the transport-independent API. */ 00037 00038 typedef struct netsnmp_transport_s { 00039 /* The transport domain object identifier. */ 00040 00041 const oid *domain; 00042 int domain_length; /* In sub-IDs, not octets. */ 00043 00044 /* Local transport address (in relevant SNMP-style encoding). */ 00045 00046 unsigned char *local; 00047 int local_length; /* In octets. */ 00048 00049 /* Remote transport address (in relevant SNMP-style encoding). */ 00050 00051 unsigned char *remote; 00052 int remote_length; /* In octets. */ 00053 00054 /* The actual socket. */ 00055 00056 int sock; 00057 00058 /* Flags (see #definitions above). */ 00059 00060 unsigned int flags; 00061 00062 /* Protocol-specific opaque data pointer. */ 00063 00064 void *data; 00065 int data_length; 00066 00067 /* Maximum size of PDU that can be sent/received by this transport. */ 00068 00069 size_t msgMaxSize; 00070 00071 /* Callbacks. Arguments are: 00072 * 00073 * "this" pointer, fd, buf, size, *opaque, *opaque_length 00074 */ 00075 00076 int (*f_recv) (struct netsnmp_transport_s *, void *, 00077 int, void **, int *); 00078 int (*f_send) (struct netsnmp_transport_s *, void *, 00079 int, void **, int *); 00080 int (*f_close) (struct netsnmp_transport_s *); 00081 00082 /* This callback is only necessary for stream-oriented transports. */ 00083 00084 int (*f_accept) (struct netsnmp_transport_s *); 00085 00086 /* Optional callback to format a transport address. */ 00087 00088 char *(*f_fmtaddr)(struct netsnmp_transport_s *, void *, 00089 int); 00090 } netsnmp_transport; 00091 00092 typedef struct netsnmp_transport_list_s { 00093 netsnmp_transport *transport; 00094 struct netsnmp_transport_list_s *next; 00095 } netsnmp_transport_list; 00096 00097 typedef struct netsnmp_tdomain_s { 00098 const oid *name; 00099 size_t name_length; 00100 const char **prefix; 00101 00102 /* 00103 * The f_create_from_tstring field is deprecated, please do not use it 00104 * for new code and try to migrate old code away from using it. 00105 */ 00106 netsnmp_transport *(*f_create_from_tstring) (const char *, int); 00107 00108 netsnmp_transport *(*f_create_from_ostring) (const u_char *, size_t, int); 00109 00110 struct netsnmp_tdomain_s *next; 00111 00112 netsnmp_transport *(*f_create_from_tstring_new) (const char *, int, 00113 const char*); 00114 00115 } netsnmp_tdomain; 00116 00117 00118 /* Some utility functions. */ 00119 00120 int netsnmp_transport_add_to_list(netsnmp_transport_list **transport_list, 00121 netsnmp_transport *transport); 00122 int netsnmp_transport_remove_from_list(netsnmp_transport_list **transport_list, 00123 netsnmp_transport *transport); 00124 00125 00126 /* 00127 * Return an exact (deep) copy of t, or NULL if there is a memory allocation 00128 * problem (for instance). 00129 */ 00130 00131 netsnmp_transport *netsnmp_transport_copy(netsnmp_transport *t); 00132 00133 00134 /* Free an netsnmp_transport. */ 00135 00136 void netsnmp_transport_free(netsnmp_transport *t); 00137 00138 00139 /* 00140 * If the passed oid (in_oid, in_len) corresponds to a supported transport 00141 * domain, return 1; if not return 0. If out_oid is not NULL and out_len is 00142 * not NULL, then the "internal" oid which should be used to identify this 00143 * domain (e.g. in pdu->tDomain etc.) is written to *out_oid and its length to 00144 * *out_len. 00145 */ 00146 00147 int netsnmp_tdomain_support(const oid *in_oid, size_t in_len, 00148 const oid **out_oid, size_t *out_len); 00149 00150 int netsnmp_tdomain_register(netsnmp_tdomain *domain); 00151 00152 int netsnmp_tdomain_unregister(netsnmp_tdomain *domain); 00153 00154 void netsnmp_clear_tdomain_list(void); 00155 00156 void netsnmp_tdomain_init(void); 00157 00158 netsnmp_transport *netsnmp_tdomain_transport(const char *str, 00159 int local, 00160 const char *default_domain); 00161 00162 netsnmp_transport *netsnmp_tdomain_transport_full(const char *application, 00163 const char *str, 00164 int local, 00165 const char *default_domain, 00166 const char *default_target); 00167 00168 netsnmp_transport *netsnmp_tdomain_transport_oid(const oid * dom, 00169 size_t dom_len, 00170 const u_char * o, 00171 size_t o_len, 00172 int local); 00173 00174 netsnmp_transport* 00175 netsnmp_transport_open_client(const char* application, const char* str); 00176 00177 netsnmp_transport* 00178 netsnmp_transport_open_server(const char* application, const char* str); 00179 00180 netsnmp_transport* 00181 netsnmp_transport_open(const char* application, const char* str, int local); 00182 00183 #ifdef __cplusplus 00184 } 00185 #endif 00186 #endif/*_SNMP_TRANSPORT_H*/