commit - 80bbcad5f279e47ec5ccc22076fe1184af7caf5b
commit + 709d6e5ead07ce64dd6625eef05deaedadd8f095
blob - 60554b173025ee6dd42a8eef9680204d0d39ea34
blob + 995b54d11ce59f761349f1a379749539d3c573d3
--- ChangeLog
+++ ChangeLog
+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>
* uri.c (parse_uri): IRI support
blob - 981b73cae288638a206d7d193242032addb5666e
blob + df6c9a70377a6ba209a5682de0ae0be7f490337f
--- gmid.c
+++ gmid.c
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <netdb.h>
#include <signal.h>
#include <stdarg.h>
#include <string.h>
__attribute__ ((format (printf, 3, 4)))
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_start(ap, fmt);
- priority |= LOG_DAEMON;
- if (inet_ntop(c->af, &c->addr, buf, sizeof(buf)) == NULL)
- fatal("inet_ntop: %s", strerror(errno));
+ len = sizeof(c->addr);
+ 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) {
- vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
- } else
- vsyslog(priority, fmt, ap);
+ if (vasprintf(&fmted, fmt, ap) == -1)
+ fatal("vasprintf: %s", strerror(errno));
+
+ if (foreground)
+ 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);
}
do_accept(int sock, struct tls *ctx, struct pollfd *fds, struct client *clients)
{
int i, fd;
- struct sockaddr_in addr;
+ struct sockaddr_storage addr;
socklen_t len;
len = sizeof(addr);
clients[i].child = -1;
clients[i].buf = MAP_FAILED;
clients[i].af = AF_INET;
- clients[i].addr = addr.sin_addr;
+ clients[i].addr = addr;
connected_clients++;
return;
blob - 16d96a7d7dcf40e2f3948b437dac46e5447a9f21
blob + 0df59ed5b33978a62a13e25df7356f3505d5a858
--- gmid.h
+++ gmid.h
void *buf, *i; /* mmap buffer */
ssize_t len, off; /* mmap/static buffer */
int af;
- struct in_addr addr;
+ struct sockaddr_storage addr;
};
struct uri {