1 | /*
|
---|
2 | #ifdef UNICODE
|
---|
3 | Const _FuncName_getaddrinfo = "GetAddrInfoW"
|
---|
4 | Const _FuncName_freeaddrinfo = "FreeAddrInfoW"
|
---|
5 | Const _FuncName_getnameinfo = "GetNameInfoW"
|
---|
6 | Const _FuncName_inet_pton = "InetPtonW"
|
---|
7 | Const _FuncName_inet_ntop = "InetNtopW"
|
---|
8 | #else
|
---|
9 | Const _FuncName_getaddrinfo = "GetAddrInfoA"
|
---|
10 | Const _FuncName_freeaddrinfo = "FreeAddrInfoA"
|
---|
11 | Const _FuncName_getnameinfo = "GetNameInfoA"
|
---|
12 | Const _FuncName_inet_pton = "InetPton"
|
---|
13 | Const _FuncName_inet_ntop = "InetNtop"
|
---|
14 | #endif
|
---|
15 | */
|
---|
16 |
|
---|
17 | Const _FuncName_getaddrinfo = "getaddrinfo"
|
---|
18 | Const _FuncName_freeaddrinfo = "freeaddrinfo"
|
---|
19 | Const _FuncName_getnameinfo = "getnameinfo"
|
---|
20 |
|
---|
21 | Const INET_ADDRSTRLEN = 22
|
---|
22 | Const INET6_ADDRSTRLEN = 65
|
---|
23 |
|
---|
24 | Const EAI_AGAIN = WSATRY_AGAIN
|
---|
25 | Const EAI_BADFLAGS = WSAEINVAL
|
---|
26 | Const EAI_FAIL = WSANO_RECOVERY
|
---|
27 | Const EAI_FAMILY = WSAEAFNOSUPPORT
|
---|
28 | Const EAI_MEMORY = WSA_NOT_ENOUGH_MEMORY
|
---|
29 | 'Const EAI_NODATA = WSANO_DATA
|
---|
30 | Const EAI_NONAME = WSAHOST_NOT_FOUND
|
---|
31 | Const EAI_SERVICE = WSATYPE_NOT_FOUND
|
---|
32 | Const EAI_SOCKTYPE = WSAESOCKTNOSUPPORT
|
---|
33 |
|
---|
34 | Const EAI_NODATA = EAI_NONAME
|
---|
35 |
|
---|
36 | Type addrinfo
|
---|
37 | ai_flags As Long
|
---|
38 | ai_family As Long
|
---|
39 | ai_socktype As Long
|
---|
40 | ai_protocol As Long
|
---|
41 | ai_addrlen As DWord
|
---|
42 | ai_canonname As PTSTR
|
---|
43 | ai_addr As *sockaddr
|
---|
44 | ai_next As *addrinfo
|
---|
45 | End Type
|
---|
46 |
|
---|
47 | Const AI_PASSIVE = &H00000001 ' Socket address will be used in bind() call
|
---|
48 | Const AI_CANONNAME = &H00000002 ' Return canonical name in first ai_canonname
|
---|
49 | Const AI_NUMERICHOST = &H00000004 ' Nodename must be a numeric address string
|
---|
50 | Const AI_NUMERICSERV = &H00000008 ' Servicename must be a numeric port number
|
---|
51 |
|
---|
52 | Const AI_ALL = &H00000100 ' Query both IP6 and IP4 with AI_V4MAPPED
|
---|
53 | Const AI_ADDRCONFIG = &H00000400 ' Resolution only if global address configured
|
---|
54 | Const AI_V4MAPPED = &H00000800 ' On v6 failure, query v4 and convert to V4MAPPED format
|
---|
55 |
|
---|
56 |
|
---|
57 | Const AI_NON_AUTHORITATIVE = &H4000 ' LUP_NON_AUTHORITATIVE
|
---|
58 | Const AI_SECURE = &H8000 'LUP_SECURE
|
---|
59 | Const AI_RETURN_PREFERRED_NAMES = &H10000 ' LUP_RETURN_PREFERRED_NAMES
|
---|
60 |
|
---|
61 | TypeDef socklen_t = Long
|
---|
62 |
|
---|
63 | Declare Function getaddrinfo Lib "Ws2_32" Alias _FuncName_getaddrinfo (pNodeName As LPCTSTR, pServiceName As LPCTSTR, ByRef pHints As addrinfo, ByRef ppResult As *addrinfo) As Long
|
---|
64 | Declare Sub freeaddrinfo Lib "Ws2_32" Alias _FuncName_freeaddrinfo (ByRef ai As addrinfo)
|
---|
65 | Declare Function getnameinfo Lib "Ws2_32" Alias _FuncName_getnameinfo (ByRef sa As sockaddr, salen As socklen_t, host As LPTSTR, hostlen As SIZE_T, serv As LPTSTR, servlen As SIZE_T, flags As Long) As Long
|
---|
66 |
|
---|
67 | /*
|
---|
68 | Declare Function inet_pton Lib "Ws2_32" Alias _FuncName_inet_pton (family As Long, pszAddrString As LPCTSTR, pAddrBuf As VoidPtr) As Long
|
---|
69 | Declare Function inet_ntop Lib "Ws2_32" Alias _FuncName_inet_ntop (family As Long, pAddr As VoidPtr, pStringBuf As LPTSTR, StringBufSize As SIZE_T) As LPCTSTR
|
---|
70 | */
|
---|
71 |
|
---|
72 | Const GAI_STRERROR_BUFFER_SIZE = 1024
|
---|
73 | Function gai_strerror( ecode As Long) As LPCTSTR
|
---|
74 | Dim dwMsgLen As DWord
|
---|
75 | Dim buff[GAI_STRERROR_BUFFER_SIZE] As SByte
|
---|
76 | dwMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS,
|
---|
77 | NULL,
|
---|
78 | ecode,
|
---|
79 | LANG_USER_DEFAULT,
|
---|
80 | buff,
|
---|
81 | GAI_STRERROR_BUFFER_SIZE,
|
---|
82 | NULL)
|
---|
83 | Return buff
|
---|
84 | End Function
|
---|
85 |
|
---|
86 | Const NI_MAXHOST = 1025 /* Max size of a fully-qualified domain name */
|
---|
87 | Const NI_MAXSERV = 32 /* Max size of a service name */
|
---|
88 |
|
---|
89 | /* Flags for getnameinfo() */
|
---|
90 |
|
---|
91 | Const NI_NOFQDN = &H01 /* Only return nodename portion for local hosts */
|
---|
92 | Const NI_NUMERICHOST = &H02 /* Return numeric form of the host's address */
|
---|
93 | Const NI_NAMEREQD = &H04 /* Error if the host's name not in DNS */
|
---|
94 | Const NI_NUMERICSERV = &H08 /* Return numeric form of the service (port #) */
|
---|
95 | Const NI_DGRAM = &H10 /* Service is a datagram service */
|
---|