Added net.h
This commit is contained in:
parent
dbad87a94e
commit
1828c99094
7 changed files with 54 additions and 52 deletions
|
@ -9,9 +9,9 @@ set(SOURCE_FILES modules/peer.h modules/peer.c utility.c utility.h modules/webio
|
|||
option(BUILD_DOC "Build Documentation" ON)
|
||||
|
||||
|
||||
add_executable(p2p main.c modules/peer.h modules/peer.c utility.c utility.h modules/webio.h modules/webio.c modules/config.h modules/config.c lib/map.h lib/map.c lib/tcp-listener.c lib/tcp-listener.h)
|
||||
add_executable(p2p-2 main.c modules/peer.h modules/peer.c utility.c utility.h modules/webio.h modules/webio.c modules/config.h modules/config.c lib/map.h lib/map.c lib/tcp-listener.c lib/tcp-listener.h)
|
||||
add_executable(p2p-3 main.c modules/peer.h modules/peer.c utility.c utility.h modules/webio.h modules/webio.c modules/config.h modules/config.c lib/map.h lib/map.c lib/tcp-listener.c lib/tcp-listener.h)
|
||||
add_executable(p2p main.c modules/peer.h modules/peer.c utility.c utility.h modules/webio.h modules/webio.c modules/config.h modules/config.c lib/map.h lib/map.c lib/tcp-listener.c lib/tcp-listener.h lib/net.h)
|
||||
add_executable(p2p-2 main.c modules/peer.h modules/peer.c utility.c utility.h modules/webio.h modules/webio.c modules/config.h modules/config.c lib/map.h lib/map.c lib/tcp-listener.c lib/tcp-listener.h lib/net.h)
|
||||
add_executable(p2p-3 main.c modules/peer.h modules/peer.c utility.c utility.h modules/webio.h modules/webio.c modules/config.h modules/config.c lib/map.h lib/map.c lib/tcp-listener.c lib/tcp-listener.h lib/net.h)
|
||||
set_target_properties( p2p-2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/p2p-2 )
|
||||
set_target_properties( p2p-3 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/p2p-3 )
|
||||
# Függvények kipróbálására hoztam létre
|
||||
|
|
27
lib/net.h
Normal file
27
lib/net.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Keszitette: Toldi Balázs Ádám
|
||||
// Datum: 2019. 11. 05.
|
||||
//
|
||||
#pragma once
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
//Winsock2 kompatiblitás érdekében
|
||||
#ifndef SOCKET_ERROR
|
||||
#define SOCKET_ERROR -1
|
||||
#endif
|
||||
#ifndef INVALID_SOCKET
|
||||
#define INVALID_SOCKET -1
|
||||
#endif
|
||||
//Ez winsock2-ben definiálva van (ott elvileg unsigned long long int-ként)
|
||||
typedef int SOCKET;
|
||||
#elif _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
16
main.c
16
main.c
|
@ -3,7 +3,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#include "modules/peer.h"
|
||||
#include "modules/webio.h"
|
||||
#include "modules/config.h"
|
||||
|
@ -11,15 +10,6 @@
|
|||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
#ifdef RANDOM_PORT
|
||||
#define DEFAULT_PORT "0"
|
||||
#else
|
||||
#define DEFAULT_PORT "6327"
|
||||
#endif
|
||||
#define DEFAULT_INTERFACE_PORT "5081"
|
||||
#define DEFAULT_WWW_FOLDER "htdocs/"
|
||||
|
||||
|
||||
int main(void) {
|
||||
Map config = config_load();
|
||||
|
||||
|
@ -121,12 +111,6 @@ int main(void) {
|
|||
|
||||
logger_log("Started web interface at http://127.0.0.1:%d", tcp_getSockPort(webIo.socket));
|
||||
|
||||
|
||||
char *command = (char *) malloc(64);
|
||||
sprintf(command, "start http://127.0.0.1:%d/", tcp_getSockPort(webIo.socket));
|
||||
system(command);
|
||||
free(command);
|
||||
|
||||
logger_log("Starting main loop...");
|
||||
bool run = true;
|
||||
while (run) {
|
||||
|
|
|
@ -8,7 +8,7 @@ Config config_load(){
|
|||
Config cfg;
|
||||
map_init(&cfg);
|
||||
FILE * f;
|
||||
f = fopen("Config.ini","r");
|
||||
f = fopen("config.ini","r");
|
||||
if(f != NULL) {
|
||||
char buf[256], key[65], value[65];
|
||||
while (fgets(buf, sizeof(buf), f) != NULL)
|
||||
|
@ -22,20 +22,20 @@ Config config_load(){
|
|||
}
|
||||
}else{
|
||||
|
||||
char* exampleConf= "#Becenév\n"
|
||||
|
||||
f = fopen("config.ini","w");
|
||||
fprintf(f,"#Becenév\n"
|
||||
"#nickname=Pelda\n"
|
||||
"#A program által használt port (Alapértelmezett: 6381)\n"
|
||||
"port=6327\n"
|
||||
"#A program által használt port (Alapértelmezett: %s)\n"
|
||||
"port=%s\n"
|
||||
"#Letiltja a külső csatlakozást (Alapértelmezett: false)\n"
|
||||
"localmode=false\n"
|
||||
"#Ezne a porton lesz elérhető a felhasználói felület (Alapértelmezett: 5381)\n"
|
||||
"interface-port=5381\n"
|
||||
"#Ebben a mappában vannak tárolva a html fájlok a felhasználói felülethez (Alapértelmezett: htdocs/)\n"
|
||||
"interface-folder=htdocs/\n"
|
||||
"#Ezne a porton lesz elérhető a felhasználói felület (Alapértelmezett: %s)\n"
|
||||
"interface-port=%s\n"
|
||||
"#Ebben a mappában vannak tárolva a html fájlok a felhasználói felülethez (Alapértelmezett: %s)\n"
|
||||
"interface-folder=%s\n"
|
||||
"#A felhasználói felület csak ezen a gépen érhető elő (Alapértelmezett: true;Ajánlott)\n"
|
||||
"interface-local=true" ;
|
||||
f = fopen("Config.ini","w");
|
||||
fprintf(f,exampleConf);
|
||||
"interface-local=true",DEFAULT_PORT,DEFAULT_PORT,DEFAULT_INTERFACE_PORT,DEFAULT_INTERFACE_PORT,DEFAULT_WWW_FOLDER,DEFAULT_WWW_FOLDER);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
#pragma once
|
||||
#include "../utility.h"
|
||||
#include "../lib/map.h"
|
||||
|
||||
#ifdef RANDOM_PORT
|
||||
#define DEFAULT_PORT "0"
|
||||
#else
|
||||
#define DEFAULT_PORT "6327"
|
||||
#endif
|
||||
#define DEFAULT_INTERFACE_PORT "5081"
|
||||
#define DEFAULT_WWW_FOLDER "htdocs/"
|
||||
|
||||
Config config_load();
|
||||
|
|
17
utility.h
17
utility.h
|
@ -5,6 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "lib/map.h"
|
||||
#include "lib/net.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -12,23 +13,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#ifndef SOCKET_ERROR
|
||||
#define SOCKET_ERROR -1
|
||||
#endif
|
||||
#ifndef INVALID_SOCKET
|
||||
#define INVALID_SOCKET -1
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
|
||||
//! (MAXIMUM) Ekkora mérető csomagokat küld el a program alapértelmezetten.
|
||||
#define DEFAULT_BUFLEN 4096
|
||||
|
|
Loading…
Reference in a new issue