telnet always tries 255.255.255.255

Andrei A. Voropaev av at simcon-mt.com
Fri Jan 28 01:12:47 PST 2005


On Thu, Jan 27, 2005 at 05:22:32PM +0000, Ian Molton wrote:
> Andrei A. Voropaev wrote:
> 
> >Hm. True, on my alpha telnet works. 
> 
> Dont alphas use a 32 bit userspace and 64bit kernel ?

This is not really important for this particular problem. The important
thing is that on my alpha libc declares inet_addr returning unsigned
long. And in the telnet program (as well as in ftp and tftp) they
compare returned value with unsigned long. In this case things shall
work both if unsigned long is 64 bit and if it is 32 bit. The problem
appears only with newer libc (I don't know starting with which version)
which declares inet_addr returning u_int32_t, which is always 32 bits
long. In this case comparisson with unsigned long is not valid anymore.
So the code stops working.


In other words, since lfs uses new library (this affects even lfs-5.1)
then to make telnet, ftp and tftp work on 64-bit platforms the following
patch can be used (previous patch fixed only telnet)

--- inetutils-1.4.2/telnet/commands.c	2002-06-26 05:15:06.000000000 +0200
+++ inetutils-1.4.2-patched/telnet/commands.c	2005-01-27 13:23:52.773505864 +0100
@@ -2291,9 +2291,7 @@
 	}
     } else {
 #endif
-	temp = inet_addr(hostp);
-	if (temp != (unsigned long) -1) {
-	    sin.sin_addr.s_addr = temp;
+	if(inet_aton(hostp, &sin.sin_addr) != 0) {
 	    sin.sin_family = AF_INET;
 
 	    if (_hostname)
@@ -2897,8 +2895,7 @@
 		if (!c)
 			cp2 = 0;
 
-		if ((tmp = inet_addr(cp)) != -1) {
-			sin_addr.s_addr = tmp;
+		if (inet_aton(cp, &sin_addr.s_addr) != 0) {
 		} else if (host = gethostbyname(cp)) {
 #if	defined(h_addr)
 			memmove((caddr_t)&sin_addr,
--- inetutils-1.4.2/libinetutils/iruserok.c	2002-12-11 13:38:00.000000000 +0100
+++ inetutils-1.4.2-patched/libinetutils/iruserok.c	2005-01-27 14:13:18.313675232 +0100
@@ -260,7 +260,7 @@
   register char **pp;
 
   /* Try for raw ip address first. */
-  if (isdigit (*lhost) && (long)(laddr = inet_addr (lhost)) != -1)
+  if (isdigit (*lhost) && (laddr = inet_addr (lhost)) != INADDR_NONE)
     return (raddr == laddr);
 
   /* Better be a hostname. */
--- inetutils-1.4.2/ftp/ftp.c	2002-06-26 05:15:05.000000000 +0200
+++ inetutils-1.4.2-patched/ftp/ftp.c	2005-01-27 13:58:58.063453144 +0100
@@ -119,8 +119,8 @@
 	static char hostnamebuf[80];
 
 	memset((char *)&hisctladdr, 0, sizeof (hisctladdr));
-	hisctladdr.sin_addr.s_addr = inet_addr(host);
-	if (hisctladdr.sin_addr.s_addr != -1) {
+
+	if (inet_aton(host, &hisctladdr.sin_addr) != 0) {
 		hisctladdr.sin_family = AF_INET;
 		(void) strncpy(hostnamebuf, host, sizeof(hostnamebuf));
 	} else {
--- inetutils-1.4.2/tftp/main.c	2001-11-02 22:50:13.000000000 +0100
+++ inetutils-1.4.2-patched/tftp/main.c	2005-01-27 14:00:47.942748952 +0100
@@ -228,8 +228,7 @@
 		strcpy(hostname, host->h_name);
 	} else {
 		peeraddr.sin_family = AF_INET;
-		peeraddr.sin_addr.s_addr = inet_addr(argv[1]);
-		if (peeraddr.sin_addr.s_addr == -1) {
+		if (inet_aton(argv[1], &peeraddr.sin_addr) == 0) {
 			connected = 0;
 			printf("%s: unknown host\n", argv[1]);
 			return;

-- 
Minds, like parachutes, function best when open



More information about the lfs-support mailing list