handle_request(char *req, struct sockaddr_in *client, socklen_t addlen){ fprintf(stderr, "In handle_request\n"); fflush(stderr); char *response; int ret; if(strncmp(req, "HELO", 4) == 0) response = do_hello(req); else if(strncmp(req, "GBYE", 4) == 0) response = do_goodbye(req); else response = "FAIL invalid request"; narrate("SAID:", response, client); ret = sendto(sd, response, strlen(response), 0, client, addlen); if(ret == -1) perror("SERVER sendto failed"); }
/* handle_request(request, clientaddr, addrlen) * branch on code in request */ handle_request(char *req, struct sockaddr_in *client, socklen_t addlen) { char *response; int ret; /* act and compose a response */ if (strncmp(req, "HELO", 4) == 0) response = do_hello(req); else if(strncmp(req, "GBYE", 4) == 0) response = do_goodbye(req); else response = "FAIL invalid request"; /* send the response to the client */ narrate("SAID:", response, client); ret = sendto(sd, response, strlen(response), 0, client, addlen); if (ret == -1) perror("SERVER sendto failed"); }