-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInetAddr.h
69 lines (53 loc) · 1.27 KB
/
InetAddr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// InetAddr.h: interface for the CInetAddr class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_INETADDR_H__5A4723FF_6B0B_4F9C_A3AA_7241A6F5CB8C__INCLUDED_)
#define AFX_INETADDR_H__5A4723FF_6B0B_4F9C_A3AA_7241A6F5CB8C__INCLUDED_
#include "common.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ClassLib\sockets.h"
class CInetAddr
{
private:
ULONG m_ulAddr;
public:
CInetAddr() : m_ulAddr(0) { }
CInetAddr(ULONG ulAddr)
{
m_ulAddr = htonl(ulAddr);
}
BOOL LookUp(LPTSTR szAddr)
{
assert(szAddr != NULL);
if (szAddr == NULL)
return FALSE;
#ifdef UNICODE
CHAR szTemp[1024];
size_t converted = 0;
wcstombs_s(&converted, szTemp, 1024, szAddr, 1024);
m_ulAddr = inet_addr(szTemp);
#else
m_ulAddr = inet_addr(szAddr);
#endif
if (m_ulAddr == INADDR_NONE)
{
struct hostent* HostInf;
#ifdef UNICODE
HostInf = gethostbyname(szTemp);
#else
HostInf = gethostbyname(szAddr);
#endif
if (HostInf == NULL)
return FALSE;
m_ulAddr = *((PULONG)HostInf->h_addr_list[0]);
}
return TRUE;
}
operator ULONG()
{
return m_ulAddr;
}
};
#endif // !defined(AFX_INETADDR_H__5A4723FF_6B0B_4F9C_A3AA_7241A6F5CB8C__INCLUDED_)