Now that we've worked out our program's functionality, we can begin on the networked version of the same program.
To begin with, we include the needed headers:
/*time_server.c*/#if defined(_WIN32)#ifndef _WIN32_WINNT#define _WIN32_WINNT 0x0600#endif#include <winsock2.h>#include <ws2tcpip.h>#pragma comment(lib, "ws2_32.lib")#else#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <unistd.h>#include <errno.h>#endif
As we discussed earlier, this detects if the compiler is running on Windows or not and includes the proper headers for the platform it is running on.
We also define some macros, which abstract out some of the difference between the Berkeley socket ...