]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/snmplib/coexistance.c
Cleanup: un-wrap C++ header includes
[thirdparty/squid.git] / lib / snmplib / coexistance.c
1 /*
2 * RFC 1908: Coexistence between SNMPv1 and SNMPv2
3 */
4 /**********************************************************************
5 *
6 * Copyright 1997 by Carnegie Mellon University
7 *
8 * All Rights Reserved
9 *
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and that
13 * both that copyright notice and this permission notice appear in
14 * supporting documentation, and that the name of CMU not be
15 * used in advertising or publicity pertaining to distribution of the
16 * software without specific, written prior permission.
17 *
18 * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
19 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
20 * CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
21 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 * SOFTWARE.
25 *
26 * Author: Ryan Troll <ryan+@andrew.cmu.edu>
27 *
28 **********************************************************************/
29
30 #include "squid.h"
31
32 #if HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35 #if HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38 #if HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
41 #if HAVE_CTYPE_H
42 #include <ctype.h>
43 #endif
44 #if HAVE_GNUMALLOC_H
45 #include <gnumalloc.h>
46 #elif HAVE_MALLOC_H
47 #include <malloc.h>
48 #endif
49 #if HAVE_MEMORY_H
50 #include <memory.h>
51 #endif
52 #if HAVE_STRING_H
53 #include <string.h>
54 #endif
55 #if HAVE_STRINGS_H
56 #include <strings.h>
57 #endif
58 #if HAVE_BSTRING_H
59 #include <bstring.h>
60 #endif
61 #if HAVE_SYS_SOCKET_H
62 #include <sys/socket.h>
63 #endif
64 #if HAVE_NETINET_IN_H
65 #include <netinet/in.h>
66 #endif
67 #if HAVE_ARPA_INET_H
68 #include <arpa/inet.h>
69 #endif
70 #if HAVE_SYS_TIME_H
71 #include <sys/time.h>
72 #endif
73 #if HAVE_NETDB_H
74 #include <netdb.h>
75 #endif
76
77 #include "asn1.h"
78 #include "snmp.h"
79 #include "snmp_api_error.h"
80 #include "snmp_error.h"
81 #include "snmp_pdu.h"
82 #include "snmp_vars.h"
83
84 #include "util.h"
85
86 /*
87 * RFC 1908: Coexistence between SNMPv1 and SNMPv2
88 *
89 * These convert:
90 *
91 * V1 PDUs from an ** AGENT ** to V2 PDUs for an ** MANAGER **
92 * V2 PDUs from an ** MANAGER ** to V1 PDUs for an ** AGENT **
93 *
94 * We will never convert V1 information from a manager into V2 PDUs. V1
95 * requests are always honored by V2 agents, and the responses will be
96 * valid V1 responses. (I think. XXXXX)
97 *
98 */
99 int
100 snmp_coexist_V2toV1(struct snmp_pdu *PDU)
101 {
102 /* Per 3.1.1:
103 */
104 switch (PDU->command) {
105
106 case SNMP_PDU_GET:
107 case SNMP_PDU_GETNEXT:
108 #if SNMP_PDU_SET
109 case SNMP_PDU_SET:
110 #endif
111 return (1);
112 break;
113
114 case SNMP_PDU_GETBULK:
115 PDU->non_repeaters = 0;
116 PDU->max_repetitions = 0;
117 PDU->command = SNMP_PDU_GETNEXT;
118 return (1);
119 break;
120
121 default:
122 snmplib_debug(2, "Unable to translate PDU %d to SNMPv1!\n", PDU->command);
123 snmp_set_api_error(SNMPERR_PDU_TRANSLATION);
124 return (0);
125 }
126 }