bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in WIN32 getPeer


From: Siegfried Becker
Subject: Bug in WIN32 getPeer
Date: Thu, 13 Dec 2001 09:26:08 +0100

Hi,

I use the CommonC++ lib 1.9 under linux and also under Windows.
When calling getPeer under Windows you will not get the peer host, because
the method ::recvfrom(...) will return with -1 because the buffersize of 1.
In the following lines I have my modification which will work.

Best regards

Siegfied Becker



in socket.cpp

InetHostAddress UDPSocket::getPeer(tpport_t *port) const
{
        char buf;
        socklen_t len = sizeof(peer);
        int rtn = ::recvfrom(so, &buf, 1, MSG_PEEK, (struct sockaddr *)&peer,
&len);

#ifdef WIN32
        if(rtn < 1 && WSAGetLastError() != WSAEMSGSIZE)
        {
                if(port)
                        *port = 0;

                memset((void*) &peer, 0, sizeof(peer));
        }
#else
        if(rtn < 1)
        {
                if(port)
                        *port = 0;

                memset((void*) &peer, 0, sizeof(peer));
        }
#endif
        else
        {
                if(port)
                        *port = ntohs(peer.sin_port);
        }
        return InetHostAddress(peer.sin_addr);
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]