15 #include "mswhelper.h"
20 #define NSP_CALLID_DNS 0x0001
21 #define NSP_CALLID_HOSTNAME 0x0002
22 #define NSP_CALLID_HOSTBYNAME 0x0003
23 #define NSP_CALLID_SERVICEBYNAME 0x0004
28 #ifndef WS2_INTERNAL_MAX_ALIAS
29 #define WS2_INTERNAL_MAX_ALIAS 512
30 #endif // WS2_INTERNAL_MAX_ALIAS
32 //#define IP_LOCALHOST 0x0100007F
34 //#define NSP_REDIRECT
41 CHAR
** servaliasesA
; /* array */
43 } WSHOSTINFOINTERN
, *PWSHOSTINFOINTERN
;
46 GUID providerId
; /* Provider-ID */
47 DWORD dwControlFlags
; /* dwControlFlags (WSALookupServiceBegin) */
48 DWORD CallID
; /* List for LookupServiceNext-Calls */
49 DWORD CallIDCounter
; /* call-count of the current CallID. */
50 WCHAR
* hostnameW
; /* hostbyname */
55 } WSHANDLEINTERN
, *PWSHANDLEINTERN
;
57 static const GUID guid_NULL
= {0};
58 static const GUID guid_HOSTNAME
= SVCID_HOSTNAME
;
59 static const GUID guid_INET_HOSTADDRBYINETSTRING
= SVCID_INET_HOSTADDRBYINETSTRING
;
60 static const GUID guid_INET_HOSTADDRBYNAME
= SVCID_INET_HOSTADDRBYNAME
;
61 static const GUID guid_INET_SERVICEBYNAME
= SVCID_INET_SERVICEBYNAME
;
63 /* GUIDs - maybe they should be loaded from registry? */
65 static const GUID guid_mswsock_TcpIp
= {/*Data1:*/ 0x22059D40,
68 /*Data4:*/ {0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B}};
70 /* {6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83} */
72 static const GUID guid_mswsock_NLA
= {/*Data1:*/ 0x6642243A,
75 /*Data4:*/ {0xBA, 0xA5, 0x2E, 0x0B, 0xD7, 0x1F, 0xDD, 0x83}};
80 (CALLBACK
*lpRdrNSPStartup
)(
82 LPNSP_ROUTINE lpRout
);
84 const rdrLib
= "mswsock.dll-original";
85 lpRdrNSPStartup rdrNSPStartup
;
87 NSP_ROUTINE rdrproc_tcpip
;
88 NSP_ROUTINE rdrproc_nla
;
90 #endif /* NSP_REDIRECT */
97 LPNSP_ROUTINE lpRout
);
100 NSP_LookupServiceBeginW(
101 PWSHANDLEINTERN data
,
107 NSP_LookupServiceNextW(
108 _In_ PWSHANDLEINTERN data
,
110 _Inout_ LPWSAQUERYSETW lpRes
,
111 _Inout_ LPDWORD lpResLen
);
114 NSP_GetHostNameHeapAllocW(
115 _Out_ WCHAR
** hostname
);
118 NSP_GetHostByNameHeapAllocW(
120 _In_ GUID
* lpProviderId
,
121 _Out_ PWSHOSTINFOINTERN hostinfo
);
124 NSP_GetServiceByNameHeapAllocW(
126 _In_ GUID
* lpProviderId
,
127 _Out_ PWSHOSTINFOINTERN hostinfo
);
129 /* Implementations - Internal */
133 mwsNSPCleanUp(_In_ LPGUID lpProviderId
)
135 //WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
136 //return ERROR_CALL_NOT_IMPLEMENTED;
137 return ERROR_SUCCESS
;
143 return ERROR_SUCCESS
;
148 mwsNSPLookupServiceBegin(_In_ LPGUID lpProviderId
,
149 _In_ LPWSAQUERYSETW lpqsRestrictions
,
150 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
,
151 _In_ DWORD dwControlFlags
,
152 _Out_ LPHANDLE lphLookup
)
154 PWSHANDLEINTERN pLook
;
157 if (IsEqualGUID(lpProviderId
, &guid_mswsock_TcpIp
))
161 else if (IsEqualGUID(lpProviderId
, &guid_mswsock_NLA
))
163 WSASetLastError(WSASERVICE_NOT_FOUND
);
168 return ERROR_CALL_NOT_IMPLEMENTED
;
171 /* allocate internal structure */
172 pLook
= HeapAlloc(GetProcessHeap(), 0, sizeof(WSHANDLEINTERN
));
175 WSASetLastError(WSAEFAULT
);
179 *lphLookup
= (HANDLE
)pLook
;
181 RtlZeroMemory(pLook
, sizeof(*pLook
));
183 /* Anyway the ControlFlags "should" be needed
184 in NSPLookupServiceNext. (see doku) But
185 thats not the fact ATM. */
186 pLook
->dwControlFlags
= dwControlFlags
;
187 pLook
->providerId
= *lpProviderId
;
191 if (IsEqualGUID(lpProviderId
, &guid_mswsock_TcpIp
))
193 pLook
->rdrproc
= rdrproc_tcpip
;
195 else if (IsEqualGUID(lpProviderId
, &guid_mswsock_NLA
))
197 pLook
->rdrproc
= rdrproc_nla
;
201 return ERROR_CALL_NOT_IMPLEMENTED
;
204 if (pLook
->rdrproc
.NSPLookupServiceBegin(lpProviderId
,
208 &pLook
->rdrLookup
) == NO_ERROR
)
214 wsaErr
= WSAGetLastError();
219 res = WSAGetLastError();
222 #else /* NSP_REDIRECT */
224 wsaErr
= ERROR_CALL_NOT_IMPLEMENTED
;
225 if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
, &guid_NULL
))
227 wsaErr
= ERROR_CALL_NOT_IMPLEMENTED
;
229 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
, &guid_HOSTNAME
))
231 wsaErr
= NSP_LookupServiceBeginW(pLook
,
234 NSP_CALLID_HOSTNAME
);
236 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
,
237 &guid_INET_HOSTADDRBYNAME
))
239 wsaErr
= NSP_LookupServiceBeginW(pLook
,
241 lpqsRestrictions
->lpszServiceInstanceName
,
242 NSP_CALLID_HOSTBYNAME
);
244 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
,
245 &guid_INET_SERVICEBYNAME
))
247 wsaErr
= NSP_LookupServiceBeginW(pLook
,
249 lpqsRestrictions
->lpszServiceInstanceName
,
250 NSP_CALLID_SERVICEBYNAME
);
252 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
,
253 &guid_INET_HOSTADDRBYINETSTRING
))
255 wsaErr
= ERROR_CALL_NOT_IMPLEMENTED
;
258 #endif /* NSP_REDIRECT */
260 if (wsaErr
!= NO_ERROR
)
262 WSASetLastError(wsaErr
);
270 mwsNSPLookupServiceNext(_In_ HANDLE hLookup
,
271 _In_ DWORD dwControlFlags
,
272 _Inout_ LPDWORD lpdwBufferLength
,
273 //_Out_writes_bytes_to_(*lpdwBufferLength, *lpdwBufferLength)
274 LPWSAQUERYSETW lpqsResults
)
276 PWSHANDLEINTERN pLook
= hLookup
;
281 INT res
= pLook
->rdrproc
.NSPLookupServiceNext(pLook
->rdrLookup
,
285 wsaErr
= WSAGetLastError();
286 if (res
!= ERROR_SUCCESS
)
288 wsaErr
= WSAGetLastError();
294 #else /* NSP_REDIRECT */
296 if ((lpdwBufferLength
== NULL
) || (*lpdwBufferLength
== 0))
298 wsaErr
= WSA_NOT_ENOUGH_MEMORY
;
302 RtlZeroMemory(lpqsResults
, *lpdwBufferLength
);
303 lpqsResults
->dwSize
= sizeof(*lpqsResults
);
305 wsaErr
= NSP_LookupServiceNextW(pLook
,
311 #endif /* NSP_REDIRECT */
316 WSASetLastError(wsaErr
);
324 mwsNSPIoCtl(_In_ HANDLE hLookup
,
325 _In_ DWORD dwControlCode
,
326 _In_reads_bytes_(cbInBuffer
) LPVOID lpvInBuffer
,
327 _In_ DWORD cbInBuffer
,
328 _Out_writes_bytes_to_(cbOutBuffer
, *lpcbBytesReturned
) LPVOID lpvOutBuffer
,
329 _In_ DWORD cbOutBuffer
,
330 _Out_ LPDWORD lpcbBytesReturned
,
331 _In_opt_ LPWSACOMPLETION lpCompletion
,
332 _In_ LPWSATHREADID lpThreadId
)
334 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
335 return ERROR_CALL_NOT_IMPLEMENTED
;
340 mwsNSPLookupServiceEnd(_In_ HANDLE hLookup
)
342 PWSHANDLEINTERN pLook
;
347 pLook
= (PWSHANDLEINTERN
)hLookup
;
348 hHeap
= GetProcessHeap();
351 res
= pLook
->rdrproc
.NSPLookupServiceEnd(pLook
->rdrLookup
);
354 if (pLook
->hostnameW
!= NULL
)
355 HeapFree(hHeap
, 0, pLook
->hostnameW
);
357 HeapFree(hHeap
, 0, pLook
);
363 mwsNSPSetService(_In_ LPGUID lpProviderId
,
364 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
,
365 _In_ LPWSAQUERYSETW lpqsRegInfo
,
366 _In_ WSAESETSERVICEOP essOperation
,
367 _In_ DWORD dwControlFlags
)
369 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
370 return ERROR_CALL_NOT_IMPLEMENTED
;
375 mwsNSPInstallServiceClass(_In_ LPGUID lpProviderId
,
376 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
)
378 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
379 return ERROR_CALL_NOT_IMPLEMENTED
;
384 mwsNSPRemoveServiceClass(_In_ LPGUID lpProviderId
,
385 _In_ LPGUID lpServiceClassId
)
387 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
388 return ERROR_CALL_NOT_IMPLEMENTED
;
393 mwsNSPGetServiceClassInfo(_In_ LPGUID lpProviderId
,
394 _In_ LPDWORD lpdwBufSize
,
395 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
)
397 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
398 return ERROR_CALL_NOT_IMPLEMENTED
;
402 hostnameA / hostnameW
403 * only used by HOSTBYNAME
404 * only one should be set
408 NSP_LookupServiceBeginW(PWSHANDLEINTERN data
,
415 if (data
->CallID
!= 0)
418 data
->CallID
= CallID
;
420 if ((CallID
== NSP_CALLID_HOSTBYNAME
) ||
421 (CallID
== NSP_CALLID_SERVICEBYNAME
))
423 hHeap
= GetProcessHeap();
425 if (data
->hostnameW
!= NULL
)
426 HeapFree(hHeap
, 0, data
->hostnameW
);
428 if (hostnameA
!= NULL
)
430 data
->hostnameW
= StrA2WHeapAlloc(hHeap
, hostnameA
);
434 data
->hostnameW
= StrCpyHeapAllocW(hHeap
, hostnameW
);
440 return ERROR_SUCCESS
;
444 NSP_GetHostNameHeapAllocW(_Out_ WCHAR
** hostname
)
447 HANDLE hHeap
= GetProcessHeap();
448 DWORD bufCharLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
449 DWORD bufByteLen
= bufCharLen
* sizeof(WCHAR
);
451 name
= HeapAlloc(hHeap
, 0, bufByteLen
);
453 if (!GetComputerNameExW(ComputerNameDnsHostname
,
457 HeapFree(hHeap
, 0, name
);
458 WSASetLastError(WSAEFAULT
);
463 return ERROR_SUCCESS
;
467 NSP_GetHostByNameHeapAllocW(_In_ WCHAR
* name
,
468 _In_ GUID
* lpProviderId
,
469 _Out_ PWSHOSTINFOINTERN hostinfo
)
471 HANDLE hHeap
= GetProcessHeap();
472 DNS_STATUS dns_status
= {0};
473 /* include/WinDNS.h -- look up DNS_RECORD on MSDN */
476 INT result
= ERROR_SUCCESS
;
478 /* needed to be cleaned up if != NULL */
483 result
= ERROR_INVALID_PARAMETER
;
487 /* DNS_TYPE_A: include/WinDNS.h */
488 /* DnsQuery -- lib/dnsapi/dnsapi/query.c */
489 dns_status
= DnsQuery(name
,
492 /* extra dns servers */ 0,
496 if (dns_status
== ERROR_INVALID_NAME
)
498 WSASetLastError(WSAEFAULT
);
499 result
= ERROR_INVALID_PARAMETER
;
503 if ((dns_status
!= 0) || (dp
== NULL
))
505 result
= WSAHOST_NOT_FOUND
;
509 //ASSERT(dp->wType == DNS_TYPE_A);
510 //ASSERT(dp->wDataLength == sizeof(DNS_A_DATA));
512 while ((curr
->pNext
!= NULL
) || (curr
->wType
!= DNS_TYPE_A
))
517 if (curr
->wType
!= DNS_TYPE_A
)
519 result
= WSASERVICE_NOT_FOUND
;
523 hostinfo
->hostnameW
= StrCpyHeapAllocW(hHeap
, curr
->pName
);
524 hostinfo
->addr4
= curr
->Data
.A
.IpAddress
;
525 result
= ERROR_SUCCESS
;
529 DnsRecordListFree(dp
, DnsFreeRecordList
);
534 #define SKIPWS(ptr, act) \
535 {while(*ptr && isspace(*ptr)) ptr++; if(!*ptr) act;}
537 #define SKIPANDMARKSTR(ptr, act) \
538 {while(*ptr && !isspace(*ptr)) ptr++; \
539 if(!*ptr) {act;} else { *ptr = 0; ptr++; }}
543 DecodeServEntFromString(IN PCHAR ServiceString
,
544 OUT PCHAR
*ServiceName
,
545 OUT PCHAR
*PortNumberStr
,
546 OUT PCHAR
*ProtocolStr
,
552 //WS_DbgPrint(MAX_TRACE, ("Parsing service ent [%s]\n", ServiceString));
554 SKIPWS(ServiceString
, return FALSE
);
555 *ServiceName
= ServiceString
;
556 SKIPANDMARKSTR(ServiceString
, return FALSE
);
557 SKIPWS(ServiceString
, return FALSE
);
558 *PortNumberStr
= ServiceString
;
559 SKIPANDMARKSTR(ServiceString
, ;);
561 while (*ServiceString
&& NAliases
< MaxAlias
- 1)
563 SKIPWS(ServiceString
, break);
566 SKIPWS(ServiceString
, ;);
567 if (strlen(ServiceString
))
569 //WS_DbgPrint(MAX_TRACE, ("Alias: %s\n", ServiceString));
570 *Aliases
++ = ServiceString
;
573 SKIPANDMARKSTR(ServiceString
, ;);
578 *ProtocolStr
= strchr(*PortNumberStr
, '/');
586 //WS_DbgPrint(MAX_TRACE, ("Parsing done: %s %s %s %d\n",
587 // *ServiceName, *ProtocolStr, *PortNumberStr,
595 OpenNetworkDatabase(_In_ LPCWSTR Name
)
606 ExpandedPath
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
*sizeof(WCHAR
));
608 return INVALID_HANDLE_VALUE
;
610 /* Open the database path key */
611 ErrorCode
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
612 L
"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
616 if (ErrorCode
== NO_ERROR
)
618 /* Read the actual path */
619 ErrorCode
= RegQueryValueEx(DatabaseKey
,
626 DatabasePath
= HeapAlloc(GetProcessHeap(), 0, RegSize
);
629 HeapFree(GetProcessHeap(), 0, ExpandedPath
);
630 return INVALID_HANDLE_VALUE
;
633 /* Read the actual path */
634 ErrorCode
= RegQueryValueEx(DatabaseKey
,
638 (LPBYTE
)DatabasePath
,
642 RegCloseKey(DatabaseKey
);
644 /* Expand the name */
645 ExpandEnvironmentStrings(DatabasePath
, ExpandedPath
, MAX_PATH
);
647 HeapFree(GetProcessHeap(), 0, DatabasePath
);
651 /* Use defalt path */
652 GetSystemDirectory(ExpandedPath
, MAX_PATH
);
653 StringCchLength(ExpandedPath
, MAX_PATH
, &StringLength
);
654 if (ExpandedPath
[StringLength
- 1] != L
'\\')
656 /* It isn't, so add it ourselves */
657 StringCchCat(ExpandedPath
, MAX_PATH
, L
"\\");
659 StringCchCat(ExpandedPath
, MAX_PATH
, L
"DRIVERS\\ETC\\");
662 /* Make sure that the path is backslash-terminated */
663 StringCchLength(ExpandedPath
, MAX_PATH
, &StringLength
);
664 if (ExpandedPath
[StringLength
- 1] != L
'\\')
666 /* It isn't, so add it ourselves */
667 StringCchCat(ExpandedPath
, MAX_PATH
, L
"\\");
670 /* Add the database name */
671 StringCchCat(ExpandedPath
, MAX_PATH
, Name
);
673 /* Return a handle to the file */
674 ret
= CreateFile(ExpandedPath
,
679 FILE_ATTRIBUTE_NORMAL
,
682 HeapFree(GetProcessHeap(), 0, ExpandedPath
);
687 NSP_GetServiceByNameHeapAllocW(_In_ WCHAR
* nameW
,
688 _In_ GUID
* lpProviderId
,
689 _Out_ PWSHOSTINFOINTERN hostinfo
)
693 CHAR ServiceDBData
[BUFSIZ
* sizeof(WCHAR
)] = {0};
694 PCHAR ThisLine
= 0, NextLine
= 0, ServiceName
= 0, PortNumberStr
= 0,
695 ProtocolStr
= 0, Comment
= 0, EndValid
;
696 PCHAR Aliases
[WS2_INTERNAL_MAX_ALIAS
] = {0};
702 PCHAR nameServiceA
= NULL
;
703 PCHAR nameProtoA
= NULL
;
704 INT res
= WSANO_RECOVERY
;
708 res
= WSANO_RECOVERY
;
712 hHeap
= GetProcessHeap();
713 nameA
= StrW2AHeapAlloc(hHeap
, nameW
);
715 /* nameA has the form <service-name>/<protocol>
716 we split these now */
717 nameProtoA
= strchr(nameA
, '/');
718 if (nameProtoA
== NULL
)
720 res
= WSANO_RECOVERY
;
725 i
= (DWORD
)(nameProtoA
- nameA
- 1);
726 nameServiceA
= (PCHAR
)HeapAlloc(hHeap
, 0, i
+ 1);
727 StringCbCopyA(nameServiceA
, i
+ 1, nameA
);
728 nameServiceA
[i
] = '\0';
730 ServicesFile
= OpenNetworkDatabase(L
"services");
731 if (ServicesFile
== INVALID_HANDLE_VALUE
)
733 return WSANO_RECOVERY
;
736 /* Scan the services file ...
738 * We will be share the buffer on the lines. If the line does not fit in
739 * the buffer, then moving it to the beginning of the buffer and read
740 * the remnants of line from file.
744 ReadFile(ServicesFile
,
746 sizeof( ServiceDBData
) - 1,
750 ThisLine
= NextLine
= ServiceDBData
;
751 EndValid
= ServiceDBData
+ ReadSize
;
752 ServiceDBData
[sizeof(ServiceDBData
) - 1] = '\0';
756 for (; *NextLine
!= '\r' && *NextLine
!= '\n'; NextLine
++)
758 if (NextLine
== EndValid
)
760 int LineLen
= NextLine
- ThisLine
;
762 if (ThisLine
== ServiceDBData
)
764 //WS_DbgPrint(MIN_TRACE,("Line too long"));
765 return WSANO_RECOVERY
;
768 memmove(ServiceDBData
, ThisLine
, LineLen
);
770 ReadFile(ServicesFile
,
771 ServiceDBData
+ LineLen
,
772 sizeof( ServiceDBData
)-1 - LineLen
,
776 EndValid
= ServiceDBData
+ LineLen
+ ReadSize
;
777 NextLine
= ServiceDBData
+ LineLen
;
778 ThisLine
= ServiceDBData
;
780 if (!ReadSize
) break;
785 Comment
= strchr(ThisLine
, '#');
788 *Comment
= '\0'; /* Terminate at comment start */
790 if (DecodeServEntFromString(ThisLine
,
795 WS2_INTERNAL_MAX_ALIAS
) &&
796 (strlen(nameProtoA
) == 0 || strcmp(ProtocolStr
, nameProtoA
) == 0))
798 Found
= (strcmp(ServiceName
, nameServiceA
) == 0 || strcmp(PortNumberStr
, nameServiceA
) == 0);
800 while ((!Found
) && (*AliasPtr
!= NULL
))
802 Found
= (strcmp(*AliasPtr
, nameServiceA
) == 0);
812 /* This we'll do no matter what */
813 CloseHandle(ServicesFile
);
821 hostinfo
->servnameW
= StrA2WHeapAlloc(hHeap
, ServiceName
);
822 hostinfo
->servprotoW
= StrA2WHeapAlloc(hHeap
, ProtocolStr
);
823 hostinfo
->servaliasesA
= StrAryCpyHeapAllocA(hHeap
, (char**)&Aliases
);
824 hostinfo
->servport
= atoi(PortNumberStr
);
830 HeapFree(hHeap
, 0, nameA
);
832 if (nameServiceA
!= NULL
)
833 HeapFree(hHeap
, 0, nameServiceA
);
839 NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data
,
841 _Inout_ LPWSAQUERYSETW lpRes
,
842 _Inout_ LPDWORD lpResLen
)
845 WSHOSTINFOINTERN hostinfo
;
847 HANDLE hHeap
= GetProcessHeap();
848 WCHAR
* ServiceInstanceNameW
= NULL
;
850 CHAR
* ServiceInstanceNameA
= NULL
;
851 CHAR
* ServiceProtocolNameA
= NULL
;
853 RtlZeroMemory(&hostinfo
, sizeof(hostinfo
));
855 /* init and build result-buffer */
856 mswBufferInit(&buf
, (BYTE
*)lpRes
, *lpResLen
);
857 mswBufferIncUsed(&buf
, sizeof(*lpRes
));
859 /* QueryDataSet-Size without "blob-data"-size! */
860 lpRes
->dwSize
= sizeof(*lpRes
);
861 lpRes
->dwNameSpace
= NS_DNS
;
863 if ((CallID
== NSP_CALLID_HOSTNAME
) ||
864 (CallID
== NSP_CALLID_HOSTBYNAME
) ||
865 (CallID
== NSP_CALLID_SERVICEBYNAME
))
867 if (data
->CallIDCounter
>= 1)
875 result
= WSANO_RECOVERY
;
878 data
->CallIDCounter
++;
880 if (CallID
== NSP_CALLID_HOSTNAME
)
882 result
= NSP_GetHostNameHeapAllocW(&hostinfo
.hostnameW
);
884 if (result
!= ERROR_SUCCESS
)
889 else if (CallID
== NSP_CALLID_HOSTBYNAME
)
891 result
= NSP_GetHostByNameHeapAllocW(data
->hostnameW
,
894 if (result
!= ERROR_SUCCESS
)
899 ASSERT(CallID
== NSP_CALLID_SERVICEBYNAME
);
900 result
= NSP_GetServiceByNameHeapAllocW(data
->hostnameW
,
903 if (result
!= ERROR_SUCCESS
)
907 if (((LUP_RETURN_BLOB
& data
->dwControlFlags
) != 0) ||
908 ((LUP_RETURN_NAME
& data
->dwControlFlags
) != 0))
910 if (CallID
== NSP_CALLID_HOSTNAME
|| CallID
== NSP_CALLID_HOSTBYNAME
)
912 ServiceInstanceNameW
= hostinfo
.hostnameW
;
913 ServiceInstanceNameA
= StrW2AHeapAlloc(hHeap
, ServiceInstanceNameW
);
914 if (ServiceInstanceNameA
== NULL
)
921 if (CallID
== NSP_CALLID_SERVICEBYNAME
)
923 ServiceInstanceNameW
= hostinfo
.servnameW
;
924 ServiceInstanceNameA
= StrW2AHeapAlloc(hHeap
, ServiceInstanceNameW
);
925 if (ServiceInstanceNameA
== NULL
)
931 ServiceProtocolNameA
= StrW2AHeapAlloc(hHeap
, hostinfo
.servprotoW
);
932 if (ServiceProtocolNameA
== NULL
)
941 if ((LUP_RETURN_ADDR
& data
->dwControlFlags
) != 0)
943 if (!mswBufferAppendAddr_AddrInfoW(&buf
, lpRes
, hostinfo
.addr4
))
945 *lpResLen
= buf
.bytesUsed
;
951 if ((LUP_RETURN_BLOB
& data
->dwControlFlags
) != 0)
953 if (CallID
== NSP_CALLID_HOSTBYNAME
)
955 /* Write data for PBLOB (hostent) */
956 if (!mswBufferAppendBlob_Hostent(&buf
,
958 ServiceInstanceNameA
,
961 *lpResLen
= buf
.bytesUsed
;
966 else if (CallID
== NSP_CALLID_SERVICEBYNAME
)
968 /* Write data for PBLOB (servent) */
969 if (!mswBufferAppendBlob_Servent(&buf
,
971 ServiceInstanceNameA
,/* ServiceName */
972 hostinfo
.servaliasesA
,
973 ServiceProtocolNameA
,
976 *lpResLen
= buf
.bytesUsed
;
983 result
= WSANO_RECOVERY
;
988 if ((LUP_RETURN_NAME
& data
->dwControlFlags
) != 0)
990 /* HostByName sets the ServiceInstanceName to a
991 (UNICODE)copy of hostent.h_name */
992 lpRes
->lpszServiceInstanceName
= (LPWSTR
)mswBufferEndPtr(&buf
);
993 if (!mswBufferAppendStrW(&buf
, ServiceInstanceNameW
))
995 lpRes
->lpszServiceInstanceName
= NULL
;
996 *lpResLen
= buf
.bytesUsed
;
1002 *lpResLen
= buf
.bytesUsed
;
1004 result
= ERROR_SUCCESS
;
1007 if (ServiceInstanceNameA
!= NULL
)
1008 HeapFree(hHeap
, 0, ServiceInstanceNameA
);
1010 if (ServiceProtocolNameA
!= NULL
)
1011 HeapFree(hHeap
, 0, ServiceProtocolNameA
);
1013 if (hostinfo
.hostnameW
!= NULL
)
1014 HeapFree(hHeap
, 0, hostinfo
.hostnameW
);
1016 if (hostinfo
.servnameW
!= NULL
)
1017 HeapFree(hHeap
, 0, hostinfo
.servnameW
);
1019 if (hostinfo
.servprotoW
!= NULL
)
1020 HeapFree(hHeap
, 0, hostinfo
.servprotoW
);
1025 /* Implementations - Exports */
1031 NSPStartup(_In_ LPGUID lpProviderId
,
1032 _Out_ LPNSP_ROUTINE lpRout
)
1036 if ((lpRout
== NULL
) ||
1037 (lpRout
->cbSize
!= sizeof(NSP_ROUTINE
)))
1039 WSASetLastError(ERROR_INVALID_PARAMETER
);
1040 return ERROR_INVALID_PARAMETER
;
1045 /* set own Provider GUID - maybe we need
1046 here to set the original mswsock-GUID?! */
1051 - sets cbSize to 44! */
1052 lpRout
->dwMajorVersion
= 1;
1053 lpRout
->dwMinorVersion
= 1;
1054 lpRout
->cbSize
= sizeof(*lpRout
) - sizeof(lpRout
->NSPIoctl
);
1055 lpRout
->NSPCleanup
= &mwsNSPCleanUp
;
1056 lpRout
->NSPLookupServiceBegin
= &mwsNSPLookupServiceBegin
;
1057 lpRout
->NSPLookupServiceNext
= &mwsNSPLookupServiceNext
;
1058 lpRout
->NSPLookupServiceEnd
= &mwsNSPLookupServiceEnd
;
1059 lpRout
->NSPSetService
= &mwsNSPSetService
;
1060 lpRout
->NSPInstallServiceClass
= &mwsNSPInstallServiceClass
;
1061 lpRout
->NSPRemoveServiceClass
= &mwsNSPRemoveServiceClass
;
1062 lpRout
->NSPGetServiceClassInfo
= &mwsNSPGetServiceClassInfo
;
1063 lpRout
->NSPIoctl
= NULL
;// &mwsNSPIoCtl;