Re: PRB:socket api "listen" always fails returning WSAEINVAL and p



hi,
Thanks for prompt response.I really appreciate.
I have verified both are having same subnet mask 255.255.255.0
WinXP pc is not running any firewall as i have switched off firewall and
security too.

As you haev written "It is possible to configure that to send the ICMP
packets, but reject incoming packets.
"
Are you talking about WINCE, if yes,then how can i make sure that it is not
happening?

I am using winsock.h, this could be a problem as during WSAStartup i am
using 2.2 version?I will try including winsock2.h and let you know.
I 'll also remove SOCKADDR and try to use given with .h file.
thanks and Regards.

"Paul G. Tobey [eMVP]" wrote:

Verify for me that both the PC and your target device use the same subnet
mask. Is the target device running the Windows CE firewall? Is the PC
running Windows Firewall? It is possible to configure that to send the ICMP
packets, but reject incoming packets.

You should not be defining SOCKADDR yourself. That's a WinSock structure
name and you should be using the WinSock structure, not your own version.
Your version does NOT match the WinSock version. This probably has nothing
to do with the ping situation, but what you're doing there is wrong. Are
you even including winsock2.h or winsock.h?

No, continue separate threads separately. If I had anything to add on that
issue, I would have replied.

Paul T.

"nishant" <nishant@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D8159196-7421-4FFA-89AD-2ADCC2B177C8@xxxxxxxxxxxxxxxx
Hi Paul,
Thanks for reply.
No subnet mask and MAC address of the ethernet card both are fine as i am
using nomal ether net card brought from market,I have already verified
those.
ip address of wince target:10.123.4.93
ip addrees of the WinXP pc:10.123.4.101
subnet mask:255.255.255.0

I am defining SOCKADDR as ,I need to pass some info to my PAL layer,but
that
should not cause any problem as i am passing the right value.
Is seems that some component is filtering packets coming outside but that
is
also doubtful as i can do ping from one side and can also access internet
websites.

Sorry for mixing issues but actually i posted another issue related to
com
port issue on emulator in wince 6.0.Can you give some idea to that too?I
want
to use com port as normal com port to read and write data and not to use
as
any modem like thing, how?
Thanks and Regards.

"Paul G. Tobey [eMVP]" wrote:

Why are you defining SOCKADDR yourself? Are you defining it yourself?

Your PING information sounds like you don't have the subnet mask set
correctly on the device or that the device has an incorrect (or
ridiculous),
Ethernet address (0xffffffffffff, for example, if the address has not
been
set). What are the IP addresses of the your target platform and the PC
you
can successfully ping from it, but can't ping in the other direction?

Paul T.

"nishant" <nishant@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:759C15AF-8093-42FE-B34B-C981D83DE8E0@xxxxxxxxxxxxxxxx
Hi Paul,
thanks for your reply.
Actually My code is giving problem when i try
my application on CEPC(wince 6.00 on x86 platform) but as i try it on
wince
6.0 emulator, it works fine.

Also I am not able to ping my target pc(x86 platfrom where wince runs)
from
other WinXP PCs connected to same LAN, though i can ping from my target
PC
to other PCs.This also confirms that adapter is enabled,also i can open
inetrnet sites.

Code where problem is coming is given below for your reference:
typedef struct
{
INT16 reserved_0;
UINT16 sin_port;
UINT32 sin_addr;
CHAR reserved_1[8];
} SOCKADDR;

int TCPListen(){
int listener;
int readset[2] = {0, 0};
unsigned int result;
SOCKADDR name, incoming;
VOID *warn = param;
param = warn;
char opt_c;
int result = 0;
ULONG opt_l;

runningGlobal = 1;

if (!winsock_initialized)
{
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD( 2, 2 );
WSAStartup( wVersionRequested, &wsaData );
GetErrno();
winsock_initialized = 1;
}

listener = socket(AF_INET, SOCK_STREAM, 0);
GetErrno();

if (listener == 0)
{
DEBUGMSG(1,(DEBUGTXT("socket() failed, errno=%d\n"), errno));
return ERROR;
}
opt_l = 0;
result = ioctlsocket(listener, FIONBIO, &opt_l);
GetErrno();
if (result!=0) DEBUGMSG(1,(DEBUGTXT("ioctlsocket() failed,
errno=%d\n"), errno));

opt_c = 1;
result = setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &opt_c,
sizeof(opt_c));
GetErrno();
if (result!=0) DEBUGMSG(1,(DEBUGTXT("setsockopt() failed,
errno=%d\n"), errno));

opt_c = 1;
result = setsockopt(listener, SOL_SOCKET, SO_DONTLINGER, &opt_c,
sizeof(opt_c));
GetErrno();
if (result!=0) DEBUGMSG(1,(DEBUGTXT("setsockopt() failed,
errno=%d\n"), errno));

opt_c = 1;
result = setsockopt(listener, IPPROTO_TCP, TCP_NODELAY, &opt_c,
sizeof(opt_c));
GetErrno();
if (result!=0) DEBUGMSG(1,(DEBUGTXT("setsockopt() failed,
errno=%d\n"), errno));

memset(&name, 0, sizeof(name));

name.sin_port = tcpipPortGlobal>>8 | tcpipPortGlobal<<8;
name->reserved_0 = AF_INET;

do
{
result = bind(listener, (struct sockaddr*)&name,
sizeof(SOCKADDR));

if ( result == 0 ) {
PRINTF("tcpip: bound to port %d...\n", tcpipPortGlobal );
} else {
PRINTF("tcpip: error binding to port %d,
result=0x%04ld...\n",
tcpipPortGlobal, result);
Sleep( 6000 );
}
} while ( runningGlobal && result!=0 );

while (runningGlobal)
{
do
{
/* Issue is here:
when it comes first tiem over here listen gives success but
as PAL_NET_Select timeouts and it comes here again to listen,
it always fails thereafter */
result = listen(listener, SOMAXCONN);
GetErrno();
} while (result!=0 && errno==EINTR);

if (result != 0)
{
PRINTF("tcpip: error listening\n");
Sleep( 6000 );
continue;
}

readset[0] = listener;
result = PAL_NET_Select( readset, 0, 0, 6000 );
/* code for pal_net_select given below*/
if ( result != SUCCESS ) {
continue;
}

/* do the accept */

PRINTF("Stcpip: connection established\n");
/* start the main loop */
/* do read and write */
}

/* shutdown and close listener sockets, preventing any further
connections */
closesocket( listener );
PRINTF("tcpip: listener closed\n");
}
RESULT PAL_NET_Select( int *read, int *write, int *excpt, UINT32
timeout)
{
struct timeval tv;
fd_set r, w, e;
int result, i, fdmax;

fdmax = 0;

FD_ZERO(&r);
FD_ZERO(&w);
FD_ZERO(&e);

if (read)
{
for (i=0; read[i]; i++)
{
FD_SET(read[i], &r);
if (read[i]>fdmax) fdmax=read[i];
}
}

if (write)
{
for (i=0; write[i]; i++)
{
FD_SET(write[i], &w);
if (write[i]>fdmax) fdmax=write[i];
}
}

if (excpt)
{
for (i=0; excpt[i]; i++)
{
FD_SET(excpt[i], &e);
if (excpt[i]>fdmax) fdmax=excpt[i];
}
}

tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;


do
{
result = select(fdmax+1, &r, &w, &e, &tv);
GetErrno();
}
while ( result<0 && errno==EINTR );

if (result>0)
{
if (read)
for (i=0; read[i]; i++)
if (!FD_ISSET(read[i], &r))
read[i] = 0;
if (write)
for (i=0; write[i]; i++)
if (!FD_ISSET(write[i], &w))
write[i] = 0;
if (excpt)
for (i=0; excpt[i]; i++)
if (!FD_ISSET(excpt[i], &e))
excpt[i] = 0;
}

return result>0 ? 0 : (result==0 ? PAL_NET_TIMEOUT : PAL_NET_ERROR);

} /* PAL_NET_Select() */

Thanks and Regards.


"Paul G. Tobey [eMVP]" wrote:

According to the help for listen, WSAEINVAL returned from listen
indicates
that the socket isn't bound. I suppose that you might also be passing
a
backlog value that's invalid. Perhaps you bound it to a specific IP
that
the device doesn't have? Or to an adapter that's disabled? Pseudo
code
for
this type of question won't cut it; you'll have to post the real code
(and
try a few things first like verifying that bind() worked and that
you're
binding to ANY).

Paul T.

"nishant" <nishant@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EFAEF5B1-2F12-4C49-906C-BA3534AFA5DF@xxxxxxxxxxxxxxxx
hi,
I am writing a application for wince 5.0 which is communicating to
other
application on WINXP machine using tcp/ip connection.But i am facing
2
.



Relevant Pages

  • Re: PoPTop, Samba, IPTables
    ... and no one machine can ping to me. ... Here it is from WinXP: ... You only have a route set up through the firewall for 192.168.0.0/24 so only ... you tried enabling "Use Default Gateway on Remote Network" in the Advanced ...
    (comp.os.linux.networking)
  • Re: W2000 Pro networking problem
    ... The same subnet mask is used in all 3 ... firewall, did a re-scan of home network and voila! ... Thanks Pegasus for leading me to do the re-scan. ... > Until you resolve the ping problem there is no point in ...
    (microsoft.public.win2000.networking)
  • almost solved
    ... After I disabled the built-in firewall on windows server 2003, i could ping ... From the winxp computer I cannot ping the windows server, ...
    (microsoft.public.windowsxp.general)
  • Re: FreeBSD basic networking
    ... > The trouble is my BSDbox can seem to ping the Winxp ... which enables the Windows firewall. ...
    (freebsd-questions)
  • Re: Hiding winxp pro?
    ... Win2000 don't have a Microsoft firewall like WinXP, but you can add the same feature with alternative like Norton Security software. ... If you want the WinXP pc respond to your ping command, you should enable it by go to the pc & customize his firewall options. ...
    (microsoft.public.win2000.networking)

Loading