Win Socket Creation fails with Error code 10022 if non super user

让人想犯罪 __ 提交于 2020-01-03 04:15:49

问题


I encountered a very peculiar behavior on windows 7 with winsockets. Two librarys (Wt http://www.webtoolkit.eu/ libwebsocket https://libwebsockets.org/ ) and as well myself with a sample code got the errorcode 10022 ( Invalid argument. ) when running as normal user, and never when running as superuser. Neither the devs at the lib projects nor I can find a reason. I fear that its maybe a very hidden idiotic group rule in our company.

Example code to trigger:

#include <cstdlib>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <iostream>
#include <exception>
#include <stdexcept>
int main(int argc, char** argv) {
    WSADATA sinfo;
    int sr =  WSAStartup(MAKEWORD(2, 2),&sinfo);
    if (sr != 0)
    {
        std::cout << sr << std::endl;
        throw std::runtime_error("WSAStartup");
    }
    SOCKET listenSocket = socket(PF_INET, SOCK_STREAM, 0);
    if (listenSocket == INVALID_SOCKET)
    {
        std::cout << "Failed with "<< WSAGetLastError() << " " << GetLastError()<< std::endl;
        throw std::runtime_error("Socket");
    }
    WSACleanup();
    std::cout << "Finished" << std::endl;
    return 0;
} 

Output is: "Failed with 10022 10022"(and then of course the runtime_error caused terminate).


回答1:


Finally I got the reason: This happens if the binary is being placed on e.g. execute from a network share/volume.

Microsoft has recognized the problems and delivers a hotfix: https://support.microsoft.com/en-us/kb/2649107



来源:https://stackoverflow.com/questions/31936303/win-socket-creation-fails-with-error-code-10022-if-non-super-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!