add client IP output on new connection
This commit is contained in:
15
src/main.cpp
15
src/main.cpp
@@ -235,7 +235,9 @@ int main(int argc , char *argv[]) {
|
||||
if (fds[i].fd == master_socket && fds[i].revents == POLLIN) {
|
||||
// Handle new connections
|
||||
do {
|
||||
newsock = accept(master_socket, NULL, NULL);
|
||||
struct sockaddr_in client_name;
|
||||
socklen_t client_len = sizeof(client_name);
|
||||
newsock = accept(master_socket, (struct sockaddr*)&client_name, &client_len);
|
||||
if (newsock < 0) {
|
||||
if (errno != EWOULDBLOCK) {
|
||||
logger->print(LOGLEVEL_ERROR, "net: accept() failed: {}", strerror(errno));
|
||||
@@ -262,8 +264,17 @@ int main(int argc , char *argv[]) {
|
||||
// Set non-blocking mode
|
||||
int flags = fcntl(newsock, F_GETFL, 0);
|
||||
fcntl(newsock, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
char client_addr[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &client_name.sin_addr, client_addr, sizeof(client_addr));
|
||||
|
||||
logger->print(LOGLEVEL_DEBUG, "client {} accepted in slot {}", newsock, slot);
|
||||
logger->print(
|
||||
LOGLEVEL_DEBUG,
|
||||
"client {} (ip: {}) accepted in slot {}",
|
||||
newsock,
|
||||
client_addr,
|
||||
slot
|
||||
);
|
||||
|
||||
fds[slot].fd = newsock;
|
||||
fds[slot].events = POLLIN;
|
||||
|
||||
Reference in New Issue
Block a user