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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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
issues
1.ping does not work from other machines on network to wince machine
while
reverse works(means ping from wince machine to other machine on
network
get
reply ),even I can access inetnet.
2.Second issue is with listen api which always returns WSAEINVAL.Can
somebody give some idea regarding this?
To give some more idea about problem:I am writing this application
for
CEPC(x86-wince5.0).
I created a socket as socket(AF_INET, SOCK_STREAM, 0) in blocking
mode.After
this bind() api is called to a bind to some port no..
Now in while loop I execute listen(),select() and then accept() as
given
below(just an idea about code):
while(running){
if(listen(created socket handle)!=0){
/* always comes here I checked for return value
it is -1 always and error code is WSAEINVAL*/
continue;
}
if(select()!=0) continue;
if(accept()!=0) continue;
else break;
}

Thanks a lot.









.



Relevant Pages

  • Re: PRB:socket api "listen" always fails returning WSAEINVAL and p
    ... No subnet mask and MAC address of the ethernet card both are fine as i am ... port issue on emulator in wince 6.0.Can you give some idea to that too?I want ... Your PING information sounds like you don't have the subnet mask set ... int listener; ...
    (microsoft.public.windowsce.app.development)
  • Re: PRB:socket api "listen" always fails returning WSAEINVAL and p
    ... Why are you defining SOCKADDR yourself? ... Your PING information sounds like you don't have the subnet mask set ... Also I am not able to ping my target pc(x86 platfrom where wince runs) ... int listener; ...
    (microsoft.public.windowsce.app.development)
  • RE: ICMP (Ping)
    ... No determining a target based upon hatred or zero day exploits. ... As far as the ping sweep stuff, to be honest, I wouldn't ever have ... How you assume they will attack the network or probe ... Almost all scanners and worms even, will hit the range of IPs and not ...
    (Security-Basics)
  • Re: Cannot simultaneously share DSL connection
    ... Did you typed the ID and PW of the Internet provider into the WAN DSL ... Computer 2: Nancy ... Target Nancy ... "DIANNE ping Nancy" ...
    (microsoft.public.windowsxp.network_web)
  • Re: CE 6.0 Networking Problems
    ... Paul T. ... Also, if I'm pinging from my PC, and then go to my target and ping my host ... Perhaps it's a timing issue in the driver? ...
    (microsoft.public.windowsce.embedded)