diff --git a/src/tcldcc.c b/src/tcldcc.c index 601714ba2..c1b015649 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -1024,7 +1024,7 @@ static int tcl_connect STDVAR static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *maskproc, char *flag) { int i, idx = -1, port, realport, found=0, ipv4=1, error; - char s[11], msg[256], newip[EGG_INET_ADDRSTRLEN]; + char s[11], msg[256], newip[EGG_INET_ADDRSTRLEN], newip2[EGG_INET_ADDRSTRLEN]; struct portmap *pmap = NULL, *pold = NULL; sockname_t name; struct in_addr ipaddr4; @@ -1107,16 +1107,35 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m /* Check if IP is specific, but the already-bound IP is all-interfaces */ if (ipv4) { if ((ipaddr4.s_addr != 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr == 0)) { - Tcl_AppendResult(irp, "this port is already bound to 0.0.0.0 on this " - "machine, remove it before trying to bind to this IP", NULL); + Tcl_AppendResult(irp, "This port is already bound to 0.0.0.0 on this " + "machine, remove it (using listen [ip] off) before " + "trying to bind to specific IP ", + inet_ntop(AF_INET, &ipaddr4.s_addr, newip, sizeof newip), + ".", NULL); + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + "0.0.0.0 on this machine, remove it (using listen [ip] " + "off) before trying to bind to specific IP %s, check listen settings " + "in config file or restart instead of rehash.", port, + inet_ntop(AF_INET, &ipaddr4.s_addr, newip, sizeof newip)); + return TCL_OK; + } return TCL_ERROR; } } #ifdef IPV6 else if ((!IN6_IS_ADDR_UNSPECIFIED(&ipaddr6)) && (IN6_IS_ADDR_UNSPECIFIED(&dcc[idx].sockname.addr.s6.sin6_addr))) { - Tcl_AppendResult(irp, "this port is already bound to :: on this " - "machine, remove it before trying to bind to this IP", NULL); + Tcl_AppendResult(irp, "This port is already bound to :: on this " + "machine, remove it (using listen [ip] off) before " + "trying to bind to this IP.", NULL); + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + ":: on this machine, remove it (using listen [ip] " + "off) before trying to bind to this IP, check listen settings " + "in config file or restart instead of rehash.", port); + return TCL_OK; + } return TCL_ERROR; } #endif @@ -1124,19 +1143,38 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m /* Check if IP is all-interfaces, but the already-bound IP is specific */ if (ipv4) { if ((ipaddr4.s_addr == 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr != 0)) { - Tcl_AppendResult(irp, "this port is already bound to a specific IP " - "on this machine, remove it before trying to bind to all " - "interfaces", NULL); + Tcl_AppendResult(irp, "This port is already bound to specific IP ", + inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), + " on this machine, remove it (using listen [ip] off) " + "before trying to bind to all interfaces.", NULL); + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + "specific IP %s on this machine, remove it (using listen [ip] " + "off) before trying to bind to IP %s, check listen settings " + "in config file or restart instead of rehash.", port, + inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), + inet_ntop(AF_INET, &ipaddr4.s_addr, newip2, sizeof newip2)); + return TCL_OK; + } return TCL_ERROR; } } #ifdef IPV6 else if (IN6_IS_ADDR_UNSPECIFIED(&ipaddr6) && (!IN6_IS_ADDR_UNSPECIFIED(&dcc[idx].sockname.addr.s6.sin6_addr))) { - Tcl_AppendResult(irp, "this port is already bound to a specific IP " - "on this machine, remove it before trying to bind to this all " - "interfaces", NULL); - return TCL_ERROR; + Tcl_AppendResult(irp, "This port is already bound to specific IP ", + inet_ntop(AF_INET6, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip), + " on this machine, remove it (using listen [ip] off) " + "before trying to bind to all interfaces", NULL); + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + "specific IP %s on this machine, remove it (using listen [ip] " + "off) before trying to bind to this IP, check listen settings " + "in config file or restart instead of rehash.", port, + inet_ntop(AF_INET, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip)); + return TCL_OK; + } + return TCL_ERROR; } #endif } @@ -1151,7 +1189,7 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m } /* Remove */ if (idx < 0) { - Tcl_AppendResult(irp, "no such listen port is open", NULL); + Tcl_AppendResult(irp, "no such listen ip/port is open", NULL); return TCL_ERROR; } killsock(dcc[idx].sock);