473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

accept() always returns 204.204.204.204

Hi,

I wrote an app that accepts a client connection.

[snip]
SOCKADDR_IN sockAddrIn;
unsigned int clientLen = sizeof( sockAddrIn );
SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
NULL );

if ( conn == INVALID_SOCKET )
{
int errorno = WSAGetLastError();
if ( errorno != WSAEWOULDBLOCK )
{
return -1;
}
else
{
return false;
}

}
else
{

CFusionSCK_Client myclient(m_ConnFlags);

myclient.Socket( &conn );
myclient.AddrIn( &sockAddrIn );
myclient.IPAddress( inet_ntoa( sockAddrIn.sin_addr ) );
myclient.Port( sockAddrIn.sin_port );

m_listClients.push_back( myclient );

}

return false;

[/snip]

The IP address pulled out of the SOCKADDRIN structure is always
204.204.204.204, no matter what machine I connect from. The connection
is otherwise functional. Has anyone had this problem before?

Thanks in advance,
Tom
Jan 4 '08 #1
2 3560
"TBass" <tb*@automateddesign.comwrote in message
news:4a**********************************@s19g2000 prg.googlegroups.com...
Hi,

I wrote an app that accepts a client connection.

[snip]
SOCKADDR_IN sockAddrIn;
unsigned int clientLen = sizeof( sockAddrIn );
SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
NULL );

From the docs: "If addr and/or addrlen are equal to NULL, then no
information about the remote address of the accepted socket is returned."

Maybe try

SOCKADDR_IN sockAddrIn;
int clientLen = sizeof( sockAddrIn );
SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
&clientLen );

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

>
if ( conn == INVALID_SOCKET )
{
int errorno = WSAGetLastError();
if ( errorno != WSAEWOULDBLOCK )
{
return -1;
}
else
{
return false;
}

}
else
{

CFusionSCK_Client myclient(m_ConnFlags);

myclient.Socket( &conn );
myclient.AddrIn( &sockAddrIn );
myclient.IPAddress( inet_ntoa( sockAddrIn.sin_addr ) );
myclient.Port( sockAddrIn.sin_port );

m_listClients.push_back( myclient );

}

return false;

[/snip]

The IP address pulled out of the SOCKADDRIN structure is always
204.204.204.204, no matter what machine I connect from. The connection
is otherwise functional. Has anyone had this problem before?

Thanks in advance,
Tom
Jan 4 '08 #2
TBass wrote:
SOCKADDR_IN sockAddrIn;
unsigned int clientLen = sizeof( sockAddrIn );
SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
NULL );

You're passing NULL to accept() for the length of the address field,
which causes no information to be returned (sane behavior -- without
knowing the number of bytes to the memory pointed, it could not possibly
do anything reasonable)

Try:

SOCKET conn = accept(m_Socket,
(struct sockaddr *)&sockAddrIn,
&clientLen);

The IP address pulled out of the SOCKADDRIN structure is always
204.204.204.204, no matter what machine I connect from. The connection
is otherwise functional. Has anyone had this problem before?
204 is 0xCC, which is the value that the compiler uses for
uninitialized stack variables in debug builds to help catch bad
accesses. Since you passed NULL, nothing was returned, and sockAddrIn
was uninitialized.

-n
Jan 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben | last post by:
hi all, Just trying to figure out what the accept() method in socket.py does. Lets consider the following webserver code: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port =...
2
by: Rene van Hoek | last post by:
Hi, I am using Xalan 1.8.0 and Xerces 2.6.0 in C++. I have an XML document which I first transform into an other XML document using an XSL styelsheet. Then I want to parse with XPathEvaluator...
5
by: Blatwurst | last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the...
2
by: Marina | last post by:
I get an "access violation" when I use someting like this: @@@@@@@@@@@@@@ string tempo; const char *output; vector <ofstream> outs(3); .... .... open_output=(const char *)tempo.c_str();...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
1
by: opi | last post by:
My blocking TCP server hangs in the Accept method when the client software sometimes gets an error. Are there any ways to stop this blocking in the Accept method so I dont have to restart the...
2
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the...
3
by: YSpa | last post by:
Hi, I'm using SQL-Server Express 2005 on Windows XP Prof. and after working properly for some time my asp.net application suddenly gave the error that my DateFormat wasn't accepted while using...
0
by: Philip Semanchuk | last post by:
On Oct 16, 2008, at 6:50 AM, Martin Bachwerk wrote: I'm not sure what you mean by this. In my experiment with wget, Google respects the Accept-Language header. On other words, this returns a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.