From 9aed37b92e85c95f023d655e280d648ca66a0628 Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Tue, 25 Jun 2024 23:05:07 +0300 Subject: [PATCH] IPv6 fixes for incoming inetd calls, minors from lint --- source/bforce/io_tcpip.c | 1 - source/bforce/io_unix_tio.c | 8 +++++++- source/bforce/prot_binkp.c | 2 +- source/bforce/sess_answ.c | 27 +++++++++++++++------------ source/bforce/u_misc.c | 1 + 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/source/bforce/io_tcpip.c b/source/bforce/io_tcpip.c index e4f38f7..38f3145 100644 --- a/source/bforce/io_tcpip.c +++ b/source/bforce/io_tcpip.c @@ -54,7 +54,6 @@ static int tcpip_connect2(struct addrinfo *ai) if ( fd == -1 ) { DEB((D_INFO, "tcpip_connect2: socket error")); - continue; } else break; diff --git a/source/bforce/io_unix_tio.c b/source/bforce/io_unix_tio.c index 91b4281..5f37c1f 100644 --- a/source/bforce/io_unix_tio.c +++ b/source/bforce/io_unix_tio.c @@ -118,6 +118,9 @@ int tio_get(int fd, TIO *tio) { #ifdef HAVE_TERMIOS_H return tcgetattr(fd, tio); +#else + DEB(("io_unix_tio: TERMIOS not supported!")); + return -1; #endif } @@ -127,6 +130,9 @@ int tio_set(int fd, TIO *tio) { #ifdef HAVE_TERMIOS_H return tcsetattr(fd, TCSANOW, tio); +#else + DEB(("io_unix_tio: TERMIOS not supported!")); + return -1; #endif } @@ -177,7 +183,7 @@ int tio_get_speed(TIO *tio) return speedtab[i].nspeed; } - return-1; + return -1; } int tio_set_flow_control(int fd, TIO *tio, int flow) diff --git a/source/bforce/prot_binkp.c b/source/bforce/prot_binkp.c index 3c3d051..c3d0e6a 100644 --- a/source/bforce/prot_binkp.c +++ b/source/bforce/prot_binkp.c @@ -788,7 +788,7 @@ case BPMSG_FILE: /* File information */ DEB((D_24554, "no, skipping; TODO: accept it")); if( bstate->extracmd[0] != -1 ) return 0; bstate->extracmd[0] = BPMSG_SKIP; - sprintf(bstate->extracmd+1, "%s %ld %ld %ld", recvfi.fn, recvfi.sz, recvfi.tm); + sprintf(bstate->extracmd+1, "%s %ld %ld %ld", recvfi.fn, recvfi.sz, recvfi.tm, recvfi.offs); bstate->extraislast = false; return 1; } diff --git a/source/bforce/sess_answ.c b/source/bforce/sess_answ.c index ddb0642..f6cb2d5 100644 --- a/source/bforce/sess_answ.c +++ b/source/bforce/sess_answ.c @@ -22,8 +22,11 @@ int answ_system(e_session type, char *connstr, int inetd) { TIO oldtio; - struct sockaddr_in client; + struct sockaddr_storage client; int clientlen = sizeof(client); + char clienthost[NI_MAXHOST]; + char clientport[NI_MAXSERV]; + int clientres = 0; int rc = 0; char *p; @@ -74,18 +77,18 @@ int answ_system(e_session type, char *connstr, int inetd) log("Answering TCPIP call..."); if( connstr && *connstr ) state.connstr = (char*)xstrcpy(connstr); - else if( getpeername(0, (struct sockaddr*)&client, &clientlen) == -1 ) - logerr("can't get client address"); - else + else { -#ifdef IPV6 - >char addr_str[INET6_ADDRSTRLEN+1]; - state.peername = (char*)xstrcpy(inet_ntop(AF_INET6, client.sin6_addr, addr_str, INET6_ADDRSTRLEN)); - state.peerport = (long)ntohs(client.sin6_port); -#else - state.peername = (char*)xstrcpy(inet_ntoa(client.sin_addr)); - state.peerport = (long)ntohs(client.sin_port); -#endif + clientres = getnameinfo( (struct sockaddr*)&client, clientlen, + clienthost, sizeof(clienthost), clientport, + sizeof(clientport), NI_NUMERICHOST | NI_NUMERICSERV); + if ( clientres == 0 ) + { + state.peername = (char*)xstrcpy(clienthost); + state.peerport = (long)atol(clientport); + } + else + log("sess_answ: can't get client address: ", gai_strerror(clientres)); } } diff --git a/source/bforce/u_misc.c b/source/bforce/u_misc.c index e2f1967..d2042ec 100644 --- a/source/bforce/u_misc.c +++ b/source/bforce/u_misc.c @@ -81,6 +81,7 @@ void *xrealloc(void *buf, size_t size) else if( (tmp = (char*)(buf ? realloc(buf, size) : malloc(size))) == NULL ) { log("failed to reallocate %ld bytes -> abort", size); + if( buf ) free(buf); abort(); }