From 254d73a72ecb4cdbaa2d2562ff01be4dcfdc3fd2 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 13 Apr 2016 17:42:22 +1000 Subject: [PATCH] Added IP to logs --- bbs.c | 8 ++++++-- bbs.h | 2 +- main.c | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bbs.c b/bbs.c index ddcc7d5..d27669b 100644 --- a/bbs.c +++ b/bbs.c @@ -25,6 +25,8 @@ int gSocket; int usertimeout; int timeoutpaused; +char *ipaddress; + void dolog(char *fmt, ...) { char buffer[512]; struct tm time_now; @@ -48,7 +50,7 @@ void dolog(char *fmt, ...) { vsnprintf(buffer, 512, fmt, ap); va_end(ap); - fprintf(logfptr, "%02d:%02d:%02d %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, buffer); + fprintf(logfptr, "%02d:%02d:%02d [%s] %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, ipaddress, buffer); fclose(logfptr); } @@ -658,7 +660,7 @@ void display_info(int socket) { s_getc(socket); } -void runbbs(int socket, char *config_path) { +void runbbs(int socket, char *config_path, char *ip) { char buffer[256]; char password[17]; @@ -676,6 +678,8 @@ void runbbs(int socket, char *config_path) { lua_State *L; int do_internal_login = 0; + ipaddress = ip; + write(socket, iac_echo, 3); write(socket, iac_sga, 3); diff --git a/bbs.h b/bbs.h index 3191ad8..89e5fce 100644 --- a/bbs.h +++ b/bbs.h @@ -133,7 +133,7 @@ struct user_record { }; extern void dolog(char *fmt, ...); -extern void runbbs(int sock, char *config); +extern void runbbs(int sock, char *config, char *ipaddress); extern struct fido_addr *parse_fido_addr(const char *str); extern void s_putchar(int socket, char c); extern void s_putstring(int socket, char *c); diff --git a/main.c b/main.c index bad9433..38149ee 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "bbs.h" void sigchld_handler(int s) @@ -72,7 +73,7 @@ int main(int argc, char **argv) { if (pid == 0) { close(socket_desc); - runbbs(client_sock, argv[1]); + runbbs(client_sock, argv[1], strdup(inet_ntoa(client.sin_addr))); exit(0); } else {