Winsock, ConnectEx, shutdown, SO_UPDATE_CONNECT_CONTEXT and WSANOTCONN

 //=======================================================
#include
#define WIN32_LEAN_AND_MEAN
#include
#include


int main() {
// App
int iRet;


// Startup WinSock
WSADATA wsaData;

printf("WSAStartup(...):/n");

iRet = WSAStartup(
MAKEWORD(2,2),
&wsaData
);
printf("iRet: %d/n", iRet);
printf("MAKEWORD(2,2): %x/n", MAKEWORD(2,2));
printf("wsaData.wVersion: %x/n", wsaData.wVersion);
printf("wsaData.wHighVersion: %x/n", wsaData.wHighVersion);
printf("wsaData.szDescription: %s/n", wsaData.szDescription);
printf("wsaData.szSystemStatus: %s/n", wsaData.szSystemStatus);


// Socket
SOCKET s;

printf("/n/nWSASocket(...):/n");

s = WSASocket(
AF_INET,
SOCK_STREAM,
IPPROTO_TCP,
NULL,
0,
WS_OVERLAPPED
);
printf("s: %d/n", s);

setsockopt( s,
SOL_SOCKET,
SO_UPDATE_CONNECT_CONTEXT,
NULL,
0 );

// Load ConnectEx
GUID GuidConnectEx = WSAID_CONNECTEX;
LPFN_CONNECTEX lpfnConnectEx = NULL;
DWORD dwBytes = 0;

printf("/n/nWSAIoctl(...) for ConnectEx:/n");

iRet = WSAIoctl(
s,
SIO_GET_EXTENSION_FUNCTION_POINTER,
&GuidConnectEx,
sizeof(GuidConnectEx),
&lpfnConnectEx,
sizeof(lpfnConnectEx),
&dwBytes,
NULL,
NULL
);
printf("iRet: %d/n", iRet);
printf("sizeof(GuidConnectEx): %d/n", sizeof(GuidConnectEx));
printf("lpfnConnectEx: %x/n", lpfnConnectEx);
printf("sizeof(lpfnConnectEx): %d/n", sizeof(lpfnConnectEx));
printf("dwBytes: %d/n", dwBytes);
printf("WSAGetLastError(): %d/n", WSAGetLastError());


// Try ConnectEx
SOCKADDR_IN addr;
BOOL bRet;
OVERLAPPED overlapped;

printf("/n/nlpfnConnectEx(...):/n");

memset(&addr, 0, sizeof(addr));

addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(88);

memset(&overlapped, 0, sizeof(overlapped));

dwBytes = 0;
bRet = lpfnConnectEx(
s,
(LPSOCKADDR)&addr,
sizeof(addr),
NULL,
0,
NULL,
&overlapped
);
printf("bRet: %d/n", bRet);
printf("sizeof(addr): %d/n", sizeof(addr));
printf("WSAGetLastError(): %d/n", WSAGetLastError());




// Wait
char str[255];
gets(str);

return 0;
}

你可能感兴趣的:(Winsock, ConnectEx, shutdown, SO_UPDATE_CONNECT_CONTEXT and WSANOTCONN)