locked
socket() fails with error 10022 when application is run from certain network shares on Vista and Windows 7 (works on XP) RRS feed

  • Question

  • Hi,

    We've run into a strange problem where our network application runs fine from most network shares, but fails on a particular one. 

    The socket() function returns an 10022 (WSAEINVAL) error when this occurs.  It runs fine locally and on most network shares.

    Here's a sample program that causes the error:

    #include "stdafx.h"
    #include <windows.h>
    #include <winsock.h>
    #include <stdio.h>

    int _tmain(int argc, _TCHAR* argv[])
    {

        WSADATA wsadata;
        //request socket version 2.2
        WORD vers = MAKEWORD (2, 2);
        int ret, sock;

        //initialize windows sockets
        ret = WSAStartup (vers, &wsadata);
        if (ret)
        {
            fprintf (stderr, "WSAStartup failed: rc: %d\n", ret);   
            fprintf (stderr, "err: %lu\n", WSAGetLastError());
            return 1;
        }
        else
        {
            printf("WSAStartup succeeded...\n");
        }


        printf("WSA Information:\n");
        printf("high ver: %d.%d ver: %d.%d\n",
            HIBYTE(wsadata.wHighVersion),
            LOBYTE(wsadata.wHighVersion),
            HIBYTE(wsadata.wVersion),
            LOBYTE(wsadata.wVersion));
        printf("desc: %s\n", wsadata.szDescription);
        printf("stat: %s\n", wsadata.szSystemStatus);
        printf("max sock: %d max udp size: %d\n", wsadata.iMaxSockets, wsadata.iMaxUdpDg);

        //create a simple socket
        sock = socket (AF_INET, SOCK_STREAM, 0);
        if (sock == INVALID_SOCKET)
        {
            int iErr = WSAGetLastError();
            LPVOID lpMsgBuf;
             FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                iErr,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                (LPTSTR) &lpMsgBuf,
                0, NULL );


            
            fprintf (stderr, "socket failed: err: %lu\n %s\n", iErr, lpMsgBuf);

            LocalFree(lpMsgBuf);
        }
        else
        {
            fprintf (stderr, "socket succeeded: %d\n", sock);
            closesocket (sock);
        }
        WSACleanup ();
        return 0;
    }

     

    When run locally or on most shares you get success:

     

    C:\Users\test\Desktop>SocketTest.exe

    WSAStartup succeeded...

    WSA Information:

    high ver: 2.2 ver: 2.2

    desc: WinSock 2.0

    stat: Running

    max sock: 0 max udp size: 0

    socket succeeded : 68

     

    When run from a certain network share:  (Q: is a mapped share, SocketTest.exe is located on the share)

     

    Q:\VISTA_trials>SocketTest.exe

    WSAStartup succeeded...

    WSA Information:

    high ver: 2.2 ver: 2.2

    desc: WinSock 2.0

    stat: Running

    max sock: 0 max udp size: 0

    socket failed : err: 10022

     An invalid argument was supplied.

     

    Since it works on most shares and locally, it makes me think it is some kind of security problem.  It fails the same way when run with Administrator permissions.  It reminds me of the .NET application running from a share permissions.  I didn't see anything suspicious with process monitor.  Unfortunately, I couldn't step into the socket() function to see exactly where it fails.  I'm going to install a checked build of Vista to see if that helps.  Any idea on how to proceed / fix this problem?  This looks like the same problem posted here: http://www.ureader.com/msg/14772558.aspx

     

    Thanks,

    Ben

    Thursday, September 23, 2010 2:40 PM

Answers