I was playing around with a small piece of code that queries port 37 on host 22.214.171.124 to get the date and time. It consistently gives me back 3435973836. Doing the conversion, that's roughly 108.8 years after January 1, 1900 (the epoch). For today, I would have expected a number close to 3461794781. Questions: 1) why would I keep getting the same number, and 2) why is it not the right number?
// error checking has been omitted for brevity
SOCKET rSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
unsigned long ul = 1;
ioctlsocket(rSocket, FIONBIO, &ul);
rSocketAddr.sin_family = AF_INET;
rSocketAddr.sin_addr.s_addr = inet_addr("126.96.36.199");
rSocketAddr.sin_port = htons(37);
connect(rSocket, (LPSOCKADDR) &rSocketAddr, sizeof(rSocketAddr));
unsigned int nData = 0;
recv(rSocket, (char *) &nData, sizeof(nData), 0); // returns 4 bytes read
Update: initializing nData to 0 answers the questions as to why recv() was consistently assigning 3435973836 to nData. After a few more rounds of testing, the culprit looks to be the call to ioctlsocket() which made the socket non-blocking.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons