-1
我想創建一個安全的套接字連接,但我有一些錯誤。 這裏是代碼:SSLSocket setsockopt返回10042和WSAIoctl 10045
int main(int argc,char *argv[])
{
WSADATA wd;
SOCKET s;
SSLVALIDATECERTHOOK hook;
int secopt=SO_SEC_SSL;
WSAStartup(MAKEWORD(2,2),&wd);
s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
setsockopt(s,SOL_SOCKET,SO_SECURE,&secopt,sizeof(secopt));
hook.HookFunc=SSLValCert;
hook.pvArg=NULL;
WSAIoctl(s,SO_SSL_SET_VALIDATE_CERT_HOOK,&hook,sizeof(hook),NULL,0,NULL,NULL,NULL);
/* Some code goes here */
closesocket(s);
WSACleanup();
}
int CALLBACK SSLValCert(DWORD dwType,LPVOID pvArg,DWORD dwChainLen,LPBLOB pCertChain,DWORD dwFlags)
{
return SSL_ERR_OKAY;
}
在這段代碼setsockopt
回報10042和WSAIoctl
回報10045.
您是否檢查過[錯誤代碼的含義](https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v = vs.85).aspx)? –
是的,但我不明白爲什麼會發生這種情況? –
另外我想說的是,常量'SO_SECURE','SO_SEC_SSL'和'SO_SSL_VALIDATE_CERT_HOOK'沒有在'winsock2.h'中聲明。我已經直接在代碼中聲明瞭它們。值爲'SO_SECURE = 0x2001','SO_SEC_SSL = 0x2004'和'SO_SSL_VALIDATE_CERT_HOOK = 8' –