"Fossies" - the Fresh Open Source Software Archive 
Member "netxms-3.8.166/src/server/drivers/ignitenet/ignitenet.cpp" (23 Feb 2021, 4505 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "ignitenet.cpp" see the
Fossies "Dox" file reference documentation and the last
Fossies "Diffs" side-by-side code changes report:
3.6.300_vs_3.7.95.
1 /*
2 ** NetXMS - Network Management System
3 ** Driver for IgniteNet devices
4 ** Copyright (C) 2003-2017 Raden Solutions
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: ignitenet.cpp
21 **/
22
23 #include "ignitenet.h"
24 #include <netxms-version.h>
25
26 /**
27 * Driver name
28 */
29 static TCHAR s_driverName[] = _T("IGNITENET");
30
31 /**
32 * Driver version
33 */
34 static TCHAR s_driverVersion[] = NETXMS_VERSION_STRING;
35
36 /**
37 * Get driver name
38 */
39 const TCHAR *IgniteNetDriver::getName()
40 {
41 return s_driverName;
42 }
43
44 /**
45 * Get driver version
46 */
47 const TCHAR *IgniteNetDriver::getVersion()
48 {
49 return s_driverVersion;
50 }
51
52 /**
53 * Check if given device can be potentially supported by driver
54 *
55 * @param oid Device OID
56 */
57 int IgniteNetDriver::isPotentialDevice(const TCHAR *oid)
58 {
59 return !_tcscmp(oid, _T(".1.3.6.1.4.1.47307")) ? 254 : 0;
60 }
61
62 /**
63 * Check if given device is supported by driver
64 *
65 * @param snmp SNMP transport
66 * @param oid Device OID
67 */
68 bool IgniteNetDriver::isDeviceSupported(SNMP_Transport *snmp, const TCHAR *oid)
69 {
70 return true;
71 }
72
73 /**
74 * Get interface state. Both states must be set to UNKNOWN if cannot be read from device.
75 *
76 * @param snmp SNMP transport
77 * @param node Node
78 * @param driverData driver's data
79 * @param ifIndex interface index
80 * @param adminState OUT: interface administrative state
81 * @param operState OUT: interface operational state
82 */
83 void IgniteNetDriver::getInterfaceState(SNMP_Transport *snmp, NObject *node, DriverData *driverData, UINT32 ifIndex,
84 int ifTableSuffixLen, UINT32 *ifTableSuffix, InterfaceAdminState *adminState, InterfaceOperState *operState)
85 {
86 UINT32 state = 0;
87 TCHAR oid[256], suffix[128];
88 if (ifTableSuffixLen > 0)
89 _sntprintf(oid, 256, _T(".1.3.6.1.2.1.2.2.1.7%s"), SNMPConvertOIDToText(ifTableSuffixLen, ifTableSuffix, suffix, 128)); // Interface administrative state
90 else
91 _sntprintf(oid, 256, _T(".1.3.6.1.2.1.2.2.1.7.%d"), (int)ifIndex); // Interface administrative state
92 SnmpGet(snmp->getSnmpVersion(), snmp, oid, NULL, 0, &state, sizeof(UINT32), 0);
93
94 // IgniteNet devices may not support interface administrative state reading through SNMP
95 // Assume interface administratively UP
96 if (state == 0)
97 state = 1;
98
99 switch(state)
100 {
101 case 2:
102 *adminState = IF_ADMIN_STATE_DOWN;
103 *operState = IF_OPER_STATE_DOWN;
104 break;
105 case 1:
106 case 3:
107 *adminState = (InterfaceAdminState)state;
108 // Get interface operational state
109 state = 0;
110 if (ifTableSuffixLen > 0)
111 _sntprintf(oid, 256, _T(".1.3.6.1.2.1.2.2.1.8%s"), SNMPConvertOIDToText(ifTableSuffixLen, ifTableSuffix, suffix, 128));
112 else
113 _sntprintf(oid, 256, _T(".1.3.6.1.2.1.2.2.1.8.%d"), (int)ifIndex);
114 SnmpGet(snmp->getSnmpVersion(), snmp, oid, NULL, 0, &state, sizeof(UINT32), 0);
115 switch(state)
116 {
117 case 3:
118 *operState = IF_OPER_STATE_TESTING;
119 break;
120 case 2: // down: interface is down
121 case 7: // lowerLayerDown: down due to state of lower-layer interface(s)
122 *operState = IF_OPER_STATE_DOWN;
123 break;
124 case 1:
125 *operState = IF_OPER_STATE_UP;
126 break;
127 default:
128 *operState = IF_OPER_STATE_UNKNOWN;
129 break;
130 }
131 break;
132 default:
133 *adminState = IF_ADMIN_STATE_UNKNOWN;
134 *operState = IF_OPER_STATE_UNKNOWN;
135 break;
136 }
137 }
138
139 /**
140 * Driver entry point
141 */
142 DECLARE_NDD_ENTRY_POINT(IgniteNetDriver);
143
144 /**
145 * DLL entry point
146 */
147 #ifdef _WIN32
148
149 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
150 {
151 if (dwReason == DLL_PROCESS_ATTACH)
152 DisableThreadLibraryCalls(hInstance);
153 return TRUE;
154 }
155
156 #endif