Fixed some bugs in node creation
[public/netxms.git] / src / console / win32 / CreateNodeDlg.cpp
CommitLineData
7e3eff61
VK
1// CreateNodeDlg.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "nxcon.h"
6#include "CreateNodeDlg.h"
7
8#ifdef _DEBUG
9#define new DEBUG_NEW
10#undef THIS_FILE
11static char THIS_FILE[] = __FILE__;
12#endif
13
14/////////////////////////////////////////////////////////////////////////////
15// CCreateNodeDlg dialog
16
17
18CCreateNodeDlg::CCreateNodeDlg(CWnd* pParent /*=NULL*/)
19 : CCreateObjectDlg(CCreateNodeDlg::IDD, pParent)
20{
21 //{{AFX_DATA_INIT(CCreateNodeDlg)
7e3eff61
VK
22 //}}AFX_DATA_INIT
23}
24
25
26void CCreateNodeDlg::DoDataExchange(CDataExchange* pDX)
27{
28 CCreateObjectDlg::DoDataExchange(pDX);
29 //{{AFX_DATA_MAP(CCreateNodeDlg)
bcb07fad 30 DDX_Control(pDX, IDC_EDIT_NAME, m_wndObjectName);
7e3eff61
VK
31 DDX_Control(pDX, IDC_IP_ADDR, m_wndIPAddr);
32 //}}AFX_DATA_MAP
33}
34
35
36BEGIN_MESSAGE_MAP(CCreateNodeDlg, CCreateObjectDlg)
37 //{{AFX_MSG_MAP(CCreateNodeDlg)
bcb07fad 38 ON_BN_CLICKED(IDC_BUTTON_RESOLVE, OnButtonResolve)
7e3eff61
VK
39 //}}AFX_MSG_MAP
40END_MESSAGE_MAP()
41
42/////////////////////////////////////////////////////////////////////////////
43// CCreateNodeDlg message handlers
44
45
46//
47// "OK" button handler
48//
49
50void CCreateNodeDlg::OnOK()
51{
7cbe553e
VK
52 int iNumBytes;
53
54 iNumBytes = m_wndIPAddr.GetAddress(m_dwIpAddr);
55 if ((iNumBytes != 0) && (iNumBytes != 4))
56 {
57 MessageBox(_T("Invalid IP address"), _T("Warning"), MB_OK | MB_ICONEXCLAMATION);
58 }
59 else
60 {
61 if (iNumBytes == 0)
62 m_dwIpAddr = 0;
63 if ((m_pParentObject == NULL) && (m_dwIpAddr == 0))
64 MessageBox(_T("Node without IP address and parent container object cannot be created"),
65 _T("Warning"), MB_OK | MB_ICONEXCLAMATION);
66 else
67 CCreateObjectDlg::OnOK();
68 }
7e3eff61 69}
bcb07fad
VK
70
71
72//
73// "Resolve" button handler
74//
75
76void CCreateNodeDlg::OnButtonResolve()
77{
78 TCHAR szHostName[256];
79 struct hostent *hs;
80 DWORD dwAddr = INADDR_NONE;
81
82 m_wndObjectName.GetWindowText(szHostName, 256);
83 hs = gethostbyname(szHostName);
84 if (hs != NULL)
85 {
86 memcpy(&dwAddr, hs->h_addr, sizeof(DWORD));
87 }
88 else
89 {
90 dwAddr = inet_addr(szHostName);
91 }
92
93 if (dwAddr != INADDR_NONE)
94 {
95 m_wndIPAddr.SetAddress(ntohl(dwAddr));
96 }
97 else
98 {
99 MessageBox(_T("Unable to resolve host name!"), _T("Error"), MB_OK | MB_ICONSTOP);
100 }
101}