From stolz@i2.informatik.rwth-aachen.de  Thu Mar 16 09:58:10 2006
Return-Path: <stolz@i2.informatik.rwth-aachen.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 596F316A400
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 16 Mar 2006 09:58:10 +0000 (UTC)
	(envelope-from stolz@i2.informatik.rwth-aachen.de)
Received: from atlas.informatik.rwth-aachen.de (atlas.informatik.RWTH-Aachen.DE [137.226.194.2])
	by mx1.FreeBSD.org (Postfix) with ESMTP id BCC3543D46
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 16 Mar 2006 09:58:08 +0000 (GMT)
	(envelope-from stolz@i2.informatik.rwth-aachen.de)
Received: from i2.informatik.rwth-aachen.de (menelaos.informatik.RWTH-Aachen.DE [137.226.194.73])
	by atlas.informatik.rwth-aachen.de (8.12.10/8.12.10/SuSE Linux 0.7) with ESMTP id k2G9w7sY032286
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 16 Mar 2006 10:58:07 +0100
Received: (from stolz@localhost)
	by i2.informatik.rwth-aachen.de (8.13.4/8.13.4/Submit) id k2G9wDY1023810;
	Thu, 16 Mar 2006 10:58:13 +0100 (CET)
	(envelope-from stolz)
Message-Id: <200603160958.k2G9wDY1023810@i2.informatik.rwth-aachen.de>
Date: Thu, 16 Mar 2006 10:58:13 +0100 (CET)
From: Volker Stolz <vs@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Make telnet accept 'host:port' on command line
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         94546
>Category:       bin
>Synopsis:       [patch] Make telnet(1) accept 'host:port' on command line
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 16 15:09:37 GMT 2006
>Closed-Date:    
>Last-Modified:  Mon Dec 29 18:16:59 UTC 2008
>Originator:     Volker Stolz
>Release:        FreeBSD 6.1-BETA3 i386
>Organization:
Lehrstuhl fr Informatik II; RWTH Aachen (c) Universitt
>Environment:
System: FreeBSD menelaos.informatik.rwth-aachen.de 6.1-BETA3 FreeBSD 6.1-BETA3 #1: Mon Mar 13 10:45:03 CET 2006 root@menelaos.informatik.rwth-aachen.de:/usr/obj/usr/src/sys/MENELAOS i386


>Description:
Almost every network application allows you to specify the remote end through
'host:port', only telnet seems to be stuck in the last millenium. This patch
addresses this problem:
- permit 'telnet host:port'
- fail on 'telnet host:port1 port2' with an error message
- protect against IPv6 addresses (they have multiple colons)
>How-To-Repeat:
>Fix:
--- telnet.patch begins here ---
--- /usr/src/contrib/telnet/telnet/commands.c	Mon Feb 28 13:46:52 2005
+++ src/telnet/telnet/commands.c	Thu Mar 16 10:52:06 2006
@@ -2291,8 +2291,26 @@
 	    hostname++;
 	    srcroute = 1;
 	}
-    } else
-        hostname = hostp;
+    } else {
+      char *colon;
+      /* Did we get host:port? */
+      colon = strrchr(hostp,':');
+      /* Maybe, make sure it's not an IPv6 address */
+      if ((colon != NULL) && (colon == strchr(hostp,':'))) {
+	if (portp) {
+	  fprintf(stderr, "Destination port already set.\n");
+	  goto fail;	  
+	} else { /* Patch \0 into argument */
+	  *colon = '\0';
+	  /* Check if colon was last char in argument: */
+	  colon++;
+	  if ((*colon) != '\0')
+	    portp = colon;
+	}
+      }
+      hostname = hostp;
+      
+    }
     if (!portp) {
       telnetport = 1;
       portp = strdup("telnet");
--- telnet.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
