Compare commits
No commits in common. "ce081c07809eb0b15e1cf7e83e955894dc597889" and "5d3dda1df62d9b256a53356e155e3586e8f8d336" have entirely different histories.
ce081c0780
...
5d3dda1df6
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,4 +35,3 @@
|
||||
# Extras
|
||||
build
|
||||
test/web_server
|
||||
.vscode
|
||||
|
@ -8,7 +8,3 @@ add_executable(web_server
|
||||
./network.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(proxy wsock32 ws2_32)
|
||||
target_link_libraries(web_server wsock32 ws2_32)
|
||||
endif()
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "network.hpp"
|
||||
#ifdef UNIX
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h> // Needed for exit()
|
||||
#include <cstring>
|
||||
@ -37,14 +35,8 @@ void PipeSockets(int sender_s, int receiver_s) {
|
||||
send(sender_s, in_buf, strlen(in_buf), 0);
|
||||
strcpy(in_buf, MESS_403);
|
||||
send(sender_s, in_buf, strlen(in_buf), 0);
|
||||
#ifdef WIN
|
||||
closesocket(sender_s);
|
||||
closesocket(receiver_s);
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
close(sender_s);
|
||||
close(receiver_s);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,14 +72,8 @@ void ProxySockets(int sender_s, int receiver_s) {
|
||||
send(receiver_s, out_buf, strlen(out_buf), 0);
|
||||
strcpy(out_buf, MESS_403);
|
||||
send(receiver_s, out_buf, strlen(out_buf), 0);
|
||||
#ifdef WIN
|
||||
closesocket(sender_s);
|
||||
closesocket(receiver_s);
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
close(sender_s);
|
||||
close(receiver_s);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,14 +83,8 @@ void ProxySockets(int sender_s, int receiver_s) {
|
||||
std::cout << "LOG (info) - proxy packet send size: " << buf_len << '\n';
|
||||
} while ((buf_len == BUF_SIZE) || (buf_len == 40));
|
||||
std::cout << "Sent to browser" << std::endl;
|
||||
#ifdef WIN
|
||||
closesocket(sender_s);
|
||||
closesocket(receiver_s);
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
close(sender_s);
|
||||
close(receiver_s);
|
||||
#endif
|
||||
}
|
||||
|
||||
Client::Client(void) {
|
||||
@ -136,13 +116,9 @@ bool Client::ConnectTo(int portNumber) {
|
||||
|
||||
Server::Server(int portNumber) {
|
||||
std::cout << "Opening the server" << std::endl;
|
||||
#ifdef WIN
|
||||
socketFD = socket(AF_INET, SOCK_STREAM, 0);
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
socketFD = socket(AF_INET, SOCK_STREAM, 0);
|
||||
#endif
|
||||
if (socketFD == -1) {
|
||||
if (socketFD == -1)
|
||||
{
|
||||
std::cerr << "ERROR - Unable to create socket on server" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
@ -150,7 +126,8 @@ Server::Server(int portNumber) {
|
||||
address.sin_port = htons(portNumber);
|
||||
address.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
// Create a socket, fill-in address information, and then bind it
|
||||
if (bind(socketFD, (struct sockaddr *)&address, sizeof(address)) == -1) {
|
||||
if (bind(socketFD, (struct sockaddr *)&address, sizeof(address)) == -1)
|
||||
{
|
||||
std::cerr << "ERROR - Unable to bind socket" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
@ -161,11 +138,5 @@ Server::Server(int portNumber) {
|
||||
|
||||
void Server::Close(void) {
|
||||
std::cout << "Closing the server" << std::endl;
|
||||
#ifdef WIN
|
||||
closesocket(socketFD);
|
||||
WSACleanup();
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
close(socketFD);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,15 +1,7 @@
|
||||
#ifndef NETWORK_HPP
|
||||
#define NETWORK_HPP
|
||||
|
||||
#define WIN // WIN for Windows environment, UNIX for BSD or LINUX env.
|
||||
|
||||
#ifdef UNIX
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef WIN
|
||||
#include <winsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#define BUF_SIZE 4096 // Buffer size (big enough for a GET)
|
||||
|
@ -8,18 +8,6 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* FOR WIN ------------------------------------------------------------- */
|
||||
#ifdef WIN
|
||||
WORD wVersionRequested = MAKEWORD(1, 1); // Stuff for WSA functions
|
||||
WSADATA wsaData;
|
||||
int wsResult; // Stuff for WSA functions
|
||||
wsResult = WSAStartup(wVersionRequested, &wsaData);
|
||||
if (wsResult != 0) {
|
||||
printf("WSAStartup failed: %d\n", wsResult);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
/* --------------------------------------------------------------------- */
|
||||
strcpy(hazardous_contents_CS_01, "password.txt");
|
||||
strcpy(hazardous_contents_CS_02, "admin.config");
|
||||
std::vector<std::future<void>> pending_futures;
|
||||
|
@ -28,6 +28,7 @@
|
||||
//= History: KJC (12/29/00) - Genesis (from server.c) =
|
||||
//= HF (01/25/01) - Ported to multi-platform environment =
|
||||
//=============================================================================
|
||||
#define UNIX // WIN for Windows environment, UNIX for BSD or LINUX env.
|
||||
|
||||
//----- Include files ---------------------------------------------------------
|
||||
#include <string.h> // Needed for strcpy() and strlen()
|
||||
@ -50,7 +51,13 @@
|
||||
|
||||
/* FOR WIN ---------------------------------------------------------------- */
|
||||
#ifdef WIN
|
||||
#include <stddef.h> // Needed for _threadid
|
||||
#include <process.h> // Needed for _beginthread() and _endthread()
|
||||
#include <io.h> // Needed for open(), close(), and eof()
|
||||
#include <winsock2.h>
|
||||
#include <windows.h> // Needed for all Winsock stuff
|
||||
// Lazy struct fixes
|
||||
typedef int32_t socklen_t;
|
||||
#endif
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@ -75,13 +82,18 @@ int main(void)
|
||||
#ifdef WIN
|
||||
WORD wVersionRequested = MAKEWORD(1, 1); // Stuff for WSA functions
|
||||
WSADATA wsaData; // Stuff for WSA functions
|
||||
WSAStartup(wVersionRequested, &wsaData);
|
||||
#endif
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
std::vector<std::future<void>> pending_futures;
|
||||
Server webserver(kWebserverPort);
|
||||
Client proxy;
|
||||
/* FOR WIN ------------------------------------------------------------- */
|
||||
#ifdef WIN
|
||||
// Initialize winsock
|
||||
WSAStartup(wVersionRequested, &wsaData);
|
||||
#endif
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
// Main loop to listen, accept, and then spin-off a thread to handle the GET
|
||||
while (1)
|
||||
@ -156,19 +168,9 @@ void ClientRequest(int client_s) {
|
||||
std::cout << "LOG (info) - webserver send size: " << buf_len << '\n';
|
||||
} while (buf_len == BUF_SIZE);
|
||||
std::cout << std::endl;
|
||||
#ifdef WIN
|
||||
closesocket(fh);
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
close(fh);
|
||||
#endif
|
||||
}
|
||||
// Close the client socket and end the thread
|
||||
#ifdef WIN
|
||||
closesocket(client_s);
|
||||
#endif
|
||||
#ifdef UNIX
|
||||
close(client_s);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user