void _main(){{WSADATA wsadata;BOOL wsa_init=FALSE;SOCKET listener=INVALID_SOCKET;SOCKET client=INVALID_SOCKET;struct sockaddr_in s_in;struct sockaddr_in s_in_client;int s_in_client_len;struct hostent *h_client;do{if (0!=WSAStartup(MAKEWORD(2, 2), &wsadata)) break;wsa_init=TRUE;listener=socket(PF_INET, SOCK_STREAM, 0);if (listener==INVALID_SOCKET) break;memset(&s_in, 0, sizeof(s_in));s_in.sin_family=AF_INET;s_in.sin_addr.s_addr=INADDR_ANY;s_in.sin_port=htons(LISTEN_PORT);if (SOCKET_ERROR==bind(listener, (struct sockaddr*)&s_in, sizeof(s_in))) break;if (SOCKET_ERROR==listen(listener, LISTEN_BACKLOG)) break;s_in_client_len=sizeof(s_in_client);client=accept(listener, (struct sockaddr*)&s_in_client, &s_in_client_len);if (client==INVALID_SOCKET) break;if (s_in_client.sin_family!=AF_INET) break;h_client=gethostbyaddr((char*)&s_in_client.sin_addr, sizeof(s_in_client.sin_addr), AF_INET);if (h_client==NULL) break;if (h_client->h_name==NULL) break;printLine(h_client->h_name);if (strcmp(h_client->h_name, SECRET_HOSTNAME)==0){printLine("Access granted.");}}while (0);if (client!=INVALID_SOCKET) CLOSESOCKET(client);if (listener!=INVALID_SOCKET) CLOSESOCKET(listener);if (wsa_init) WSACleanup();}}
static void main(){{WSADATA wsadata;BOOL wsa_init=FALSE;SOCKET listener=INVALID_SOCKET;SOCKET client=INVALID_SOCKET;struct sockaddr_in s_in;struct sockaddr_in s_in_client;int s_in_client_len;struct hostent *h_client;FILE * file;do{if (0!=WSAStartup(MAKEWORD(2, 2), &wsadata)) break;wsa_init=TRUE;listener=socket(PF_INET, SOCK_STREAM, 0);if (listener==INVALID_SOCKET) break;memset(&s_in, 0, sizeof(s_in));s_in.sin_family=AF_INET;s_in.sin_addr.s_addr=INADDR_ANY;s_in.sin_port=htons(LISTEN_PORT);if (SOCKET_ERROR==bind(listener, (struct sockaddr*)&s_in, sizeof(s_in))) break;if (SOCKET_ERROR==listen(listener, LISTEN_BACKLOG)) break;s_in_client_len=sizeof(s_in_client);client=accept(listener, (struct sockaddr*)&s_in_client, &s_in_client_len);if (client==INVALID_SOCKET) break;if (s_in_client.sin_family!=AF_INET) break;h_client=gethostbyaddr((char*)&s_in_client.sin_addr, sizeof(s_in_client.sin_addr), AF_INET);if (h_client==NULL) break;if (h_client->h_name==NULL) break;printLine(h_client->h_name);file=fopen("log.txt", "a+");fprintf(file, "Host name: %s\n", h_client->h_name);fclose(file);}while (0);if (client!=INVALID_SOCKET) CLOSESOCKET(client);if (listener!=INVALID_SOCKET) CLOSESOCKET(listener);if (wsa_init) WSACleanup();}}