push
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
ls
|
||||||
|
help
|
||||||
|
running
|
||||||
|
help app
|
||||||
|
help all
|
||||||
|
tdump
|
||||||
|
tdump ./main
|
||||||
|
exit
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#include "server/server.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int server_socket, client_socket;
|
||||||
|
struct sockaddr_in server_addr, client_addr;
|
||||||
|
socklen_t addr_len = sizeof(client_addr);
|
||||||
|
|
||||||
|
// Create socket
|
||||||
|
server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (server_socket == -1) {
|
||||||
|
perror("Socket creation failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up server address
|
||||||
|
memset(&server_addr, 0, sizeof(server_addr));
|
||||||
|
server_addr.sin_family = AF_INET;
|
||||||
|
server_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
server_addr.sin_port = htons(PORT);
|
||||||
|
|
||||||
|
// Bind socket
|
||||||
|
if (bind(server_socket, (struct sockaddr *)&server_addr,
|
||||||
|
sizeof(server_addr)) < 0) {
|
||||||
|
perror("Bind failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Listen for connections
|
||||||
|
if (listen(server_socket, 10) < 0) {
|
||||||
|
perror("Listen failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Server listening on port %d\n", PORT);
|
||||||
|
|
||||||
|
// Accept and handle clients
|
||||||
|
while (1) {
|
||||||
|
client_socket =
|
||||||
|
accept(server_socket, (struct sockaddr *)&client_addr, &addr_len);
|
||||||
|
if (client_socket < 0) {
|
||||||
|
perror("Accept failed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf("Accepted connection from %s:%d\n", inet_ntoa(client_addr.sin_addr),
|
||||||
|
ntohs(client_addr.sin_port));
|
||||||
|
handle_client(client_socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(server_socket);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
global .text
|
||||||
|
|
||||||
|
_start
|
||||||
|
mov eax, 70
|
||||||
|
|
||||||
|
jp carry_set
|
||||||
|
carry_set
|
||||||
|
mov bx, 66
|
||||||
|
syscall
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include "server.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void handle_client(int client_socket, const char *uri) {
|
||||||
|
char buffer[1024];
|
||||||
|
char path[256] = "./public";
|
||||||
|
|
||||||
|
if (strcmp(uri, "/") == 0) {
|
||||||
|
strcat(path, "/index.html");
|
||||||
|
} else {
|
||||||
|
strcat(path, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *f = fopen(path, "rb");
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
|
char *response = "HTTP/1.1 404 Not Found\r\OK\r\nContent-Length: 0\r\n\r\n";
|
||||||
|
send(client_socket, response, strlen(response), 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
stat(path, &st);
|
||||||
|
long file_size = st.st_size;
|
||||||
|
|
||||||
|
recv(client_socket, buffer, 1024, 0);
|
||||||
|
|
||||||
|
char *response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello "
|
||||||
|
"from server 8080 localhost!";
|
||||||
|
send(client_socket, response, strlen(response), 0);
|
||||||
|
|
||||||
|
// Close the socket
|
||||||
|
close(client_socket);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define PORT 8080
|
||||||
|
|
||||||
|
#define INDEX \
|
||||||
|
"/" \
|
||||||
|
"index.html"
|
||||||
|
|
||||||
|
void handle_client(int client_socket);
|
||||||
Reference in New Issue
Block a user