Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#116 winsock2.h struct sizeerror in mingw 1.1

closed
Earnie Boyd
2002-03-04
2002-02-26
No

Looks like some structure size (probably sockaddr) is
wrong for newer versions of windoze.

On my windoze-xp system, getting a list of interfaces
doesn't quite work as expected and only the first
address in the list looks ok, with the netmask and
broadcast address being all zeros.

If I hack the sa_data field of struct sockaddr in
winsock2.h to be
char sa_data[22];
rather than
char sa_data[14];

then things work fine.

Discussion

  • Danny Smith
    Danny Smith
    2002-02-26

    Logged In: YES
    user_id=11494

    Can you submit sample code that shows the bug on XP but not
    on earlier win. XP has IPv6 support and there may be a
    conflict if you are using that protocol.
    Danny

     
  • Logged In: YES
    user_id=470508

    OK. Code fragment follows.

    I'm only assuming this code would work on earlier versions
    of windows ... I only have an XP system, and haven't had
    that for long (I'm a GNU/Linux user).

    I did a standard install of XP - so if there is an option
    to turn on/off IPv6 support, I didn't see it, and am using
    the default.

    I would expect the data structure size to be the same (big
    enough for IPv6) irrespective of whether the IP code in the kernel was actually using IPv6 ... so I suspect that the winsock2.h file needs some code to vary the size of the structure depending on which version of windows it's being used on.

    {
    INTERFACE_INFO InterfaceList[20];
    unsigned long nBytesReturned;
    int i, nNumInterfaces;
    SOCKET desc = WSASocket(PF_INET, SOCK_RAW, AF_INET, 0, 0, 0);

    if (desc == INVALID_SOCKET)
    {
    fprintf(stderr, "Failed to get a socket. Error %s\n", WSAGetLastError());
    exit(1);
    }

    memset((void*)InterfaceList, '\0', sizeof(InterfaceList));
    if (WSAIoctl(desc, SIO_GET_INTERFACE_LIST, 0, 0, (void*)InterfaceList,
    sizeof(InterfaceList), &nBytesReturned, 0, 0) == SOCKET_ERROR)
    {
    fprintf(stderr, "Failed WSAIoctl. Error %s\n", WSAGetLastError());
    exit(1);
    }

    nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);

    for (i = 0; i < nNumInterfaces; i++)
    {
    u_long nFlags = InterfaceList[i].iiFlags;

    if ((nFlags & IFF_UP)
    && (InterfaceList[i].iiAddress.sa_family == AF_INET))
    {
    fprintf(stderr, "address (%s)\n",
    inet_ntoa(((struct sockaddr_in*)
    &(InterfaceList[i].iiAddress))->sin_addr));
    fprintf(stderr, "metmask (%s)\n",
    inet_ntoa(((struct sockaddr_in*)
    &(InterfaceList[i].iiNetmask))->sin_addr));
    fprintf(stderr, "broadcast (%s)\n",
    inet_ntoa(((struct sockaddr_in*)
    &(InterfaceList[i].iiBroadcast))->sin_addr));
    }
    }
    closesocket(desc);
    }

     
  • Danny Smith
    Danny Smith
    2002-02-28

    Logged In: YES
    user_id=11494

    Thanks for the testcase.

    To find out if you have IPv6 installed type "ipv6 if" at
    the command prompt.

    Some changes are indeed needed to both winsock2.h and
    ws2tcpip.h to provide IPv6/v4 compatability. In particular
    INTERFACE_INFO has changed and their is a new structure
    INTERFACE_INFO_EX which does not depend on size of
    address. I'm in process of testing patches. I don't know
    whether they are relevant to your problem or not.

    Cheers

     
  • Logged In: YES
    user_id=470508

    Thanks
    ipv6 up reports that the protocol stack is not installed
    I haven;t noticed INTERFACE_INFO_EX in the documentation
    anywhere ... I'll have a look for it and see if it makes
    any sense to me.

     
  • Danny Smith
    Danny Smith
    2002-02-28

    Logged In: YES
    user_id=11494

    While, we've got each other's attention, would you mind
    testing updated winsock2.h and ws2tcpip.h with your problem
    on XP. They are in the "Existing Files" box below. have a
    look at MSDN docs on
    INTERFACE_INFO_EX and SIO_GET_INTERFACE_LIST_EX

     
  • Logged In: YES
    user_id=470508

    With the new headers, my compile falls over at line 472 in winsock2.h, saying 'parse error before inet_ntoa'
    then 'warning: data definition has no type or storage class'
    followed by similar errors at 481, 482, 483 ...

    I looked at the MSDN win32 api docs and couldn't find
    INTERFACE_INFO_EX or SIO_GET_INTERFACE_LIST_EX

    Are these documented in some special section somewhere?

     
  • Danny Smith
    Danny Smith
    2002-03-01

    Logged In: YES
    user_id=11494

    Sorry. The parse errors arise because of a Watcom/Mingw
    compatability define that is in CVS version of w32api. In
    windef.h there is now this switch:

    #ifdef __GNUC__
    #define DECLARE_STDCALL_P( type ) __stdcall type
    #elif defined(__WATCOMC__)
    #define DECLARE_STDCALL_P( type ) type __stdcall
    #endif /* __GNUC__/__WATCOMC__ */

    The INTERFACE_INFO_EX business was actually from some MS
    IPv6 Technology Preview docs, which I can't seem to find
    any more on the net either. There is a known bug with
    INTERFACE_INFO which is documented in ther MSDN KB as:

    FIX: WSAIoctl SIO_GET_INTERFACE_LIST Option Problem
    (Q181520)
    http://support.microsoft.com/default.aspx?scid=kb;en-
    us;Q181520

    and

    FIX: Call to WSAIoctl with SIO_GET_INTERFACE_LIST Option
    Fails (Q170642) at:
    http://support.microsoft.com/default.aspx?scid=kb;EN-
    NZ;q170642

     
  • Logged In: YES
    user_id=470508

    Thanks.
    After adding a define for DECLARE_STDCALL_P my compile
    failed because it could not find the sa_family member of
    struct sockaddr ... checking through the changes it was
    obviousl that there was a new union sockaddr_gen, and
    changing my code to look in iiAddress.Address.sa_family
    rather than iiAddress.sa_family fixed that problem, and
    my program appeared to run fine.

    Is this based on the preview documentation you had? Are
    microsoft adding the sockaddr_gen union to handle this issue?

     
  • Danny Smith
    Danny Smith
    2002-03-02

    Logged In: YES
    user_id=11494

    I'll tidy up my changes a bit and commit to w32api CVS
    within the Cygwin (winsup) repository. The sockaddr_gen
    info comes from a Google search which turned up some Delphi
    code and Wine docs.

    As it turns out, the bug you reported has been around for
    awhile, is not specific to XP and is only indirectly
    related to IPv6. Thanks for providing the leads.

    Danny

     
  • Danny Smith
    Danny Smith
    2002-03-04

    • status: open --> closed