I am using TCP / IP through ActiveSync to connect from a Windows CE device to a Windows XP desktop. The WinSock connect () function always succeeds, regardless of whether the desktop server application is running.
The following simplified code demonstrates this problem:
#include "stdafx.h"
#include <Winsock2.h>
int _tmain(int argc, _TCHAR* argv[])
{
const int Port = 5555;
const char * HostName = "ppp_peer";
WSADATA wsadata;
if (WSAStartup(MAKEWORD(1, 1), &wsadata) != 0)
return 1;
struct hostent * hp = gethostbyname(HostName);
if (hp == NULL)
return 1;
struct sockaddr_in sockaddr;
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
sockaddr.sin_port = htons(Port);
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == SOCKET_ERROR)
return 1;
int result = connect(sock, (struct sockaddr*)&sockaddr, sizeof(sockaddr));
closesocket(sock);
return 0;
}
This is mistake? If not, what is the correct way to determine if the server is actually on the network? Just try to use the established connection (recv / send data)?
Device: Windows CE 5.0, WinSock 2.2; Desktop: Windows XP, SP3, ActiveSync 4.5.
source
share