From 2bf4539966bde0191c75782c6b05509321b06ade Mon Sep 17 00:00:00 2001 From: verdant Date: Tue, 9 Jun 2026 18:23:44 +0800 Subject: Print usage when no argument The program needs a argument to specific which port it works on. --- server.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server.c b/server.c index dbdaa67..fdc8724 100644 --- a/server.c +++ b/server.c @@ -13,6 +13,12 @@ typedef enum { GET = 0, POST = 1, UNKNOWN = -1 } HTTP_METHODS; +static void usage(const char *progname) +{ + fprintf(stderr, "Usage: %s \n", progname); + exit(EXIT_FAILURE); +} + int shsd_sendfile(int in_fd, FILE *ou_fd) { struct stat s; @@ -81,6 +87,9 @@ int handle_client(int client_fd, char *buf) int main(int argc, char **argv) { + if (argc < 2) { + usage(argv[0]); + } struct addrinfo hints, *res; struct sockaddr_storage their_addr; socklen_t addr_size; -- cgit v1.2.3