1 // NAME 2 // $RCSfile: InterfacesPdu.java,v $ 3 // DESCRIPTION 4 // [given below in javadoc format] 5 // DELTA 6 // $Revision: 3.12 $ 7 // CREATED 8 // $Date: 2006/11/29 16:12:50 $ 9 // COPYRIGHT 10 // Westhawk Ltd 11 // TO DO 12 // 13 14 /* 15 * Copyright (C) 1996 - 1998 by Westhawk Ltd (www.westhawk.nl) 16 * Copyright (C) 1998 - 2006 by Westhawk Ltd 17 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a> 18 * 19 * Permission to use, copy, modify, and distribute this software 20 * for any purpose and without fee is hereby granted, provided 21 * that the above copyright notices appear in all copies and that 22 * both the copyright notice and this permission notice appear in 23 * supporting documentation. 24 * This software is provided "as is" without express or implied 25 * warranty. 26 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a> 27 */ 28 29 package uk.co.westhawk.snmp.pdu; 30 31 /*- 32 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 33 * SNMP Java Client 34 * ჻჻჻჻჻჻ 35 * Copyright 2023 MetricsHub, Westhawk 36 * ჻჻჻჻჻჻ 37 * This program is free software: you can redistribute it and/or modify 38 * it under the terms of the GNU Lesser General Public License as 39 * published by the Free Software Foundation, either version 3 of the 40 * License, or (at your option) any later version. 41 * 42 * This program is distributed in the hope that it will be useful, 43 * but WITHOUT ANY WARRANTY; without even the implied warranty of 44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 45 * GNU General Lesser Public License for more details. 46 * 47 * You should have received a copy of the GNU General Lesser Public 48 * License along with this program. If not, see 49 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 50 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 51 */ 52 import uk.co.westhawk.snmp.stack.*; 53 import java.util.*; 54 55 /** 56 * The InterfacesPdu class will ask for the number of current interfaces. 57 * For each interface it will send an InterfacePdu to get the 58 * information of the specific interface. 59 * 60 * @see InterfacePdu 61 * 62 * @author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a> 63 * @version $Revision: 3.12 $ $Date: 2006/11/29 16:12:50 $ 64 * 65 */ 66 public class InterfacesPdu extends InterfacePdu { 67 private static final String version_id = "@(#)$Id: InterfacesPdu.java,v 3.12 2006/11/29 16:12:50 birgit Exp $ Copyright Westhawk Ltd"; 68 69 /** 70 * ifNumber 71 * The number of network interfaces (regardless of their current state) 72 * present on this system. 73 */ 74 final static String IFNUMBER = "1.3.6.1.2.1.2.1.0"; 75 76 InterfacePdu[] ifs; 77 78 /** 79 * Constructor that will send the request immediately. 80 * 81 * @param con the SnmpContextBasisFace 82 * @param o the Observer that will be notified when the answer is received 83 * @param interfs the index of the requested interface 84 */ 85 public InterfacesPdu(SnmpContextBasisFace con, Observer o, int interfs) 86 throws PduException, java.io.IOException { 87 super(con); 88 ifs = new InterfacePdu[interfs]; 89 for (int interf = 0; interf < interfs; interf++) { 90 addOids(interf); 91 ifs[interf] = new InterfacePdu(con); 92 } 93 if (o != null) { 94 addObserver(o); 95 } 96 send(); 97 } 98 99 /** 100 * Returns the interfaces. 101 * 102 * @return the interfaces as an array of InterfacePdu 103 */ 104 public InterfacePdu[] getInterfacePdus() { 105 return ifs; 106 } 107 108 /** 109 * The value of the request is set. This will be called by 110 * Pdu.fillin(). 111 * 112 * @param n the index of the value 113 * @param res the value 114 * @see Pdu#new_value 115 */ 116 protected void new_value(int n, varbind res) { 117 int thif = n / 4; 118 if (thif < ifs.length) { 119 ifs[thif].new_value(n % 4, res); 120 } 121 } 122 123 }