2020-09-23 14:32:52 -04:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
server_logf(FILE *f, const char *fmt, va_list ap)
|
|
|
|
{
|
2020-09-24 19:58:34 -04:00
|
|
|
fprintf(f, "[gmnisrv] ");
|
2020-09-23 14:32:52 -04:00
|
|
|
vfprintf(f, fmt, ap);
|
2020-09-24 11:15:04 -04:00
|
|
|
fprintf(f, "\n");
|
2020-09-23 14:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_logf(FILE *f, struct sockaddr *addr, const char *fmt, va_list ap)
|
|
|
|
{
|
2020-09-24 19:58:34 -04:00
|
|
|
char abuf[INET6_ADDRSTRLEN + 1];
|
2020-09-23 14:32:52 -04:00
|
|
|
const char *addrs = inet_ntop(addr->sa_family,
|
|
|
|
addr->sa_data, abuf, sizeof(abuf));
|
|
|
|
assert(addrs);
|
|
|
|
|
2020-09-24 19:58:34 -04:00
|
|
|
fprintf(f, "%s ", addrs);
|
2020-09-23 14:32:52 -04:00
|
|
|
vfprintf(f, fmt, ap);
|
2020-09-24 11:15:04 -04:00
|
|
|
fprintf(f, "\n");
|
2020-09-23 14:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2020-09-26 13:40:20 -04:00
|
|
|
server_logf(stderr, fmt, ap);
|
2020-09-23 14:32:52 -04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_log(struct sockaddr *addr, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
client_logf(stdout, addr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_error(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
server_logf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_error(struct sockaddr *addr, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
client_logf(stderr, addr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|