Add basic server argparsing
parent
fccf0db890
commit
5e4275ac5b
|
@ -1,5 +1,6 @@
|
|||
#include "http_client.h"
|
||||
#include "../common/http_types.h"
|
||||
#include "../common/socket_helper.h"
|
||||
#include "http_socket.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#include <time.h>
|
||||
|
||||
#define HTTP_VERSION "HTTP/1.1"
|
||||
#define MIN_PORT 1
|
||||
#define MAX_PORT 65535
|
||||
|
||||
struct response_info {
|
||||
char *contents;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "http_types.h"
|
||||
|
||||
#define MIN_PORT 1
|
||||
#define MAX_PORT 65535
|
||||
#define BUFFER_SIZE 1024
|
||||
#define HEADER_CONTENT_LENGTH "Content-Length"
|
||||
#define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#include "http_server.h"
|
||||
#include "../common/socket_helper.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
printf("%s", USAGE_STRING);
|
||||
}
|
||||
char *port = argv[1];
|
||||
long port_num = strtol(port, NULL, 10);
|
||||
if (port_num < MIN_PORT || port_num > MAX_PORT || errno == ERANGE || errno == EINVAL) {
|
||||
printf("%s", PORT_ERROR);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef HTTP_SERVER_H
|
||||
#define HTTP_SERVER_H
|
||||
|
||||
#define USAGE_STRING "Usage: ./http_server port"
|
||||
#define PORT_ERROR "Port must be a number in the range 1-65535"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue