--- /dev/null
+# C Simple HTTP
+
+A simple HTTP/1.1 server written in C.
+
+## Usage
+
+ Usage:
+ -p <port> | --port <port>
+ --config=<config_file>
+
+## Example
+
+ # Build the project.
+ make c_simple_http
+
+ # Run it with the example config.
+ ./c_simple_http --config=example_config/example.config
+
+ # If port is not specified, the server picks a random port.
+ # This program should print which TCP port it is listening on.
+ # Sometimes the program will fail to rebind to the same port due to how TCP
+ # works. Either wait some time or choose a different port.
+
+ # Access the website.
+ # This assumes the server is hosted on port 3000.
+ curl localhost:3000
return 2;
}
- printf("listening on port: %u\n", args.port);
- printf("config file is: %s\n", args.config_file);
+ printf("Config file is: %s\n", args.config_file);
__attribute__((cleanup(c_simple_http_clean_up_parsed_config)))
C_SIMPLE_HTTP_ParsedConfig parsed_config = c_simple_http_parse_config(
return 1;
}
+ {
+ struct sockaddr_in6 ipv6_addr;
+ memset(&ipv6_addr, 0, sizeof(struct sockaddr_in6));
+ socklen_t size = sizeof(ipv6_addr);
+ int ret = getsockname(tcp_socket, (struct sockaddr*)&ipv6_addr, &size);
+ if (ret == 0) {
+ printf("Listening on port: %u\n", u16_be_swap(ipv6_addr.sin6_port));
+ } else {
+ fprintf(
+ stderr,
+ "WARNING Failed to get info on tcp socket to print port number!\n");
+ }
+ }
+
struct timespec sleep_time;
sleep_time.tv_sec = 0;
sleep_time.tv_nsec = C_SIMPLE_HTTP_SLEEP_NANOS;