15 #include "mswhelper.h"
17 #define NSP_CALLID_DNS 0x0001
18 #define NSP_CALLID_HOSTNAME 0x0002
19 #define NSP_CALLID_HOSTBYNAME 0x0003
20 #define NSP_CALLID_SERVICEBYNAME 0x0004
25 #ifndef WS2_INTERNAL_MAX_ALIAS
26 #define WS2_INTERNAL_MAX_ALIAS 512
27 #endif // WS2_INTERNAL_MAX_ALIAS
29 //#define IP_LOCALHOST 0x0100007F
31 //#define NSP_REDIRECT
38 CHAR
** servaliasesA
; /* array */
40 } WSHOSTINFOINTERN
, *PWSHOSTINFOINTERN
;
43 GUID providerId
; /* Provider-ID */
44 DWORD dwControlFlags
; /* dwControlFlags (WSALookupServiceBegin) */
45 DWORD CallID
; /* List for LookupServiceNext-Calls */
46 DWORD CallIDCounter
; /* call-count of the current CallID. */
47 WCHAR
* hostnameW
; /* hostbyname */
52 } WSHANDLEINTERN
, *PWSHANDLEINTERN
;
54 static const GUID guid_NULL
= {0};
55 static const GUID guid_HOSTNAME
= SVCID_HOSTNAME
;
56 static const GUID guid_INET_HOSTADDRBYINETSTRING
= SVCID_INET_HOSTADDRBYINETSTRING
;
57 static const GUID guid_INET_HOSTADDRBYNAME
= SVCID_INET_HOSTADDRBYNAME
;
58 static const GUID guid_INET_SERVICEBYNAME
= SVCID_INET_SERVICEBYNAME
;
60 /* GUIDs - maybe they should be loaded from registry? */
62 static const GUID guid_mswsock_TcpIp
= {/*Data1:*/ 0x22059D40,
65 /*Data4:*/ {0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B}};
67 /* {6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83} */
69 static const GUID guid_mswsock_NLA
= {/*Data1:*/ 0x6642243A,
72 /*Data4:*/ {0xBA, 0xA5, 0x2E, 0x0B, 0xD7, 0x1F, 0xDD, 0x83}};
77 (CALLBACK
*lpRdrNSPStartup
)(
79 LPNSP_ROUTINE lpRout
);
81 const rdrLib
= "mswsock.dll-original";
82 lpRdrNSPStartup rdrNSPStartup
;
84 NSP_ROUTINE rdrproc_tcpip
;
85 NSP_ROUTINE rdrproc_nla
;
87 #endif /* NSP_REDIRECT */
94 LPNSP_ROUTINE lpRout
);
97 NSP_LookupServiceBeginW(
104 NSP_LookupServiceNextW(
105 _In_ PWSHANDLEINTERN data
,
107 _Inout_ LPWSAQUERYSETW lpRes
,
108 _Inout_ LPDWORD lpResLen
);
111 NSP_GetHostNameHeapAllocW(
112 _Out_ WCHAR
** hostname
);
115 NSP_GetHostByNameHeapAllocW(
117 _In_ GUID
* lpProviderId
,
118 _Out_ PWSHOSTINFOINTERN hostinfo
);
121 NSP_GetServiceByNameHeapAllocW(
123 _In_ GUID
* lpProviderId
,
124 _Out_ PWSHOSTINFOINTERN hostinfo
);
126 /* Implementations - Internal */
130 mwsNSPCleanUp(_In_ LPGUID lpProviderId
)
132 //WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
133 //return ERROR_CALL_NOT_IMPLEMENTED;
134 return ERROR_SUCCESS
;
140 return ERROR_SUCCESS
;
145 mwsNSPLookupServiceBegin(_In_ LPGUID lpProviderId
,
146 _In_ LPWSAQUERYSETW lpqsRestrictions
,
147 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
,
148 _In_ DWORD dwControlFlags
,
149 _Out_ LPHANDLE lphLookup
)
151 PWSHANDLEINTERN pLook
;
154 if (IsEqualGUID(lpProviderId
, &guid_mswsock_TcpIp
))
158 else if (IsEqualGUID(lpProviderId
, &guid_mswsock_NLA
))
160 WSASetLastError(WSASERVICE_NOT_FOUND
);
165 return ERROR_CALL_NOT_IMPLEMENTED
;
168 /* allocate internal structure */
169 pLook
= HeapAlloc(GetProcessHeap(), 0, sizeof(WSHANDLEINTERN
));
172 WSASetLastError(WSAEFAULT
);
176 *lphLookup
= (HANDLE
)pLook
;
178 RtlZeroMemory(pLook
, sizeof(*pLook
));
180 /* Anyway the ControlFlags "should" be needed
181 in NSPLookupServiceNext. (see doku) But
182 thats not the fact ATM. */
183 pLook
->dwControlFlags
= dwControlFlags
;
184 pLook
->providerId
= *lpProviderId
;
188 if (IsEqualGUID(lpProviderId
, &guid_mswsock_TcpIp
))
190 pLook
->rdrproc
= rdrproc_tcpip
;
192 else if (IsEqualGUID(lpProviderId
, &guid_mswsock_NLA
))
194 pLook
->rdrproc
= rdrproc_nla
;
198 return ERROR_CALL_NOT_IMPLEMENTED
;
201 if (pLook
->rdrproc
.NSPLookupServiceBegin(lpProviderId
,
205 &pLook
->rdrLookup
) == NO_ERROR
)
211 wsaErr
= WSAGetLastError();
216 res = WSAGetLastError();
219 #else /* NSP_REDIRECT */
221 wsaErr
= ERROR_CALL_NOT_IMPLEMENTED
;
222 if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
, &guid_NULL
))
224 wsaErr
= ERROR_CALL_NOT_IMPLEMENTED
;
226 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
, &guid_HOSTNAME
))
228 wsaErr
= NSP_LookupServiceBeginW(pLook
,
231 NSP_CALLID_HOSTNAME
);
233 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
,
234 &guid_INET_HOSTADDRBYNAME
))
236 wsaErr
= NSP_LookupServiceBeginW(pLook
,
238 lpqsRestrictions
->lpszServiceInstanceName
,
239 NSP_CALLID_HOSTBYNAME
);
241 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
,
242 &guid_INET_SERVICEBYNAME
))
244 wsaErr
= NSP_LookupServiceBeginW(pLook
,
246 lpqsRestrictions
->lpszServiceInstanceName
,
247 NSP_CALLID_SERVICEBYNAME
);
249 else if (IsEqualGUID(lpqsRestrictions
->lpServiceClassId
,
250 &guid_INET_HOSTADDRBYINETSTRING
))
252 wsaErr
= ERROR_CALL_NOT_IMPLEMENTED
;
255 #endif /* NSP_REDIRECT */
257 if (wsaErr
!= NO_ERROR
)
259 WSASetLastError(wsaErr
);
267 mwsNSPLookupServiceNext(_In_ HANDLE hLookup
,
268 _In_ DWORD dwControlFlags
,
269 _Inout_ LPDWORD lpdwBufferLength
,
270 //_Out_writes_bytes_to_(*lpdwBufferLength, *lpdwBufferLength)
271 LPWSAQUERYSETW lpqsResults
)
273 PWSHANDLEINTERN pLook
= hLookup
;
278 INT res
= pLook
->rdrproc
.NSPLookupServiceNext(pLook
->rdrLookup
,
282 wsaErr
= WSAGetLastError();
283 if (res
!= ERROR_SUCCESS
)
285 wsaErr
= WSAGetLastError();
291 #else /* NSP_REDIRECT */
293 if ((lpdwBufferLength
== NULL
) || (*lpdwBufferLength
== 0))
295 wsaErr
= WSA_NOT_ENOUGH_MEMORY
;
299 RtlZeroMemory(lpqsResults
, *lpdwBufferLength
);
300 lpqsResults
->dwSize
= sizeof(*lpqsResults
);
302 wsaErr
= NSP_LookupServiceNextW(pLook
,
308 #endif /* NSP_REDIRECT */
313 WSASetLastError(wsaErr
);
321 mwsNSPIoCtl(_In_ HANDLE hLookup
,
322 _In_ DWORD dwControlCode
,
323 _In_reads_bytes_(cbInBuffer
) LPVOID lpvInBuffer
,
324 _In_ DWORD cbInBuffer
,
325 _Out_writes_bytes_to_(cbOutBuffer
, *lpcbBytesReturned
) LPVOID lpvOutBuffer
,
326 _In_ DWORD cbOutBuffer
,
327 _Out_ LPDWORD lpcbBytesReturned
,
328 _In_opt_ LPWSACOMPLETION lpCompletion
,
329 _In_ LPWSATHREADID lpThreadId
)
331 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
332 return ERROR_CALL_NOT_IMPLEMENTED
;
337 mwsNSPLookupServiceEnd(_In_ HANDLE hLookup
)
339 PWSHANDLEINTERN pLook
;
344 pLook
= (PWSHANDLEINTERN
)hLookup
;
345 hHeap
= GetProcessHeap();
348 res
= pLook
->rdrproc
.NSPLookupServiceEnd(pLook
->rdrLookup
);
351 if (pLook
->hostnameW
!= NULL
)
352 HeapFree(hHeap
, 0, pLook
->hostnameW
);
354 HeapFree(hHeap
, 0, pLook
);
360 mwsNSPSetService(_In_ LPGUID lpProviderId
,
361 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
,
362 _In_ LPWSAQUERYSETW lpqsRegInfo
,
363 _In_ WSAESETSERVICEOP essOperation
,
364 _In_ DWORD dwControlFlags
)
366 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
367 return ERROR_CALL_NOT_IMPLEMENTED
;
372 mwsNSPInstallServiceClass(_In_ LPGUID lpProviderId
,
373 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
)
375 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
376 return ERROR_CALL_NOT_IMPLEMENTED
;
381 mwsNSPRemoveServiceClass(_In_ LPGUID lpProviderId
,
382 _In_ LPGUID lpServiceClassId
)
384 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
385 return ERROR_CALL_NOT_IMPLEMENTED
;
390 mwsNSPGetServiceClassInfo(_In_ LPGUID lpProviderId
,
391 _In_ LPDWORD lpdwBufSize
,
392 _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo
)
394 WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
395 return ERROR_CALL_NOT_IMPLEMENTED
;
399 hostnameA / hostnameW
400 * only used by HOSTBYNAME
401 * only one should be set
405 NSP_LookupServiceBeginW(PWSHANDLEINTERN data
,
412 if (data
->CallID
!= 0)
415 data
->CallID
= CallID
;
417 if ((CallID
== NSP_CALLID_HOSTBYNAME
) ||
418 (CallID
== NSP_CALLID_SERVICEBYNAME
))
420 hHeap
= GetProcessHeap();
422 if (data
->hostnameW
!= NULL
)
423 HeapFree(hHeap
, 0, data
->hostnameW
);
425 if (hostnameA
!= NULL
)
427 data
->hostnameW
= StrA2WHeapAlloc(hHeap
, hostnameA
);
431 data
->hostnameW
= StrCpyHeapAllocW(hHeap
, hostnameW
);
437 return ERROR_SUCCESS
;
441 NSP_GetHostNameHeapAllocW(_Out_ WCHAR
** hostname
)
444 HANDLE hHeap
= GetProcessHeap();
445 DWORD bufCharLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
446 DWORD bufByteLen
= bufCharLen
* sizeof(WCHAR
);
448 name
= HeapAlloc(hHeap
, 0, bufByteLen
);
450 if (!GetComputerNameExW(ComputerNameDnsHostname
,
454 HeapFree(hHeap
, 0, name
);
455 WSASetLastError(WSAEFAULT
);
460 return ERROR_SUCCESS
;
464 NSP_GetHostByNameHeapAllocW(_In_ WCHAR
* name
,
465 _In_ GUID
* lpProviderId
,
466 _Out_ PWSHOSTINFOINTERN hostinfo
)
468 HANDLE hHeap
= GetProcessHeap();
469 DNS_STATUS dns_status
= {0};
470 /* include/WinDNS.h -- look up DNS_RECORD on MSDN */
473 INT result
= ERROR_SUCCESS
;
475 /* needed to be cleaned up if != NULL */
480 result
= ERROR_INVALID_PARAMETER
;
484 /* DNS_TYPE_A: include/WinDNS.h */
485 /* DnsQuery -- lib/dnsapi/dnsapi/query.c */
486 dns_status
= DnsQuery(name
,
489 /* extra dns servers */ 0,
493 if (dns_status
== ERROR_INVALID_NAME
)
495 WSASetLastError(WSAEFAULT
);
496 result
= ERROR_INVALID_PARAMETER
;
500 if ((dns_status
!= 0) || (dp
== NULL
))
502 result
= WSAHOST_NOT_FOUND
;
506 //ASSERT(dp->wType == DNS_TYPE_A);
507 //ASSERT(dp->wDataLength == sizeof(DNS_A_DATA));
509 while ((curr
->pNext
!= NULL
) || (curr
->wType
!= DNS_TYPE_A
))
514 if (curr
->wType
!= DNS_TYPE_A
)
516 result
= WSASERVICE_NOT_FOUND
;
520 hostinfo
->hostnameW
= StrCpyHeapAllocW(hHeap
, curr
->pName
);
521 hostinfo
->addr4
= curr
->Data
.A
.IpAddress
;
522 result
= ERROR_SUCCESS
;
526 DnsRecordListFree(dp
, DnsFreeRecordList
);
531 #define SKIPWS(ptr, act) \
532 {while(*ptr && isspace(*ptr)) ptr++; if(!*ptr) act;}
534 #define SKIPANDMARKSTR(ptr, act) \
535 {while(*ptr && !isspace(*ptr)) ptr++; \
536 if(!*ptr) {act;} else { *ptr = 0; ptr++; }}
540 DecodeServEntFromString(IN PCHAR ServiceString
,
541 OUT PCHAR
*ServiceName
,
542 OUT PCHAR
*PortNumberStr
,
543 OUT PCHAR
*ProtocolStr
,
549 //WS_DbgPrint(MAX_TRACE, ("Parsing service ent [%s]\n", ServiceString));
551 SKIPWS(ServiceString
, return FALSE
);
552 *ServiceName
= ServiceString
;
553 SKIPANDMARKSTR(ServiceString
, return FALSE
);
554 SKIPWS(ServiceString
, return FALSE
);
555 *PortNumberStr
= ServiceString
;
556 SKIPANDMARKSTR(ServiceString
, ;);
558 while (*ServiceString
&& NAliases
< MaxAlias
- 1)
560 SKIPWS(ServiceString
, break);
563 SKIPWS(ServiceString
, ;);
564 if (strlen(ServiceString
))
566 //WS_DbgPrint(MAX_TRACE, ("Alias: %s\n", ServiceString));
567 *Aliases
++ = ServiceString
;
570 SKIPANDMARKSTR(ServiceString
, ;);
575 *ProtocolStr
= strchr(*PortNumberStr
, '/');
583 //WS_DbgPrint(MAX_TRACE, ("Parsing done: %s %s %s %d\n",
584 // *ServiceName, *ProtocolStr, *PortNumberStr,
592 OpenNetworkDatabase(_In_ LPCWSTR Name
)
603 ExpandedPath
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
*sizeof(WCHAR
));
605 return INVALID_HANDLE_VALUE
;
607 /* Open the database path key */
608 ErrorCode
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
609 L
"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
613 if (ErrorCode
== NO_ERROR
)
615 /* Read the actual path */
616 ErrorCode
= RegQueryValueEx(DatabaseKey
,
623 DatabasePath
= HeapAlloc(GetProcessHeap(), 0, RegSize
);
626 HeapFree(GetProcessHeap(), 0, ExpandedPath
);
627 return INVALID_HANDLE_VALUE
;
630 /* Read the actual path */
631 ErrorCode
= RegQueryValueEx(DatabaseKey
,
635 (LPBYTE
)DatabasePath
,
639 RegCloseKey(DatabaseKey
);
641 /* Expand the name */
642 ExpandEnvironmentStrings(DatabasePath
, ExpandedPath
, MAX_PATH
);
644 HeapFree(GetProcessHeap(), 0, DatabasePath
);
648 /* Use defalt path */
649 GetSystemDirectory(ExpandedPath
, MAX_PATH
);
650 StringCchLength(ExpandedPath
, MAX_PATH
, &StringLength
);
651 if (ExpandedPath
[StringLength
- 1] != L
'\\')
653 /* It isn't, so add it ourselves */
654 StringCchCat(ExpandedPath
, MAX_PATH
, L
"\\");
656 StringCchCat(ExpandedPath
, MAX_PATH
, L
"DRIVERS\\ETC\\");
659 /* Make sure that the path is backslash-terminated */
660 StringCchLength(ExpandedPath
, MAX_PATH
, &StringLength
);
661 if (ExpandedPath
[StringLength
- 1] != L
'\\')
663 /* It isn't, so add it ourselves */
664 StringCchCat(ExpandedPath
, MAX_PATH
, L
"\\");
667 /* Add the database name */
668 StringCchCat(ExpandedPath
, MAX_PATH
, Name
);
670 /* Return a handle to the file */
671 ret
= CreateFile(ExpandedPath
,
676 FILE_ATTRIBUTE_NORMAL
,
679 HeapFree(GetProcessHeap(), 0, ExpandedPath
);
684 NSP_GetServiceByNameHeapAllocW(_In_ WCHAR
* nameW
,
685 _In_ GUID
* lpProviderId
,
686 _Out_ PWSHOSTINFOINTERN hostinfo
)
690 CHAR ServiceDBData
[BUFSIZ
* sizeof(WCHAR
)] = {0};
691 PCHAR ThisLine
= 0, NextLine
= 0, ServiceName
= 0, PortNumberStr
= 0,
692 ProtocolStr
= 0, Comment
= 0, EndValid
;
693 PCHAR Aliases
[WS2_INTERNAL_MAX_ALIAS
] = {0};
699 PCHAR nameServiceA
= NULL
;
700 PCHAR nameProtoA
= NULL
;
701 INT res
= WSANO_RECOVERY
;
705 res
= WSANO_RECOVERY
;
709 hHeap
= GetProcessHeap();
710 nameA
= StrW2AHeapAlloc(hHeap
, nameW
);
712 /* nameA has the form <service-name>/<protocol>
713 we split these now */
714 nameProtoA
= strchr(nameA
, '/');
715 if (nameProtoA
== NULL
)
717 res
= WSANO_RECOVERY
;
722 i
= (DWORD
)(nameProtoA
- nameA
- 1);
723 nameServiceA
= (PCHAR
)HeapAlloc(hHeap
, 0, i
+ 1);
724 StringCbCopyA(nameServiceA
, i
+ 1, nameA
);
725 nameServiceA
[i
] = '\0';
727 ServicesFile
= OpenNetworkDatabase(L
"services");
728 if (ServicesFile
== INVALID_HANDLE_VALUE
)
730 return WSANO_RECOVERY
;
733 /* Scan the services file ...
735 * We will be share the buffer on the lines. If the line does not fit in
736 * the buffer, then moving it to the beginning of the buffer and read
737 * the remnants of line from file.
741 ReadFile(ServicesFile
,
743 sizeof( ServiceDBData
) - 1,
747 ThisLine
= NextLine
= ServiceDBData
;
748 EndValid
= ServiceDBData
+ ReadSize
;
749 ServiceDBData
[sizeof(ServiceDBData
) - 1] = '\0';
753 for (; *NextLine
!= '\r' && *NextLine
!= '\n'; NextLine
++)
755 if (NextLine
== EndValid
)
757 int LineLen
= NextLine
- ThisLine
;
759 if (ThisLine
== ServiceDBData
)
761 //WS_DbgPrint(MIN_TRACE,("Line too long"));
762 return WSANO_RECOVERY
;
765 memmove(ServiceDBData
, ThisLine
, LineLen
);
767 ReadFile(ServicesFile
,
768 ServiceDBData
+ LineLen
,
769 sizeof( ServiceDBData
)-1 - LineLen
,
773 EndValid
= ServiceDBData
+ LineLen
+ ReadSize
;
774 NextLine
= ServiceDBData
+ LineLen
;
775 ThisLine
= ServiceDBData
;
777 if (!ReadSize
) break;
782 Comment
= strchr(ThisLine
, '#');
785 *Comment
= '\0'; /* Terminate at comment start */
787 if (DecodeServEntFromString(ThisLine
,
792 WS2_INTERNAL_MAX_ALIAS
) &&
793 (strlen(nameProtoA
) == 0 || strcmp(ProtocolStr
, nameProtoA
) == 0))
795 Found
= (strcmp(ServiceName
, nameServiceA
) == 0 || strcmp(PortNumberStr
, nameServiceA
) == 0);
797 while ((!Found
) && (*AliasPtr
!= NULL
))
799 Found
= (strcmp(*AliasPtr
, nameServiceA
) == 0);
809 /* This we'll do no matter what */
810 CloseHandle(ServicesFile
);
818 hostinfo
->servnameW
= StrA2WHeapAlloc(hHeap
, ServiceName
);
819 hostinfo
->servprotoW
= StrA2WHeapAlloc(hHeap
, ProtocolStr
);
820 hostinfo
->servaliasesA
= StrAryCpyHeapAllocA(hHeap
, (char**)&Aliases
);
821 hostinfo
->servport
= atoi(PortNumberStr
);
827 HeapFree(hHeap
, 0, nameA
);
829 if (nameServiceA
!= NULL
)
830 HeapFree(hHeap
, 0, nameServiceA
);
836 NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data
,
838 _Inout_ LPWSAQUERYSETW lpRes
,
839 _Inout_ LPDWORD lpResLen
)
842 WSHOSTINFOINTERN hostinfo
;
844 HANDLE hHeap
= GetProcessHeap();
845 WCHAR
* ServiceInstanceNameW
= NULL
;
847 CHAR
* ServiceInstanceNameA
= NULL
;
848 CHAR
* ServiceProtocolNameA
= NULL
;
850 RtlZeroMemory(&hostinfo
, sizeof(hostinfo
));
852 /* init and build result-buffer */
853 mswBufferInit(&buf
, (BYTE
*)lpRes
, *lpResLen
);
854 mswBufferIncUsed(&buf
, sizeof(*lpRes
));
856 /* QueryDataSet-Size without "blob-data"-size! */
857 lpRes
->dwSize
= sizeof(*lpRes
);
858 lpRes
->dwNameSpace
= NS_DNS
;
860 if ((CallID
== NSP_CALLID_HOSTNAME
) ||
861 (CallID
== NSP_CALLID_HOSTBYNAME
) ||
862 (CallID
== NSP_CALLID_SERVICEBYNAME
))
864 if (data
->CallIDCounter
>= 1)
872 result
= WSANO_RECOVERY
;
875 data
->CallIDCounter
++;
877 if (CallID
== NSP_CALLID_HOSTNAME
)
879 result
= NSP_GetHostNameHeapAllocW(&hostinfo
.hostnameW
);
881 if (result
!= ERROR_SUCCESS
)
886 else if (CallID
== NSP_CALLID_HOSTBYNAME
)
888 result
= NSP_GetHostByNameHeapAllocW(data
->hostnameW
,
891 if (result
!= ERROR_SUCCESS
)
894 else if (CallID
== NSP_CALLID_SERVICEBYNAME
)
896 result
= NSP_GetServiceByNameHeapAllocW(data
->hostnameW
,
899 if (result
!= ERROR_SUCCESS
)
904 result
= WSANO_RECOVERY
; // Internal error!
908 if (((LUP_RETURN_BLOB
& data
->dwControlFlags
) != 0) ||
909 ((LUP_RETURN_NAME
& data
->dwControlFlags
) != 0))
911 if (CallID
== NSP_CALLID_HOSTNAME
|| CallID
== NSP_CALLID_HOSTBYNAME
)
913 ServiceInstanceNameW
= hostinfo
.hostnameW
;
914 ServiceInstanceNameA
= StrW2AHeapAlloc(hHeap
, ServiceInstanceNameW
);
915 if (ServiceInstanceNameA
== NULL
)
922 if (CallID
== NSP_CALLID_SERVICEBYNAME
)
924 ServiceInstanceNameW
= hostinfo
.servnameW
;
925 ServiceInstanceNameA
= StrW2AHeapAlloc(hHeap
, ServiceInstanceNameW
);
926 if (ServiceInstanceNameA
== NULL
)
932 ServiceProtocolNameA
= StrW2AHeapAlloc(hHeap
, hostinfo
.servprotoW
);
933 if (ServiceProtocolNameA
== NULL
)
942 if ((LUP_RETURN_ADDR
& data
->dwControlFlags
) != 0)
944 if (!mswBufferAppendAddr_AddrInfoW(&buf
, lpRes
, hostinfo
.addr4
))
946 *lpResLen
= buf
.bytesUsed
;
952 if ((LUP_RETURN_BLOB
& data
->dwControlFlags
) != 0)
954 if (CallID
== NSP_CALLID_HOSTBYNAME
)
956 /* Write data for PBLOB (hostent) */
957 if (!mswBufferAppendBlob_Hostent(&buf
,
959 ServiceInstanceNameA
,
962 *lpResLen
= buf
.bytesUsed
;
967 else if (CallID
== NSP_CALLID_SERVICEBYNAME
)
969 /* Write data for PBLOB (servent) */
970 if (!mswBufferAppendBlob_Servent(&buf
,
972 ServiceInstanceNameA
,/* ServiceName */
973 hostinfo
.servaliasesA
,
974 ServiceProtocolNameA
,
977 *lpResLen
= buf
.bytesUsed
;
984 result
= WSANO_RECOVERY
;
989 if ((LUP_RETURN_NAME
& data
->dwControlFlags
) != 0)
991 /* HostByName sets the ServiceInstanceName to a
992 (UNICODE)copy of hostent.h_name */
993 lpRes
->lpszServiceInstanceName
= (LPWSTR
)mswBufferEndPtr(&buf
);
994 if (!mswBufferAppendStrW(&buf
, ServiceInstanceNameW
))
996 lpRes
->lpszServiceInstanceName
= NULL
;
997 *lpResLen
= buf
.bytesUsed
;
1003 *lpResLen
= buf
.bytesUsed
;
1005 result
= ERROR_SUCCESS
;
1008 if (ServiceInstanceNameA
!= NULL
)
1009 HeapFree(hHeap
, 0, ServiceInstanceNameA
);
1011 if (ServiceProtocolNameA
!= NULL
)
1012 HeapFree(hHeap
, 0, ServiceProtocolNameA
);
1014 if (hostinfo
.hostnameW
!= NULL
)
1015 HeapFree(hHeap
, 0, hostinfo
.hostnameW
);
1017 if (hostinfo
.servnameW
!= NULL
)
1018 HeapFree(hHeap
, 0, hostinfo
.servnameW
);
1020 if (hostinfo
.servprotoW
!= NULL
)
1021 HeapFree(hHeap
, 0, hostinfo
.servprotoW
);
1026 /* Implementations - Exports */
1032 NSPStartup(_In_ LPGUID lpProviderId
,
1033 _Out_ LPNSP_ROUTINE lpRout
)
1037 if ((lpRout
== NULL
) ||
1038 (lpRout
->cbSize
!= sizeof(NSP_ROUTINE
)))
1040 WSASetLastError(ERROR_INVALID_PARAMETER
);
1041 return ERROR_INVALID_PARAMETER
;
1046 /* set own Provider GUID - maybe we need
1047 here to set the original mswsock-GUID?! */
1052 - sets cbSize to 44! */
1053 lpRout
->dwMajorVersion
= 1;
1054 lpRout
->dwMinorVersion
= 1;
1055 lpRout
->cbSize
= sizeof(*lpRout
) - sizeof(lpRout
->NSPIoctl
);
1056 lpRout
->NSPCleanup
= &mwsNSPCleanUp
;
1057 lpRout
->NSPLookupServiceBegin
= &mwsNSPLookupServiceBegin
;
1058 lpRout
->NSPLookupServiceNext
= &mwsNSPLookupServiceNext
;
1059 lpRout
->NSPLookupServiceEnd
= &mwsNSPLookupServiceEnd
;
1060 lpRout
->NSPSetService
= &mwsNSPSetService
;
1061 lpRout
->NSPInstallServiceClass
= &mwsNSPInstallServiceClass
;
1062 lpRout
->NSPRemoveServiceClass
= &mwsNSPRemoveServiceClass
;
1063 lpRout
->NSPGetServiceClassInfo
= &mwsNSPGetServiceClassInfo
;
1064 lpRout
->NSPIoctl
= NULL
;// &mwsNSPIoCtl;