#include #include #include #include #include #include #include void handle_arguments(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s QUERRY\n", argv[0]); exit(EXIT_FAILURE); } if (strlen(argv[1]) > 100) { fprintf(stderr, "QUERRY must not exceed 100 characters!\n"); exit(EXIT_FAILURE); } } void run_client(char *msg) { int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { fprintf(stderr, "socket: "); exit(EXIT_FAILURE); } struct sockaddr_in serv_addr; memset(&serv_addr, 0, sizeof(serv_addr)); //Clears the memory serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(2137); serv_addr.sin_addr.s_addr = INADDR_ANY; int rv = sendto(sockfd, msg, strlen(msg), 0, (const struct sockaddr *)&serv_addr, sizeof(serv_addr)); if (rv < 0) { fprintf(stderr, "sendto: "); exit(EXIT_FAILURE); } char response[100]; //rv = recvfrom(sockfd, response, sizeof(response), 0, NULL, NULL); } int main(int argc, char *argv[]) { handle_arguments(argc, argv); run_client(argv[1]); return 0; }