[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug in sockets getSender() commoncpp2-1.0.9
From: |
Brandon B |
Subject: |
bug in sockets getSender() commoncpp2-1.0.9 |
Date: |
Wed, 16 Apr 2003 16:03:21 -0500 |
The sockets->getSender() function is peeking the incoming packet with a max
length of 1 byte. This causes any packet over 1 byte to get an error, which
wipes out the senders ip/port.
I think a better way to approach this is to have the return value be
ignored. Instead, check the last length parameter of the recvfrom to see if
there was a valid sender address passed back, if that is 0, wipe out the
senders ip/port otherwise return it.
This is the way I worked around the issue.
InetHostAddress Socket::getSender(tpport_t *port) const
{
struct sockaddr_in from;
char buf;
socklen_t len = sizeof(from);
int rc = ::recvfrom(so, &buf, 1, MSG_PEEK,
(struct sockaddr *)&from, &len);
if(len > 0)
{
*port = ntohs(from.sin_port);
}
else
{
*port = 0;
memset(&from.sin_addr, 0, sizeof(from.sin_addr));
}
return InetHostAddress(from.sin_addr);
}
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug in sockets getSender() commoncpp2-1.0.9,
Brandon B <=