spartserv

Simple client and server for the spartan protocol
git clone https://noulin.net/git/spartserv.git
Log | Files | Refs | README

commit 884b7cb6990ea6f568b98ea4cd534d9239ea3789
parent b197dcecdd9ce2ac9aa2b9b90dd4ff52e5a0bd62
Author: Remy Noulin <loader2x@gmail.com>
Date:   Thu,  2 Mar 2023 22:01:19 +0200

print ip on connection error

spartserv.c         | 12 ++++++++----
spartservPrivDrop.c | 12 ++++++++----
2 files changed, 16 insertions(+), 8 deletions(-)

Diffstat:
Mspartserv.c | 12++++++++----
MspartservPrivDrop.c | 12++++++++----
2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/spartserv.c b/spartserv.c @@ -119,12 +119,18 @@ int main(int ac, char **av){ struct timeval timeout; timeout.tv_sec = 10; timeout.tv_usec = 0; + // get YMD HMS date + time_t clk = time(NULL); + struct tm *pClk = localtime(&clk); + strftime(date, sizeof(date), "%Y-%m-%d:%H:%M:%S", pClk); if (setsockopt(mysock, SOL_SOCKET, SO_RCVTIMEO, (void *) &timeout, sizeof(timeout)) < 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); perror("receive timeout failed"); close(mysock); continue; } if (setsockopt(mysock, SOL_SOCKET, SO_SNDTIMEO, (void *) &timeout, sizeof(timeout)) < 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); perror("send timeout failed"); close(mysock); continue; @@ -133,20 +139,18 @@ int main(int ac, char **av){ // new client memset(buf, 0, sizeof(buf)); if ((rval = recv(mysock, buf, sizeof(buf), 0)) < 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); perror("reading message"); close(mysock); continue; } else if (rval == 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); puts("Ending connection"); close(mysock); continue; } - // get YMD HMS date - time_t clk = time(NULL); - struct tm *pClk = localtime(&clk); - strftime(date, sizeof(date), "%Y-%m-%d:%H:%M:%S", pClk); printf("%s %s ",date, inet_ntoa(addr.sin_addr)); // validate request then scan hostname path and content length diff --git a/spartservPrivDrop.c b/spartservPrivDrop.c @@ -355,12 +355,18 @@ int main(int ac, char **av){ struct timeval timeout; timeout.tv_sec = 10; timeout.tv_usec = 0; + // get YMD HMS date + time_t clk = time(NULL); + struct tm *pClk = localtime(&clk); + strftime(date, sizeof(date), "%Y-%m-%d:%H:%M:%S", pClk); if (setsockopt(mysock, SOL_SOCKET, SO_RCVTIMEO, (void *) &timeout, sizeof(timeout)) < 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); perror("receive timeout failed"); close(mysock); continue; } if (setsockopt(mysock, SOL_SOCKET, SO_SNDTIMEO, (void *) &timeout, sizeof(timeout)) < 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); perror("send timeout failed"); close(mysock); continue; @@ -369,20 +375,18 @@ int main(int ac, char **av){ // new client memset(buf, 0, sizeof(buf)); if ((rval = recv(mysock, buf, sizeof(buf), 0)) < 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); perror("reading message"); close(mysock); continue; } else if (rval == 0) { + printf("%s %s ",date, inet_ntoa(addr.sin_addr)); puts("Ending connection"); close(mysock); continue; } - // get YMD HMS date - time_t clk = time(NULL); - struct tm *pClk = localtime(&clk); - strftime(date, sizeof(date), "%Y-%m-%d:%H:%M:%S", pClk); printf("%s %s ",date, inet_ntoa(addr.sin_addr)); // validate request then scan hostname path and content length