« Return to Thread: socket woes

Re: socket woes

by kerravon86 :: Rate this Message:

Reply to Author | View in Thread

--- In hercules-390@..., "kerravon86" <kerravon86@...> wrote:
>
> With 21 failures in total out of 100 runs.

Even with a 10 second pause after a failure, I
still got 16 out of 100 failures. The failures
are less batched, but still sometimes batched.
It's difficult to tell at this level. Could
just be coincidence.

Not sure if it's relevant, but I have two
non-Hercules errors that started a few months
ago:

1. Type in www.google.com.au
It will wait and wait. Even if I type in another
address it will still wait.
Open another screen and go to the same address, and
it usually works. Original IE window never comes
back, even after hours.

2. Type in "cvs diff" or any other command to a
sourceforge project. 50% of the time it hangs and
never comes back. ctrl-c, try again, usually works.

I did an internet search and of course the world
is full of bugs:

http://forums.sun.com/thread.jspa?threadID=670368

and it's difficult to tell what's relevant.

All IE plugins are disabled on my system (deliberately).

IE also crashes regularly on my system.

I always seem to have so many PC problems.

Anyway, I figured it was probably an error on the
Windows side, but decided to inspect the parameters
that were being passed to connect(). To my surprise,
the port number was no longer 0.

It turns out that getsockname() is changing the
port number. I tried forcing it back to 0, but
that failed.

It took all day, most spent on a wild goose chase,
but I finally found out where it's going wrong.

The address sometimes stays correct:

byte 4c is 7f
byte 4d is 7f
byte 4e is 7f

and sometimes gets clobbered:

byte 4c is 7f
byte 4d is 7f
byte 4e is 0

    if (0
        || SOCKET_ERROR   == bind( temp_listen_socket, (SOCKADDR*) &localhost_a
        || (fprintf(stderr, "byte 4c is %x\n", ((unsigned char *)&localhost_add
        || SOCKET_ERROR   == listen( temp_listen_socket, 1 )
        || (fprintf(stderr, "byte 4d is %x\n", ((unsigned char *)&localhost_add
        || SOCKET_ERROR   == getsockname( temp_listen_socket, (SOCKADDR*) &loca
        || (fprintf(stderr, "byte 4e is %x\n", ((unsigned char *)&localhost_add
        || INVALID_SOCKET == (SOCKET)( socket_vector[1] = socket( AF_INET, SOCK


That byte is the first byte of the address.

        || (fprintf(stderr, "byte 4e is %x\n",
        ((unsigned char *)&localhost_addr)[4]) == 999)

And it's being wiped out by getsockname.

getsockname returns the port number, which I think we
need, but wipes out the address randomly.

The documentation:

http://msdn.microsoft.com/en-us/library/ms738543(VS.85).aspx

says:

The getsockname function does not always return information about the host address when the socket has been bound to an unspecified address, unless the socket has been connected with connect or accept (for example, using ADDR_ANY). A Windows Sockets application must not assume that the address will be specified unless the socket is connected. The address that will be used for the socket is unknown unless the socket is connected when used in a multihomed host. If the socket is using a connectionless protocol, the address may not be available until I/O occurs on the socket.

Not sure whether that says it or the app is misbehaving.

A simple fix then would seem to be to stop reusing the
same variable, and then just copy the port number
across.

Or is there some other intention?

BFN.  Paul.


 « Return to Thread: socket woes