Directory Services |
The following code example is used by the Winsock service to register the RnR connection point for the service.
[C++]
#include <winsock2.h>
#include <stdio.h>
/***************************************************************************
serverRegister()
Registers the RnR connection point for the specified service. WSAStartup
must be called before calling this function.
***************************************************************************/
INT serverRegister(SOCKADDR * sa,
GUID *pServiceID,
LPTSTR pszServiceInstanceName,
LPTSTR pszServiceInstanceComment)
{
DWORD ret;
WSAVERSION Version;
WSAQUERYSET QuerySet;
CSADDR_INFO CSAddrInfo[1];
SOCKADDR sa_local;
memset(&QuerySet, 0, sizeof(QuerySet));
memset(&CSAddrInfo, 0, sizeof(CSAddrInfo));
memset(&sa_local, 0, sizeof(SOCKADDR));
sa_local.sa_family = AF_INET;
// Build the CSAddrInfo structure to contain address
// data that clients use to establish a connection.
//
// Be aware that LocalAddr is set to zero because dynamically
// assigned port numbers are used.
//
CSAddrInfo[0].LocalAddr.iSockaddrLength = sizeof(SOCKADDR);
CSAddrInfo[0].LocalAddr.lpSockaddr = &sa_local;
CSAddrInfo[0].RemoteAddr.iSockaddrLength = sizeof(SOCKADDR);
CSAddrInfo[0].RemoteAddr.lpSockaddr = sa;
CSAddrInfo[0].iSocketType = SOCK_STREAM;
CSAddrInfo[0].iProtocol = PF_INET;
QuerySet.dwSize = sizeof(WSAQUERYSET);
QuerySet.lpServiceClassId = pServiceID;
QuerySet.lpszServiceInstanceName = pszServiceInstanceName;
QuerySet.lpszComment = pszServiceInstanceComment;
QuerySet.lpVersion = &Version;
QuerySet.lpVersion->dwVersion = 2;
QuerySet.lpVersion->ecHow = COMP_NOTLESS;
QuerySet.dwNameSpace = NS_NTDS;
QuerySet.dwNumberOfCsAddrs = 1;
QuerySet.lpcsaBuffer = CSAddrInfo;
ret = WSASetService( &QuerySet,
RNRSERVICE_REGISTER,
SERVICE_MULTIPLE);
return(ret);
}