Platform SDK: Active Directory, ADSI, and Directory Services

Example Code for Publishing the RnR Connection Point

The following function is used by the example Winsock service above to register the RnR connection point for the service.

/*
** Simple Winsock Service
*/
#include <winsock2.h>
#include <stdio.h>
 
//{A9033BC1-ECA4-11cf-A054-00AA006C33ED}
static GUID SVCID_EXAMPLE_SERVICE = 
{ 0xa9033bc1, 0xeca4, 0x11cf, { 0xa0, 0x54, 0x0, 0xaa, 0x0, 0x6c, 0x33, 0xed } };
 
static WCHAR    ServiceInstanceName[] = L"Example Service Instance";
static WCHAR    ServiceInstanceComment[] = L"ExampleService instance registered in the directory service through RnR";
 
INT 
serverRegister(SOCKADDR * sa)
{
    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
    //information. This is what clients will use to make a connection.
    //
    //Note that we zeroed out the LocalAddr because we are using
    //dynamically assigned port numbers.
    //
    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 = &SVCID_EXAMPLE_SERVICE;
    QuerySet.lpszServiceInstanceName = ServiceInstanceName;
    QuerySet.lpszComment = ServiceInstanceComment;
    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 );
 
}