Initial
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||||
|
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
|
||||||
|
{
|
||||||
|
"name": "Ubuntu",
|
||||||
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/base:noble"
|
||||||
|
|
||||||
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
|
// "features": {},
|
||||||
|
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
// "forwardPorts": [],
|
||||||
|
|
||||||
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
|
// "postCreateCommand": "uname -a",
|
||||||
|
|
||||||
|
// Configure tool-specific properties.
|
||||||
|
// "customizations": {},
|
||||||
|
|
||||||
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
|
// "remoteUser": "root"
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
## cos440-fp ##
|
## cos440-fp ##
|
||||||
|
|
||||||
[](https://gitea-actions.nicholaspease.com/latest-log?branch=main)
|
[](https://gitea-actions.nicholaspease.com/latest-log?branch=main)
|
||||||
[](https://drone.nicholaspease.com/umaine-npease/cos440-fp)
|
[](https://drone.nicholaspease.com/umaine-npease/cos440-fp)
|
||||||
[](https://wakaapi.nicholaspease.com/summary?interval=any&project=cos440-fp)
|
[](https://wakaapi.nicholaspease.com/summary?interval=any&project=cos440-fp)
|
||||||

|

|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
Final Project - Part 1
|
||||||
|
Nicholas Pease
|
||||||
|
COS440
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
#define PORT 5000
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
|
// Globals
|
||||||
|
|
||||||
|
// Structs
|
||||||
|
struct http_start_line {
|
||||||
|
char method[8];
|
||||||
|
char path[1024];
|
||||||
|
char version[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct http_header {
|
||||||
|
char field_name[256];
|
||||||
|
char field_value[1024];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct http_message {
|
||||||
|
struct http_start_line start_line;
|
||||||
|
struct http_header headers[100];
|
||||||
|
char body[8192];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
struct http_message create_http_message_from_string(char *message_str) {
|
||||||
|
struct http_message message;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
// Setup TCP Socket
|
||||||
|
if (DEBUG) printf("SETUP: Setup Sockets\n");
|
||||||
|
int serv_sock, client_sock, read_size;
|
||||||
|
struct sockaddr_in server, client;
|
||||||
|
char client_message[20000];
|
||||||
|
serv_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
client_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (DEBUG) printf("SETUP: Socket Created\n");
|
||||||
|
|
||||||
|
// Bind Sockets
|
||||||
|
server.sin_family = AF_INET;
|
||||||
|
server.sin_port = htons(PORT);
|
||||||
|
// inet_pton(AF_INET, INADDR_ANY, &(server.sin_addr));
|
||||||
|
bind(serv_sock,(struct sockaddr *)&server, sizeof(server));
|
||||||
|
if (DEBUG) printf("SETUP: Socket Bound\n");
|
||||||
|
|
||||||
|
// Start Listening and Waiting for Connections
|
||||||
|
listen(serv_sock, 1);
|
||||||
|
if (DEBUG) printf("SETUP: Listening for Connections\n\n");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
// Accept Connection from Client
|
||||||
|
if (DEBUG) printf("WAIT: Waiting for incoming connections...\n");
|
||||||
|
int c = sizeof(struct sockaddr_in);
|
||||||
|
client_sock = accept(serv_sock, (struct sockaddr *)&client, &c);
|
||||||
|
if (DEBUG) printf("CONNECT: Connection Accepted\n");
|
||||||
|
|
||||||
|
// Receive Message from Client
|
||||||
|
memset(client_message, 0, sizeof(client_message));
|
||||||
|
read_size = recv(client_sock, client_message, sizeof(client_message), 0);
|
||||||
|
if (DEBUG) printf("RECEIVE: Message Received\n");
|
||||||
|
|
||||||
|
// Process Message From Client
|
||||||
|
if (DEBUG) printf("PROCESS: Processing Message\n");
|
||||||
|
struct http_message message = create_http_message_from_string(client_message);
|
||||||
|
|
||||||
|
// Close Client Socket
|
||||||
|
close(client_sock);
|
||||||
|
if (DEBUG) printf("DISCONNECT: Client Disconnected\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user