diff options
author | Gentoo <installgentoo@endianness.com> | 2022-08-30 23:49:38 +1000 |
---|---|---|
committer | Gentoo <installgentoo@endianness.com> | 2022-08-30 23:49:38 +1000 |
commit | 9bb6b8641a8001b2de1a2956d1aa6bb5b46aa10b (patch) | |
tree | eacea837b68144186f3e7ec1940bee2ca52ad293 | |
parent | 62ea38296b6a2782efc102ab736ef1ff1637bff7 (diff) | |
download | tcp-server-master.tar.gz tcp-server-master.tar.bz2 tcp-server-master.zip |
-rw-r--r-- | LICENSE (renamed from LICENCE) | 0 | ||||
-rw-r--r-- | main.c | 14 |
2 files changed, 10 insertions, 4 deletions
@@ -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");} |