mirror of
https://github.com/darkk/redsocks.git
synced 2025-08-26 03:35:30 +00:00
Cleanup client session logging.
This commit is contained in:
parent
197d37c382
commit
94c96a60ef
13
redsocks.c
13
redsocks.c
@ -141,9 +141,10 @@ static parser_section redsocks_conf_section =
|
|||||||
.onexit = redsocks_onexit
|
.onexit = redsocks_onexit
|
||||||
};
|
};
|
||||||
|
|
||||||
void redsocks_log_write(
|
void redsocks_log_write_plain(
|
||||||
const char *file, int line, const char *func, int do_errno,
|
const char *file, int line, const char *func, int do_errno,
|
||||||
redsocks_client *client, int priority, const char *orig_fmt, ...
|
const struct sockaddr_in *clientaddr, const struct sockaddr_in *destaddr,
|
||||||
|
int priority, const char *orig_fmt, ...
|
||||||
) {
|
) {
|
||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
struct evbuffer *fmt = evbuffer_new();
|
struct evbuffer *fmt = evbuffer_new();
|
||||||
@ -155,15 +156,15 @@ void redsocks_log_write(
|
|||||||
// no return, as I have to call va_start/va_end
|
// no return, as I have to call va_start/va_end
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inet_ntop(client->clientaddr.sin_family, &client->clientaddr.sin_addr, clientaddr_str, sizeof(clientaddr_str)))
|
if (!inet_ntop(clientaddr->sin_family, &clientaddr->sin_addr, clientaddr_str, sizeof(clientaddr_str)))
|
||||||
strncpy(clientaddr_str, "???", sizeof(clientaddr_str));
|
strncpy(clientaddr_str, "???", sizeof(clientaddr_str));
|
||||||
if (!inet_ntop(client->destaddr.sin_family, &client->destaddr.sin_addr, destaddr_str, sizeof(destaddr_str)))
|
if (!inet_ntop(destaddr->sin_family, &destaddr->sin_addr, destaddr_str, sizeof(destaddr_str)))
|
||||||
strncpy(destaddr_str, "???", sizeof(destaddr_str));
|
strncpy(destaddr_str, "???", sizeof(destaddr_str));
|
||||||
|
|
||||||
if (fmt) {
|
if (fmt) {
|
||||||
evbuffer_add_printf(fmt, "[%s:%i->%s:%i]: %s",
|
evbuffer_add_printf(fmt, "[%s:%i->%s:%i]: %s",
|
||||||
clientaddr_str, ntohs(client->clientaddr.sin_port),
|
clientaddr_str, ntohs(clientaddr->sin_port),
|
||||||
destaddr_str, ntohs(client->destaddr.sin_port),
|
destaddr_str, ntohs(destaddr->sin_port),
|
||||||
orig_fmt);
|
orig_fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
redsocks.h
15
redsocks.h
@ -84,9 +84,18 @@ int redsocks_write_helper(
|
|||||||
redsocks_message_maker mkmessage, int state, size_t wm_only);
|
redsocks_message_maker mkmessage, int state, size_t wm_only);
|
||||||
|
|
||||||
|
|
||||||
#define redsocks_log_error(client, prio, msg...) redsocks_log_write(__FILE__, __LINE__, __func__, 0, client, prio, ## msg)
|
#define redsocks_log_error(client, prio, msg...) \
|
||||||
#define redsocks_log_errno(client, prio, msg...) redsocks_log_write(__FILE__, __LINE__, __func__, 1, client, prio, ## msg)
|
redsocks_log_write_plain(__FILE__, __LINE__, __func__, 0, &(client)->clientaddr, &(client)->destaddr, prio, ## msg)
|
||||||
void redsocks_log_write(const char *file, int line, const char *func, int do_errno, redsocks_client *client, int priority, const char *fmt, ...);
|
#define redsocks_log_errno(client, prio, msg...) \
|
||||||
|
redsocks_log_write_plain(__FILE__, __LINE__, __func__, 1, &(client)->clientaddr, &(client)->destaddr, prio, ## msg)
|
||||||
|
void redsocks_log_write_plain(
|
||||||
|
const char *file, int line, const char *func, int do_errno,
|
||||||
|
const struct sockaddr_in *clientaddr, const struct sockaddr_in *destaddr,
|
||||||
|
int priority, const char *fmt, ...)
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
__attribute__ (( format (printf, 8, 9) ))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
|
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||||
/* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
|
/* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
|
||||||
|
Loading…
Reference in New Issue
Block a user