a5612b653660e9e0c96adfe823be4be88a253555
[public/netxms.git] / src / libnxcl / layer2.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Client Library
4 ** Copyright (C) 2004, 2005, 2006, 2007 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 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 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: layer2.cpp
21 **
22 **/
23
24 #include "libnxcl.h"
25 #include <netxms_maps.h>
26
27
28 //
29 // Query layer 2 topology from device
30 //
31
32 DWORD LIBNXCL_EXPORTABLE NXCQueryL2Topology(NXC_SESSION hSession, DWORD dwNodeId, void **ppTopology)
33 {
34 CSCPMessage msg, *pResponse;
35 DWORD dwRetCode, dwRqId;
36
37 *ppTopology = NULL;
38 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
39
40 msg.SetCode(CMD_QUERY_L2_TOPOLOGY);
41 msg.SetId(dwRqId);
42 msg.SetVariable(VID_OBJECT_ID, dwNodeId);
43 ((NXCL_Session *)hSession)->SendMsg(&msg);
44
45 pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
46 if (pResponse != NULL)
47 {
48 dwRetCode = pResponse->GetVariableLong(VID_RCC);
49 if (dwRetCode == RCC_SUCCESS)
50 {
51 *ppTopology = new nxmap_ObjList(pResponse);
52 }
53 delete pResponse;
54 }
55 else
56 {
57 dwRetCode = RCC_TIMEOUT;
58 }
59 return dwRetCode;
60 }