]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/snmplib/snmp_api.c
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /**********************************************************************
11 * Copyright 1997 by Carnegie Mellon University
15 * Permission to use, copy, modify, and distribute this software and its
16 * documentation for any purpose and without fee is hereby granted,
17 * provided that the above copyright notice appear in all copies and that
18 * both that copyright notice and this permission notice appear in
19 * supporting documentation, and that the name of CMU not be
20 * used in advertising or publicity pertaining to distribution of the
21 * software without specific, written prior permission.
23 * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 * CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31 **********************************************************************/
42 #include <sys/types.h>
48 #include <gnumalloc.h>
65 #include <sys/socket.h>
68 #include <netinet/in.h>
71 #include <arpa/inet.h>
83 #include "snmp-internal.h"
84 #include "snmp_error.h"
85 #include "snmp_impl.h"
88 #include "snmp_session.h"
89 #include "snmp_vars.h"
92 #include "snmp_api_error.h"
93 #include "snmp_api_util.h"
97 /**********************************************************************/
100 * Takes a session and a pdu and serializes the ASN PDU into the area
101 * pointed to by packet. out_length is the size of the data area available.
102 * Returns the length of the encoded packet in out_length. If an error
103 * occurs, -1 is returned. If all goes well, 0 is returned.
106 snmp_build(struct snmp_session
*session
, struct snmp_pdu
*pdu
, u_char
*packet
, int *out_length
)
110 bufp
= snmp_msg_Encode(packet
, out_length
,
111 session
->community
, session
->community_len
,
114 snmplib_debug(8, "LIBSNMP: snmp_build(): Packet len %d (requid %d)\n",
115 *out_length
, pdu
->reqid
);
124 * Parses the packet received on the input session, and places the data into
125 * the input pdu. length is the length of the input packet. If any errors
126 * are encountered, NULL is returned. If not, the community is.
129 snmp_parse(struct snmp_session
* session
,
130 struct snmp_pdu
* pdu
,
134 u_char Community
[128];
136 int CommunityLen
= 128;
138 /* Decode the entire message. */
139 data
= snmp_msg_Decode(data
, &length
,
140 Community
, &CommunityLen
,
141 &session
->Version
, pdu
);
145 bufp
= (u_char
*) xmalloc(CommunityLen
+ 1);
149 strncpy((char *) bufp
, (char *) Community
, CommunityLen
);
150 bufp
[CommunityLen
] = '\0';
152 session
->community
= bufp
;
153 session
->community_len
= CommunityLen
;