estructura ASSOCIATE_NAMERES_CONTEXT_INPUT (mstcpip.h)

La estructura ASSOCIATE_NAMERES_CONTEXT_INPUT contiene el identificador de configuración de transporte y el identificador de un nombre de dominio completo.

Sintaxis

typedef struct _ASSOCIATE_NAMERES_CONTEXT_INPUT {
  TRANSPORT_SETTING_ID TransportSettingId;
  UINT64               Handle;
} ASSOCIATE_NAMERES_CONTEXT_INPUT, *PASSOCIATE_NAMERES_CONTEXT_INPUT;

Miembros

TransportSettingId

Identificador de configuración de transporte.

Handle

Identificador de un nombre de dominio completo.

Comentarios

Por lo general, puede usar ASSOCIATE_NAMERES_CONTEXT_INPUT para aplicar la directiva basada en el nombre de dominio completo (FQDN), en lugar de solo la dirección IP. Para ello, recupere un identificador de un FQDN con una llamada a GetAddrInfoEx mediante la estructura addinfoex4. Desde allí, puede usar el identificador en ASSOCIATE_NAMERES_CONTEXT_INPUT en una llamada a WSAIoctl mediante el SIO_APPLY_TRANSPORT_SETTING ioctl.

Ejemplos

En el código siguiente se describe cómo realizar una llamada a GetAddrInfoEx con una estructura addinfoex4 para recuperar el identificador de un FQDN. A continuación, el ejemplo llama a WSAIoctl con la estructura ASSOCIATE_NAMERES_CONTEXT_INPUT .

// 
// Connect to a server using its IPv4 addresses 
// 

VOID 
ConnectServer( 
    PCWSTR server) 
{ 
    int iResult; 
    PADDRINFOEX4 pResult = NULL; 
    ADDRINFOEX3 hints = { 0 }; 
    PADDRINFOEX4 pCur = NULL; 
    WSADATA wsaData; 
    SOCKET connectSocket = INVALID_SOCKET; 
    ULONG bytesReturned = 0; 
    ASSOCIATE_NAMERES_CONTEXT_INPUT input = { 0 }; 
    SOCKADDR_IN clientService; 
    wchar_t ipstringbuffer[46]; 
    String string; 
    DWORD dwRetval; 
    //  
    //  Initialize Winsock 
    // 
    iResult = WSAStartup( 
        MAKEWORD(2, 2),  
        &wsaData); 
    if (iResult != 0) { 
        printf("WSAStartup failed: %d\n", iResult); 
        goto Exit; 
    } 

    //  
    // Create a SOCKET for connection 
    // 
    connectSocket = socket( 
        AF_UNSPEC,  
        SOCK_STREAM,  
        IPPROTO_TCP); 
    if (connectSocket == INVALID_SOCKET)  
    { 
        printf("socket failed: %d\n", WSAGetLastError()); 
        goto Exit; 
    } 

    // 
    // Do name resolution 
    // 

    hints.ai_family = AF_INET; 
    hints.ai_socktype = SOCK_STREAM; 
    hints.ai_flags = AI_EXTENDED | AI_FQDN | AI_CANONNAME | AI_RESOLUTION_HANDLE; 
    hints.ai_version = ADDRINFOEX_VERSION_4; 

    dwRetval = GetAddrInfoExW( 
        server, 
        NULL, 
        NS_DNS, 
        NULL, 
        (const ADDRINFOEXW*)&hints, 
        (PADDRINFOEXW*)&pResult, 
        NULL, 
        NULL, 
        NULL, NULL); 
    if (dwRetval != 0) { 
        printf("GetAddrInfoEx failed with error: %d\n", dwRetval); 
        goto Exit; 
    } 
    input.TransportSettingId.Guid = ASSOCIATE_NAMERES_CONTEXT; 
    input.Handle = pResult->ai_resolutionhandle; 

    // 
    // Associate socket with the handle 
    // 

    if (WSAIoctl( 
            connectSocket, 
            SIO_APPLY_TRANSPORT_SETTING, 
            (VOID *)&input, 
            sizeof(input), 
            NULL, 
            0, 
            &bytesReturned, 
            NULL, 
            NULL) == SOCKET_ERROR) 
    if (iResult != 0){ 
        printf("WSAIoctl failed: %d\n", WSAGetLastError()); 
        goto Exit; 
    }     

    // 
    // Connect to server 
    // 

    pCur = pResult; 
    while (pCur != NULL) 
    { 
        if (pCur->ai_addr->sa_family == AF_INET) 
        { 
            clientService = *(const sockaddr_in*)pCur->ai_addr; 
            clientService.sin_port = htons(80); 
            if (connect( 
                connectSocket, 
                (const SOCKADDR *)&clientService, 
                sizeof(clientService)) == SOCKET_ERROR) 
            { 
                printf("connect failed: %d\n", WSAGetLastError()); 
                goto Exit; 
            } 
        } 
        pCur = pCur->ai_next; 
    } 

Exit: 

    if (connectSocket != INVALID_SOCKET) 
    { 
        closesocket(connectSocket); 
    } 
    if (pResult) 
    { 
        FreeAddrInfoExW((ADDRINFOEXW*)pResult); 
    } 
    WSACleanup(); 
    return; 
} 

Requisitos

Requisito Value
Cliente mínimo compatible Windows 10 [solo aplicaciones de escritorio]
Servidor mínimo compatible Windows Server 2016 [solo aplicaciones de escritorio]
Encabezado mstcpip.h

Consulte también

GetAddrInfoEx

WSAIoctl

addrinfoex4