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) {
|
if (fds[i].fd == master_socket && fds[i].revents == POLLIN) {
|
||||||
// Handle new connections
|
// Handle new connections
|
||||||
do {
|
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 (newsock < 0) {
|
||||||
if (errno != EWOULDBLOCK) {
|
if (errno != EWOULDBLOCK) {
|
||||||
logger->print(LOGLEVEL_ERROR, "net: accept() failed: {}", strerror(errno));
|
logger->print(LOGLEVEL_ERROR, "net: accept() failed: {}", strerror(errno));
|
||||||
@@ -263,7 +265,16 @@ int main(int argc , char *argv[]) {
|
|||||||
int flags = fcntl(newsock, F_GETFL, 0);
|
int flags = fcntl(newsock, F_GETFL, 0);
|
||||||
fcntl(newsock, F_SETFL, flags | O_NONBLOCK);
|
fcntl(newsock, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
|
||||||
logger->print(LOGLEVEL_DEBUG, "client {} accepted in slot {}", newsock, slot);
|
char client_addr[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &client_name.sin_addr, client_addr, sizeof(client_addr));
|
||||||
|
|
||||||
|
logger->print(
|
||||||
|
LOGLEVEL_DEBUG,
|
||||||
|
"client {} (ip: {}) accepted in slot {}",
|
||||||
|
newsock,
|
||||||
|
client_addr,
|
||||||
|
slot
|
||||||
|
);
|
||||||
|
|
||||||
fds[slot].fd = newsock;
|
fds[slot].fd = newsock;
|
||||||
fds[slot].events = POLLIN;
|
fds[slot].events = POLLIN;
|
||||||
|
|||||||
Reference in New Issue
Block a user