added files
[bcm963xx.git] / userapps / opensource / net-snmp / include / net-snmp / library / snmp_transport.h
1 #ifndef _SNMP_TRANSPORT_H
2 #define _SNMP_TRANSPORT_H
3
4 #include <sys/types.h>
5 #include <net-snmp/library/asn1.h>
6
7 #ifdef __cplusplus
8 extern          "C" {
9 #endif
10
11 /*  Some transport-type constants.  */
12
13 #ifndef NETSNMP_STREAM_QUEUE_LEN
14 #define NETSNMP_STREAM_QUEUE_LEN        5
15 #endif
16
17 /*  Some transport-type flags.  */
18
19 #define         NETSNMP_TRANSPORT_FLAG_STREAM   0x01
20 #define         NETSNMP_TRANSPORT_FLAG_LISTEN   0x02
21
22 /*  The standard SNMP domains.  */
23
24 extern oid      netsnmpUDPDomain[];     /*      = { 1, 3, 6, 1, 6, 1, 1 };  */
25 extern oid      netsnmpCLNSDomain[];    /*      = { 1, 3, 6, 1, 6, 1, 2 };  */
26 extern oid      netsnmpCONSDomain[];    /*      = { 1, 3, 6, 1, 6, 1, 3 };  */
27 extern oid      netsnmpDDPDomain[];     /*      = { 1, 3, 6, 1, 6, 1, 4 };  */
28 extern oid      netsnmpIPXDomain[];     /*      = { 1, 3, 6, 1, 6, 1, 5 };  */
29 extern size_t   netsnmpUDPDomain_len;
30 extern size_t   netsnmpCLNSDomain_len;
31 extern size_t   netsnmpCONSDomain_len;
32 extern size_t   netsnmpDDPDomain_len;
33 extern size_t   netsnmpIPXDomain_len;
34
35 /*  Structure which defines the transport-independent API.  */
36
37 typedef struct netsnmp_transport_s {
38     /*  The transport domain object identifier.  */
39
40     const oid      *domain;
41     int             domain_length;  /*  In sub-IDs, not octets.  */
42
43     /*  Local transport address (in relevant SNMP-style encoding).  */
44     
45     unsigned char  *local;
46     int             local_length;   /*  In octets.  */
47
48     /*  Remote transport address (in relevant SNMP-style encoding).  */
49
50     unsigned char  *remote;
51     int             remote_length;  /*  In octets.  */
52
53     /*  The actual socket.  */
54     
55     int             sock;
56
57     /*  Flags (see #definitions above).  */
58
59     unsigned int    flags;
60
61     /*  Protocol-specific opaque data pointer.  */
62
63     void           *data;
64     int             data_length;
65
66     /*  Maximum size of PDU that can be sent/received by this transport.  */
67
68     size_t          msgMaxSize;
69
70     /*  Callbacks.  Arguments are:
71      *          
72      *              "this" pointer, fd, buf, size, *opaque, *opaque_length  
73      */
74
75     int             (*f_recv)   (struct netsnmp_transport_s *, void *,
76                                  int, void **, int *);
77     int             (*f_send)   (struct netsnmp_transport_s *, void *,
78                                  int, void **, int *);
79     int             (*f_close)  (struct netsnmp_transport_s *);
80
81     /*  This callback is only necessary for stream-oriented transports.  */
82
83     int             (*f_accept) (struct netsnmp_transport_s *);
84
85     /*  Optional callback to format a transport address.  */
86
87     char           *(*f_fmtaddr)(struct netsnmp_transport_s *, void *,
88                                  int);
89 } netsnmp_transport;
90
91 typedef struct netsnmp_transport_list_s {
92     netsnmp_transport *transport;
93     struct netsnmp_transport_list_s *next;
94 } netsnmp_transport_list;
95
96 typedef struct netsnmp_tdomain_s {
97     const oid      *name;
98     size_t          name_length;
99     const char    **prefix;
100     netsnmp_transport *(*f_create_from_tstring) (const char *, int);
101     netsnmp_transport *(*f_create_from_ostring) (const u_char *,  size_t, int);
102
103     struct netsnmp_tdomain_s *next;
104 } netsnmp_tdomain;
105
106
107 /*  Some utility functions.  */
108
109 int netsnmp_transport_add_to_list(netsnmp_transport_list **transport_list,
110                                   netsnmp_transport *transport);
111 int netsnmp_transport_remove_from_list(netsnmp_transport_list **transport_list,
112                                        netsnmp_transport *transport);
113
114
115 /*
116  * Return an exact (deep) copy of t, or NULL if there is a memory allocation
117  * problem (for instance).
118  */
119
120 netsnmp_transport *netsnmp_transport_copy(netsnmp_transport *t);
121
122
123 /*  Free an netsnmp_transport.  */
124
125 void            netsnmp_transport_free(netsnmp_transport *t);
126
127
128 /*
129  * If the passed oid (in_oid, in_len) corresponds to a supported transport
130  * domain, return 1; if not return 0.  If out_oid is not NULL and out_len is
131  * not NULL, then the "internal" oid which should be used to identify this
132  * domain (e.g. in pdu->tDomain etc.) is written to *out_oid and its length to
133  * *out_len.
134  */
135
136 int             netsnmp_tdomain_support(const oid *in_oid, size_t in_len,
137                                         const oid **out_oid, size_t *out_len);
138
139 int             netsnmp_tdomain_register(netsnmp_tdomain *domain);
140     
141 int             netsnmp_tdomain_unregister(netsnmp_tdomain *domain);
142
143 void            netsnmp_tdomain_init(void);
144
145 netsnmp_transport *netsnmp_tdomain_transport(const char *string,
146                                              int local,
147                                              const char
148                                              *default_domain);
149
150 netsnmp_transport *netsnmp_tdomain_transport_oid(const oid * dom,
151                                                  size_t dom_len,
152                                                  const u_char * o,
153                                                  size_t o_len,
154                                                  int local);
155
156 #ifdef __cplusplus
157 }
158 #endif
159 #endif/*_SNMP_TRANSPORT_H*/