--- lbbs/src/net_server.c 2025/12/19 06:16:27 1.112 +++ lbbs/src/net_server.c 2025/12/25 05:20:09 1.113 @@ -518,6 +518,7 @@ int net_server(const char *hostaddr, in_ int ret; int flags_server[2]; struct sockaddr_in sin; + char local_addr[INET_ADDRSTRLEN]; #ifdef HAVE_SYS_EPOLL_H struct epoll_event ev, events[MAX_EVENTS]; @@ -606,6 +607,12 @@ int net_server(const char *hostaddr, in_ sin.sin_addr.s_addr = (hostaddr[0] != '\0' ? inet_addr(hostaddr) : INADDR_ANY); sin.sin_port = htons(port[i]); + if (inet_ntop(AF_INET, &(sin.sin_addr), local_addr, sizeof(local_addr)) == NULL) + { + log_error("inet_ntop() error (%d)", errno); + return -1; + } + // Reuse address and port flags_server[i] = 1; if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEADDR, &flags_server[i], sizeof(flags_server[i])) < 0) @@ -622,7 +629,7 @@ int net_server(const char *hostaddr, in_ if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0) { log_error("Bind address %s:%u error (%d)", - inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno); + local_addr, port[i], errno); return -1; } @@ -632,7 +639,7 @@ int net_server(const char *hostaddr, in_ return -1; } - log_common("Listening at %s:%u", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); + log_common("Listening at %s:%u", local_addr, port[i]); #ifdef HAVE_SYS_EPOLL_H ev.events = EPOLLIN; @@ -790,7 +797,7 @@ int net_server(const char *hostaddr, in_ #endif log_common("Reload configuration"); - + // Restart log if (log_restart() < 0) { @@ -931,9 +938,12 @@ int net_server(const char *hostaddr, in_ } } - strncpy(hostaddr_client, inet_ntoa(sin.sin_addr), sizeof(hostaddr_client) - 1); - hostaddr_client[sizeof(hostaddr_client) - 1] = '\0'; - + if (inet_ntop(AF_INET, &(sin.sin_addr), hostaddr_client, sizeof(hostaddr_client)) == NULL) + { + log_error("inet_ntop() error (%d)", errno); + close(socket_client); + break; + } port_client = ntohs(sin.sin_port); if (SYS_child_process_count - 1 < BBS_max_client)