Introduction
Introduction Statistics Contact Development Disclaimer Help
Improve tcp connexion logging - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit 42ed4146e6040a362e67369d862daabff0a01f4b
parent eaa890e1ff66d546a86e66dda6ea5c71a239a2df
Author: Quentin Rameau <[email protected]>
Date: Fri, 16 Jun 2017 18:07:23 +0200
Improve tcp connexion logging
Log events when bound to an ip or when it fails, and when a client
disconnects.
Signed-off-by: Christoph Lohmann <[email protected]>
Diffstat:
M main.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/main.c b/main.c
@@ -22,6 +22,7 @@
#include <pwd.h>
#include <grp.h>
#include <errno.h>
+#include <arpa/inet.h>
#include "ind.h"
#include "handlr.h"
@@ -266,7 +267,9 @@ initsignals(void)
int
getlistenfd(struct addrinfo *hints, char *bindip, char *port)
{
+ char addstr[INET6_ADDRSTRLEN];
struct addrinfo *ai, *rp;
+ void *sinaddr;
int on, listfd;
listfd = -1;
@@ -286,9 +289,21 @@ getlistenfd(struct addrinfo *hints, char *bindip, char *po…
sizeof(on)) < 0) {
break;
}
- if(bind(listfd, rp->ai_addr, rp->ai_addrlen) == 0)
+
+ sinaddr = (rp->ai_family == AF_INET) ?
+ (void *)&((struct sockaddr_in *)rp->ai_addr)->sin_ad…
+ (void *)&((struct sockaddr_in6 *)rp->ai_addr)->sin6_…
+
+ if(bind(listfd, rp->ai_addr, rp->ai_addrlen) == 0) {
+ if(loglvl & CONN && inet_ntop(rp->ai_family, sinaddr,
+ addstr, sizeof(addstr)))
+ logentry(addstr, port, "-", "listening");
break;
+ }
close(listfd);
+ if(loglvl & CONN && inet_ntop(rp->ai_family, sinaddr,
+ addstr, sizeof(addstr)))
+ logentry(addstr, port, "-", "could not bind");
}
if(rp == nil)
return -1;
@@ -477,7 +492,7 @@ main(int argc, char *argv[])
sizeof(clienth), clientp, sizeof(clientp),
NI_NUMERICHOST|NI_NUMERICSERV);
- if (loglvl & CONN)
+ if(loglvl & CONN)
logentry(clienth, clientp, "-", "connected");
switch(fork()) {
@@ -501,6 +516,8 @@ main(int argc, char *argv[])
break;
}
close(sock);
+ if(loglvl & CONN)
+ logentry(clienth, clientp, "-", "disconnected");
}
shutdown(listfd, SHUT_RDWR);
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.