View Javadoc
1   // NAME
2   //      $RCSfile: AsnTrapPduv1Sequence.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.6 $
7   // CREATED
8   //      $Date: 2006/01/17 17:43:54 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  /*
15   * Copyright (C) 2001 - 2006 by Westhawk Ltd
16   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17   *
18   * Permission to use, copy, modify, and distribute this software
19   * for any purpose and without fee is hereby granted, provided
20   * that the above copyright notices appear in all copies and that
21   * both the copyright notice and this permission notice appear in
22   * supporting documentation.
23   * This software is provided "as is" without express or implied
24   * warranty.
25   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26   */
27  
28  package uk.co.westhawk.snmp.stack;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * SNMP Java Client
33   * ჻჻჻჻჻჻
34   * Copyright 2023 MetricsHub, Westhawk
35   * ჻჻჻჻჻჻
36   * This program is free software: you can redistribute it and/or modify
37   * it under the terms of the GNU Lesser General Public License as
38   * published by the Free Software Foundation, either version 3 of the
39   * License, or (at your option) any later version.
40   *
41   * This program is distributed in the hope that it will be useful,
42   * but WITHOUT ANY WARRANTY; without even the implied warranty of
43   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44   * GNU General Lesser Public License for more details.
45   *
46   * You should have received a copy of the GNU General Lesser Public
47   * License along with this program.  If not, see
48   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50   */
51  
52  import java.io.*;
53  import java.util.*;
54  
55  /**
56   * The AsnTrapPduv1Sequence class knows how a TrapPdu v1 is build, it knows its
57   * sequence.
58   *
59   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
60   * @version $Revision: 3.6 $ $Date: 2006/01/17 17:43:54 $
61   */
62  class AsnTrapPduv1Sequence extends AsnSequence {
63      private static final String version_id = "@(#)$Id: AsnTrapPduv1Sequence.java,v 3.6 2006/01/17 17:43:54 birgit Exp $ Copyright Westhawk Ltd";
64  
65      AsnTrapPduv1Sequence(InputStream in, int len, int pos) throws IOException {
66          super(in, len, pos);
67      }
68  
69      String getEnterprise() throws DecodingException {
70          String ent = "";
71          AsnObject obj = getObj(0);
72          if (obj instanceof AsnObjectId) {
73              AsnObjectId rid = (AsnObjectId) obj;
74              ent = rid.getValue();
75          } else {
76              String msg = "TrapPduv1.Enterprise should be AsnObjectId"
77                      + " instead of " + obj.getRespTypeString();
78              throw new DecodingException(msg);
79          }
80          return ent;
81      }
82  
83      byte[] getIPAddress() throws DecodingException {
84          byte[] ip = null;
85          AsnObject obj = getObj(1);
86          if (obj instanceof AsnOctets) {
87              AsnOctets estat = (AsnOctets) obj;
88              ip = estat.getBytes();
89          } else {
90              String msg = "TrapPduv1.IPAddress should be of type AsnOctets"
91                      + " instead of " + obj.getRespTypeString();
92              throw new DecodingException(msg);
93          }
94          return ip;
95      }
96  
97      int getGenericTrap() throws DecodingException {
98          int genTrap = -1;
99          AsnObject obj = getObj(2);
100         if (obj instanceof AsnInteger) {
101             AsnInteger estat = (AsnInteger) obj;
102             genTrap = estat.getValue();
103         } else {
104             String msg = "TrapPduv1.GenericTrap should be of type AsnInteger"
105                     + " instead of " + obj.getRespTypeString();
106             throw new DecodingException(msg);
107         }
108         return genTrap;
109     }
110 
111     int getSpecificTrap() throws DecodingException {
112         int specTrap = -1;
113         AsnObject obj = getObj(3);
114         if (obj instanceof AsnInteger) {
115             AsnInteger estat = (AsnInteger) obj;
116             specTrap = estat.getValue();
117         } else {
118             String msg = "TrapPduv1.SpecificTrap should be of type AsnInteger"
119                     + " instead of " + obj.getRespTypeString();
120             throw new DecodingException(msg);
121         }
122         return specTrap;
123 
124     }
125 
126     long getTimeTicks() throws DecodingException {
127         long ticks = -1;
128         AsnObject obj = getObj(4);
129         if (obj instanceof AsnUnsInteger) {
130             AsnUnsInteger estat = (AsnUnsInteger) obj;
131             ticks = estat.getValue();
132         } else {
133             String msg = "TrapPduv1.TimeTicks should be of type AsnUnsInteger"
134                     + " instead of " + obj.getRespTypeString();
135             throw new DecodingException(msg);
136         }
137         return ticks;
138     }
139 
140     AsnSequence getVarBind() throws DecodingException {
141         AsnSequence varb = null;
142         AsnObject obj = getObj(5);
143         if (obj instanceof AsnSequence) {
144             varb = (AsnSequence) obj;
145         } else {
146             String msg = "TrapPduv1.VarBind should be of type AsnSequence"
147                     + " instead of " + obj.getRespTypeString();
148             throw new DecodingException(msg);
149         }
150         return varb;
151     }
152 
153     /**
154      * recursively look for a trapPduv1Sequence object
155      * - got one :-)
156      */
157     AsnObject findTrapPduv1() {
158         return this;
159     }
160 
161 }