summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGentoo <installgentoo@endianness.com>2022-08-30 23:49:38 +1000
committerGentoo <installgentoo@endianness.com>2022-08-30 23:49:38 +1000
commit9bb6b8641a8001b2de1a2956d1aa6bb5b46aa10b (patch)
treeeacea837b68144186f3e7ec1940bee2ca52ad293
parent62ea38296b6a2782efc102ab736ef1ff1637bff7 (diff)
downloadtcp-server-9bb6b8641a8001b2de1a2956d1aa6bb5b46aa10b.tar.gz
tcp-server-9bb6b8641a8001b2de1a2956d1aa6bb5b46aa10b.tar.bz2
tcp-server-9bb6b8641a8001b2de1a2956d1aa6bb5b46aa10b.zip
added license headerHEADmaster
-rw-r--r--LICENSE (renamed from LICENCE)0
-rw-r--r--main.c14
2 files changed, 10 insertions, 4 deletions
diff --git a/LICENCE b/LICENSE
index f288702..f288702 100644
--- a/LICENCE
+++ b/LICENSE
diff --git a/main.c b/main.c
index ef7c6c3..23ce6cc 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,9 @@
-//A poor tcp server that works somewhat
-//Note: Due to the usage of sockets and pipes in a single thread, this application will block at each read/write. (e.g. until output.pipe is cleared, the next read() won't commence)
+/* Copyright (C) 2022 Gentoo-libre Install
+ License: GPLv3+
+ A poor tcp server that works somewhat
+ Note: Due to the usage of sockets and pipes in a single thread, this application will block at each read/write. (e.g. until output.pipe is cleared, the next read() won't commence)
+*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -13,7 +17,8 @@
#include <sys/ioctl.h> //for ioctl
#include <linux/sockios.h>//for ioctl
#define READCHAR 80 //amount of bytes to read at once
-#define PORT 2525
+//#define PORT 2525
+#define PORT 53
#define SA struct sockaddr
#define INPUTPIPE "/tmp/input.pipe"
#define OUTPUTPIPE "/tmp/output.pipe"
@@ -97,9 +102,10 @@ bzero(&servaddr, sizeof(servaddr));
//assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+//servaddr.sin_addr.s_addr = inet_addr("0.0.0.0");
servaddr.sin_port = htons(PORT);
-//With linux, by default, even after a socket is closed properly, it can't be used again for a minute or two. Using setsockopt() with SO_REUSEADDR can be used to stop this though. There is one drawback: there is no longer anything preventing multiple processes binding to the same socket. (Only one can actually use the socket, the rest are binded and any reads and writes will fail.
+//With Linux, by default, even after a socket is closed properly, it can't be used again for a minute or two. Using setsockopt() with SO_REUSEADDR can be used to stop this though. There is one drawback: there is no longer anything preventing multiple processes binding to the same socket. (Only one can actually use the socket, the rest are binded and any reads and writes will fail.
int reuse = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0){printf("setsockopt(SO_REUSEADDR) failed!\n");}