Probably the strangest mistake I have encountered so far.
I need to connect to a third-party application running Windows XP Embedded. A network connection is present and working: I can connect to the expected port using PuTTY running on Windows XP SP3 and perform some operations like telnet. Now my application is a very simple C program (VC ++ 2008):
int _tmain(int argc, _TCHAR* argv[]) { WSADATA wsaData = { 0 }; if (SOCKET_ERROR == WSAStartup(MAKEWORD(2, 0), &wsaData)) return Error("Failed to initialize sockets."); SOCKET client = INVALID_SOCKET; const char *pserver = "172.22.1.3"; client = socket(AF_INET, SOCK_STREAM, 0); if (INVALID_SOCKET != client) { sockaddr_in s = { 0 }; s.sin_family = AF_INET; s.sin_port = htons(4799); hostent *e = gethostbyname(pserver); memmove(&s.sin_addr, e->h_addr, e->h_length); std::cout << "Connecting to: " << pserver << std::endl; if (SOCKET_ERROR != connect(client, (sockaddr*)&s, sizeof(s))) { std::cout << "Successfully connected." << std::endl; } else std::cout << "Can't connect: " << WSAGetLastError() << std::endl; } getchar(); if (INVALID_SOCKET != client) closesocket(client); return 0; }
Every time I compile and run this program, I get a WSAETIMEDOUT error. Puzzled, I started digging deeper and released two Wireshark dumps on the receiver side - one with PuTTY and the other with my application running from the same computer and connecting to the same equipment (first SYN packages below).
PuTTY:
No. Time Source Destination Protocol Info 1 0.000000 172.22.1.61 172.22.1.3 TCP atc-lm > 4799 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=0 TSV=0 TSER=0 Frame 1 (78 bytes on wire, 78 bytes captured) Ethernet II, Src: Dell_b8:4a:31 (00:26:b9:b8:4a:31), Dst: EEPD_96:04:48 (00:e0:33:96:04:48) Internet Protocol, Src: 172.22.1.61 (172.22.1.61), Dst: 172.22.1.3 (172.22.1.3) Transmission Control Protocol, Src Port: atc-lm (1170), Dst Port: 4799 (4799), Seq: 0, Len: 0 0000 00 e0 33 96 04 48 00 26 b9 b8 4a 31 08 00 45 00 ..3..H.&..J1..E. 0010 00 40 04 a1 40 00 80 06 9b aa ac 16 01 3d ac 16 .@.. @........=.. 0020 01 03 04 92 12 bf 9a 99 fc ec 00 00 00 00 b0 02 ................ 0030 ff ff 2c bd 00 00 02 04 05 b4 01 03 03 00 01 01 ..,............. 0040 08 0a 00 00 00 00 00 00 00 00 01 01 04 02 ..............
My application:
No. Time Source Destination Protocol Info 1 0.000000 Dell_b8:4a:31 EEPD_96:04:48 FC [Malformed Packet] Frame 1 (78 bytes on wire, 78 bytes captured) Ethernet II, Src: Dell_b8:4a:31 (00:26:b9:b8:4a:31), Dst: EEPD_96:04:48 (00:e0:33:96:04:48) MDS Header(Unknown(0)/Unknown(0)) [Malformed Packet: FC] 0000 00 e0 33 96 04 48 00 26 b9 b8 4a 31 00 00 00 00 ..3..H.&..J1.... 0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0020 00 00 00 00 00 00 00 00 6d 8b 00 00 00 00 b0 02 ........m....... 0030 ff ff 90 73 00 00 02 04 05 b4 01 03 03 00 01 01 ...s............ 0040 08 0a 00 00 00 00 00 00 00 00 01 01 04 02 ..............
Basically, all IP payload is destroyed with 0x00 instead of valid bytes.
Now comes the strangest part. I wrote a similar program for .NET 3.5:
static void Main(string[] args) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified); socket.Connect("172.22.1.3", 4799); Console.WriteLine("Connected"); Console.ReadLine(); socket.Disconnect(true); }
The same PC with Windows XP SP3, the same network connection - my .NET application just connects to the remote application! Moreover, my original C application works fine from another laptop under Windows 7 x64. After the daytime clamp, I have two Windows XP SP3 laptops with which my C application does not connect to the remote client, and one Windows XP SP3 and one Windows 7 x64 laptop, where my C application works without any problems.
My first guess was network drivers, but PuTTY and .NET applications just work on the same laptop!
If someone could hide something and could advise me?
Thanks.