1 // NAME
2 // $RCSfile: AsnEncoderBase.java,v $
3 // DESCRIPTION
4 // [given below in javadoc format]
5 // DELTA
6 // $Revision: 3.2 $
7 // CREATED
8 // $Date: 2006/01/17 17:43:53 $
9 // COPYRIGHT
10 // Westhawk Ltd
11 // TO DO
12 //
13
14 /*
15 * Copyright (C) 1995, 1996 by West Consulting BV
16 *
17 * Permission to use, copy, modify, and distribute this software
18 * for any purpose and without fee is hereby granted, provided
19 * that the above copyright notices appear in all copies and that
20 * both the copyright notice and this permission notice appear in
21 * supporting documentation.
22 * This software is provided "as is" without express or implied
23 * warranty.
24 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
25 * original version by hargrave@dellgate.us.dell.com (Jordan Hargrave)
26 */
27
28 /*
29 * Copyright (C) 1996 - 2006 by Westhawk Ltd
30 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
31 *
32 * Permission to use, copy, modify, and distribute this software
33 * for any purpose and without fee is hereby granted, provided
34 * that the above copyright notices appear in all copies and that
35 * both the copyright notice and this permission notice appear in
36 * supporting documentation.
37 * This software is provided "as is" without express or implied
38 * warranty.
39 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
40 */
41
42 package uk.co.westhawk.snmp.stack;
43
44 /*-
45 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
46 * SNMP Java Client
47 * ჻჻჻჻჻჻
48 * Copyright 2023 MetricsHub, Westhawk
49 * ჻჻჻჻჻჻
50 * This program is free software: you can redistribute it and/or modify
51 * it under the terms of the GNU Lesser General Public License as
52 * published by the Free Software Foundation, either version 3 of the
53 * License, or (at your option) any later version.
54 *
55 * This program is distributed in the hope that it will be useful,
56 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58 * GNU General Lesser Public License for more details.
59 *
60 * You should have received a copy of the GNU General Lesser Public
61 * License along with this program. If not, see
62 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
63 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
64 */
65 import java.io.*;
66 import java.util.*;
67
68 /**
69 * This class contains the general methods to encode a Pdu into bytes.
70 * We split the original class AsnEncoder into four classes.
71 *
72 * @since 4_14
73 * @author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
74 * @version $Revision: 3.2 $ $Date: 2006/01/17 17:43:53 $
75 */
76 class AsnEncoderBase extends Object {
77 private static final String version_id = "@(#)$Id: AsnEncoderBase.java,v 3.2 2006/01/17 17:43:53 birgit Exp $ Copyright Westhawk Ltd";
78
79 /**
80 * Encode PDU itself packet into bytes.
81 * The actual PDU encoding is the same for v1 to v3.
82 * Except for Trapv1, but we are not implementing that.
83 */
84 protected AsnObject EncodePdu(byte msg_type,
85 int pduId, int errstat, int errind, Enumeration ve)
86 throws IOException {
87 AsnObject asnPduObject, asnVBObject;
88
89 // kind of request
90 asnPduObject = new AsnSequence(msg_type);
91 asnPduObject.add(new AsnInteger(pduId)); // reqid
92 asnPduObject.add(new AsnInteger(errstat)); // errstat
93 asnPduObject.add(new AsnInteger(errind)); // errindex
94
95 // Create VarbindList sequence
96 AsnObject asnVBLObject = asnPduObject.add(new AsnSequence());
97
98 // Add variable bindings
99 while (ve.hasMoreElements()) {
100 asnVBObject = asnVBLObject.add(new AsnSequence());
101 varbind vb = (varbind) ve.nextElement();
102 asnVBObject.add(vb.getOid());
103 asnVBObject.add(vb.getValue());
104 }
105
106 return asnPduObject;
107 }
108
109 }