Permalink
Browse files

logging/ip_port function tweaked

  • Loading branch information...
1 parent 59544e8 commit e1201d72df44d111d3492abc92d36e40f51ccc50 @grobie committed Jun 6, 2009
Showing with 8 additions and 3 deletions.
  1. +8 −3 duoit.c
View
11 duoit.c
@@ -228,7 +228,8 @@ int quit_command(instruc *instruction, usr *user, fd_set *master) {
void get_ip_port(usr *user, char *ip) {
socklen_t len;
struct sockaddr_storage addr;
- char ipstr[INET6_ADDRSTRLEN + 4];
+ char ipstr[INET6_ADDRSTRLEN + 5];
+ char str_port[4];
int port;
len = sizeof(struct sockaddr_storage);
@@ -245,17 +246,20 @@ void get_ip_port(usr *user, char *ip) {
}
strcpy(ip, ipstr);
+ strcat(ip, ":");
+ sprintf(str_port, "%d", port);
+ strcat(ip, str_port);
}
void log_action(usr *user, char *message) {
char log_time[256];
time_t curtime;
- char ip[INET6_ADDRSTRLEN + 4];
+ char ip[INET6_ADDRSTRLEN + 5];
curtime = time(NULL);
get_ip_port(user, ip);
strftime(log_time, 256, "%H:%M", localtime(&curtime));
- printf("%s %s: %s\n", log_time, ip, message);
+ printf("%s - %s - %s\n", log_time, ip, message);
}
@@ -382,6 +386,7 @@ int main(int argc, char *argv[]) {
close_connection(i, &master);
} else {
find_user(i, user, &current);
+ log_action(current, "Zauberei!\n");
dispatch(current, buf, nbytes, &master);
}

0 comments on commit e1201d7

Please sign in to comment.