1 // NAME
2 // $RCSfile: RawPduEvent.java,v $
3 // DESCRIPTION
4 // [given below in javadoc format]
5 // DELTA
6 // $Revision: 1.5 $
7 // CREATED
8 // $Date: 2006/02/09 14:30:18 $
9 // COPYRIGHT
10 // Westhawk Ltd
11 // TO DO
12 //
13
14 /*
15 * Copyright (C) 2005 - 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 package uk.co.westhawk.snmp.event;
28
29 /*-
30 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
31 * SNMP Java Client
32 * ჻჻჻჻჻჻
33 * Copyright 2023 MetricsHub, Westhawk
34 * ჻჻჻჻჻჻
35 * This program is free software: you can redistribute it and/or modify
36 * it under the terms of the GNU Lesser General Public License as
37 * published by the Free Software Foundation, either version 3 of the
38 * License, or (at your option) any later version.
39 *
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Lesser Public License for more details.
44 *
45 * You should have received a copy of the GNU General Lesser Public
46 * License along with this program. If not, see
47 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
48 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
49 */
50
51 import uk.co.westhawk.snmp.stack.*;
52
53
54 /**
55 * The RawPduEvent class. This class is delivered when a undecoded pdu
56 * is received.
57 *
58 * @since 4_14
59 * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
60 * @version $Revision: 1.5 $ $Date: 2006/02/09 14:30:18 $
61 */
62 public class RawPduEvent extends java.util.EventObject {
63 private static final String version_id = "@(#)$Id: RawPduEvent.java,v 1.5 2006/02/09 14:30:18 birgit Exp $ Copyright Westhawk Ltd";
64
65 protected boolean consumed = false;
66
67 private int version;
68 private String hostAddress;
69 private int hostPort = -1;
70 private byte[] message;
71
72 /**
73 * The constructor for an undecoded pdu event. The ListeningContext
74 * class will fire undecoded pdu events.
75 *
76 * @param source The source (ListeningContext) of the event
77 * @param v The SNMP version of the pdu
78 * @param hn The IP address of the host where the pdu came from
79 * @param prt The remote port number of the host where the pdu came from
80 * @param mess The pdu in bytes
81 *
82 * @see #getVersion()
83 * @see #getHostAddress()
84 * @see #getHostPort()
85 * @see #getMessage()
86 */
87 public RawPduEvent(Object source, int v, String hn, byte[] mess, int prt) {
88 super(source);
89 version = v;
90 hostAddress = hn;
91 message = mess;
92 hostPort = prt;
93 }
94
95 /**
96 * The SNMP version number of the pdu.
97 *
98 * @return The version number.
99 * @see #getHostAddress()
100 * @see #getMessage()
101 * @see SnmpConstants#SNMP_VERSION_1
102 * @see SnmpConstants#SNMP_VERSION_2c
103 * @see SnmpConstants#SNMP_VERSION_3
104 */
105 public int getVersion() {
106 return version;
107 }
108
109 /**
110 * The IP address of the host where the pdu came from.
111 * Note, this is not necessarily the same as the IpAddress field in the
112 * SNMPv1 Pdu.
113 *
114 * @return The IP address of the host or null.
115 * @see #getVersion()
116 * @see #getMessage()
117 */
118 public String getHostAddress() {
119 return hostAddress;
120 }
121
122 /**
123 * The pdu SNMP message in bytes. This is a copy of the original
124 * message.
125 *
126 * @return The pdu in bytes.
127 * @see #getVersion()
128 * @see #getHostAddress()
129 */
130 public byte[] getMessage() {
131 return message;
132 }
133
134 /**
135 * The remote port number of the host where the pdu came from.
136 *
137 * @return The remote port number of the host or -1.
138 * @see #getVersion()
139 * @see #getMessage()
140 *
141 */
142 public int getHostPort() {
143 return hostPort;
144 }
145
146 /**
147 * Consumes this event so that it will not be sent to any other
148 * listeners.
149 */
150 public void consume() {
151 consumed = true;
152 }
153
154 /**
155 * Returns whether or not this event has been consumed.
156 *
157 * @see #consume
158 */
159 public boolean isConsumed() {
160 return consumed;
161 }
162
163 }