mirror of
https://github.com/omar-polo/gmid.git
synced 2024-09-30 06:21:19 +02:00
log also the port of the client
This commit is contained in:
parent
80bbcad5f2
commit
709d6e5ead
@ -1,3 +1,7 @@
|
|||||||
|
2021-01-10 Omar Polo <op@omarpolo.com>
|
||||||
|
|
||||||
|
* gmid.c (logs): log also the port of the client
|
||||||
|
|
||||||
2020-12-26 Omar Polo <op@omarpolo.com>
|
2020-12-26 Omar Polo <op@omarpolo.com>
|
||||||
|
|
||||||
* uri.c (parse_uri): IRI support
|
* uri.c (parse_uri): IRI support
|
||||||
|
41
gmid.c
41
gmid.c
@ -23,6 +23,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <netdb.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -90,22 +91,38 @@ fatal(const char *fmt, ...)
|
|||||||
|
|
||||||
__attribute__ ((format (printf, 3, 4)))
|
__attribute__ ((format (printf, 3, 4)))
|
||||||
static inline void
|
static inline void
|
||||||
logs(int priority, struct client *c, const char *fmt, ...)
|
logs(int priority, struct client *c,
|
||||||
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[INET_ADDRSTRLEN];
|
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||||
|
char *fmted, *s;
|
||||||
|
size_t len;
|
||||||
|
int ec;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
priority |= LOG_DAEMON;
|
|
||||||
|
|
||||||
if (inet_ntop(c->af, &c->addr, buf, sizeof(buf)) == NULL)
|
len = sizeof(c->addr);
|
||||||
fatal("inet_ntop: %s", strerror(errno));
|
ec = getnameinfo((struct sockaddr*)&c->addr, len,
|
||||||
|
hbuf, sizeof(hbuf),
|
||||||
|
sbuf, sizeof(sbuf),
|
||||||
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
|
if (ec != 0)
|
||||||
|
fatal("getnameinfo: %s", gai_strerror(ec));
|
||||||
|
|
||||||
if (foreground) {
|
if (vasprintf(&fmted, fmt, ap) == -1)
|
||||||
vfprintf(stderr, fmt, ap);
|
fatal("vasprintf: %s", strerror(errno));
|
||||||
fprintf(stderr, "\n");
|
|
||||||
} else
|
if (foreground)
|
||||||
vsyslog(priority, fmt, ap);
|
fprintf(stderr, "%s:%s %s\n", hbuf, sbuf, fmted);
|
||||||
|
else {
|
||||||
|
if (asprintf(&s, "%s:%s %s", hbuf, sbuf, fmted) == -1)
|
||||||
|
fatal("asprintf: %s", strerror(errno));
|
||||||
|
syslog(priority | LOG_DAEMON, "%s", s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(fmted);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
@ -685,7 +702,7 @@ void
|
|||||||
do_accept(int sock, struct tls *ctx, struct pollfd *fds, struct client *clients)
|
do_accept(int sock, struct tls *ctx, struct pollfd *fds, struct client *clients)
|
||||||
{
|
{
|
||||||
int i, fd;
|
int i, fd;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_storage addr;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
|
|
||||||
len = sizeof(addr);
|
len = sizeof(addr);
|
||||||
@ -711,7 +728,7 @@ do_accept(int sock, struct tls *ctx, struct pollfd *fds, struct client *clients)
|
|||||||
clients[i].child = -1;
|
clients[i].child = -1;
|
||||||
clients[i].buf = MAP_FAILED;
|
clients[i].buf = MAP_FAILED;
|
||||||
clients[i].af = AF_INET;
|
clients[i].af = AF_INET;
|
||||||
clients[i].addr = addr.sin_addr;
|
clients[i].addr = addr;
|
||||||
|
|
||||||
connected_clients++;
|
connected_clients++;
|
||||||
return;
|
return;
|
||||||
|
2
gmid.h
2
gmid.h
@ -66,7 +66,7 @@ struct client {
|
|||||||
void *buf, *i; /* mmap buffer */
|
void *buf, *i; /* mmap buffer */
|
||||||
ssize_t len, off; /* mmap/static buffer */
|
ssize_t len, off; /* mmap/static buffer */
|
||||||
int af;
|
int af;
|
||||||
struct in_addr addr;
|
struct sockaddr_storage addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct uri {
|
struct uri {
|
||||||
|
Loading…
Reference in New Issue
Block a user