FreeBSD Bugzilla – Attachment 129681 Details for
Bug 173728
[patch] add set baud rate support to telnet(1)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 11.73 KB, created by
Enji Cooper
on 2012-11-19 21:50:00 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Enji Cooper
Created:
2012-11-19 21:50:00 UTC
Size:
11.73 KB
patch
obsolete
>Index: contrib/telnet/arpa/telnet.h >=================================================================== >--- contrib/telnet/arpa/telnet.h (revision 242903) >+++ contrib/telnet/arpa/telnet.h (working copy) >@@ -127,6 +127,7 @@ > #define TELOPT_KERMIT 47 /* RFC2840 - Kermit */ > #define TELOPT_EXOPL 255 /* extended-options-list */ > >+#define COMPORT_SET_BAUDRATE 1 /* RFC2217 - Com Port Set Baud Rate */ > > #define NTELOPTS (1+TELOPT_KERMIT) > #ifdef TELOPTS >Index: contrib/telnet/telnet/baud.h >=================================================================== >--- contrib/telnet/telnet/baud.h (revision 0) >+++ contrib/telnet/telnet/baud.h (working copy) >@@ -0,0 +1,121 @@ >+/* >+ * Copyright (c) 2012 EMC Corporation >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND >+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE >+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ * >+ * $FreeBSD$ >+ */ >+ >+/* >+ * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD). >+ */ >+#if B4800 != 4800 >+#define DECODE_BAUD >+#endif >+ >+#ifdef DECODE_BAUD >+#ifndef B7200 >+#define B7200 B4800 >+#endif >+ >+#ifndef B14400 >+#define B14400 B9600 >+#endif >+ >+#ifndef B19200 >+#define B19200 B14400 >+#endif >+ >+#ifndef B28800 >+#define B28800 B19200 >+#endif >+ >+#ifndef B38400 >+#define B38400 B28800 >+#endif >+ >+#ifndef B57600 >+#define B57600 B38400 >+#endif >+ >+#ifndef B76800 >+#define B76800 B57600 >+#endif >+ >+#ifndef B115200 >+#define B115200 B76800 >+#endif >+ >+#ifndef B115200 >+#define B115200 B76800 >+#endif >+#endif >+ >+#ifndef B230400 >+#define B230400 B115200 >+#endif >+ >+/* >+ * A table of available terminal speeds >+ */ >+struct termspeeds termspeeds[] = { >+ { 0, B0 }, >+ { 50, B50 }, >+ { 75, B75 }, >+ { 110, B110 }, >+ { 134, B134 }, >+ { 150, B150 }, >+ { 200, B200 }, >+ { 300, B300 }, >+ { 600, B600 }, >+ { 1200, B1200 }, >+ { 1800, B1800 }, >+ { 2400, B2400 }, >+ { 4800, B4800 }, >+#ifdef B7200 >+ { 7200, B7200 }, >+#endif >+ { 9600, B9600 }, >+#ifdef B14400 >+ { 14400, B14400 }, >+#endif >+#ifdef B19200 >+ { 19200, B19200 }, >+#endif >+#ifdef B28800 >+ { 28800, B28800 }, >+#endif >+#ifdef B38400 >+ { 38400, B38400 }, >+#endif >+#ifdef B57600 >+ { 57600, B57600 }, >+#endif >+#ifdef B115200 >+ { 115200, B115200 }, >+#endif >+#ifdef B230400 >+ { 230400, B230400 }, >+#endif >+ { -1, 0 } >+}; >Index: contrib/telnet/telnet/commands.c >=================================================================== >--- contrib/telnet/telnet/commands.c (revision 242903) >+++ contrib/telnet/telnet/commands.c (working copy) >@@ -896,6 +896,7 @@ > { "forw1", "alternate end of line character", NULL, termForw1Charp }, > { "forw2", "alternate end of line character", NULL, termForw2Charp }, > { "ayt", "alternate AYT character", NULL, termAytCharp }, >+ { "baudrate", "set remote baud rate", DoBaudRate, ComPortBaudRate }, > { NULL, NULL, NULL, NULL } > }; > >Index: contrib/telnet/telnet/externs.h >=================================================================== >--- contrib/telnet/telnet/externs.h (revision 242903) >+++ contrib/telnet/telnet/externs.h (working copy) >@@ -231,6 +231,10 @@ > NetTraceFile[]; /* Name of file where debugging output goes */ > extern void > SetNetTrace(char *); /* Function to change where debugging goes */ >+extern unsigned char >+ ComPortBaudRate[]; /* Baud rate of the remote end */ >+extern void >+ DoBaudRate(char *); /* Function to set the baud rate of the remote end */ > > extern jmp_buf > toplevel; /* For error conditions. */ >@@ -475,7 +479,17 @@ > # endif > #endif > >+typedef struct { >+ int >+ system, /* what the current time is */ >+ echotoggle, /* last time user entered echo character */ >+ modenegotiated, /* last time operating mode negotiated */ >+ didnetreceive, /* last time we read data from network */ >+ gotDM; /* when did we last see a data mark */ >+} Clocks; > >+extern Clocks clocks; >+ > /* Ring buffer structures which are shared */ > > extern Ring >Index: contrib/telnet/telnet/main.c >=================================================================== >--- contrib/telnet/telnet/main.c (revision 242903) >+++ contrib/telnet/telnet/main.c (working copy) >@@ -154,7 +154,7 @@ > #define IPSECOPT > #endif > while ((ch = getopt(argc, argv, >- "468EKLNS:X:acde:fFk:l:n:rs:uxy" IPSECOPT)) != -1) >+ "468B:EKLNS:X:acde:fFk:l:n:rs:uxy" IPSECOPT)) != -1) > #undef IPSECOPT > { > switch(ch) { >@@ -169,6 +169,9 @@ > case '8': > eight = 3; /* binary output and input */ > break; >+ case 'B': >+ DoBaudRate(optarg); >+ break; > case 'E': > rlogin = escape = _POSIX_VDISABLE; > break; >Index: contrib/telnet/telnet/sys_bsd.c >=================================================================== >--- contrib/telnet/telnet/sys_bsd.c (revision 242903) >+++ contrib/telnet/telnet/sys_bsd.c (working copy) >@@ -60,6 +60,7 @@ > #include "defines.h" > #include "externs.h" > #include "types.h" >+#include "baud.h" > > int > tout, /* Output file descriptor */ >@@ -682,71 +683,6 @@ > > } > >-/* >- * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD). >- */ >-#if B4800 != 4800 >-#define DECODE_BAUD >-#endif >- >-#ifdef DECODE_BAUD >-#ifndef B7200 >-#define B7200 B4800 >-#endif >- >-#ifndef B14400 >-#define B14400 B9600 >-#endif >- >-#ifndef B19200 >-# define B19200 B14400 >-#endif >- >-#ifndef B28800 >-#define B28800 B19200 >-#endif >- >-#ifndef B38400 >-# define B38400 B28800 >-#endif >- >-#ifndef B57600 >-#define B57600 B38400 >-#endif >- >-#ifndef B76800 >-#define B76800 B57600 >-#endif >- >-#ifndef B115200 >-#define B115200 B76800 >-#endif >- >-#ifndef B230400 >-#define B230400 B115200 >-#endif >- >- >-/* >- * This code assumes that the values B0, B50, B75... >- * are in ascending order. They do not have to be >- * contiguous. >- */ >-struct termspeeds { >- long speed; >- long value; >-} termspeeds[] = { >- { 0, B0 }, { 50, B50 }, { 75, B75 }, >- { 110, B110 }, { 134, B134 }, { 150, B150 }, >- { 200, B200 }, { 300, B300 }, { 600, B600 }, >- { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, >- { 4800, B4800 }, { 7200, B7200 }, { 9600, B9600 }, >- { 14400, B14400 }, { 19200, B19200 }, { 28800, B28800 }, >- { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 }, >- { 230400, B230400 }, { -1, B230400 } >-}; >-#endif /* DECODE_BAUD */ >- > void > TerminalSpeeds(long *ispeed, long *ospeed) > { >Index: contrib/telnet/telnet/telnet.1 >=================================================================== >--- contrib/telnet/telnet/telnet.1 (revision 242903) >+++ contrib/telnet/telnet/telnet.1 (working copy) >@@ -43,6 +43,7 @@ > .Sh SYNOPSIS > .Nm > .Op Fl 468EFKLNacdfruxy >+.Op Fl B Ar baudrate > .Op Fl S Ar tos > .Op Fl X Ar authtype > .Op Fl e Ar escapechar >@@ -89,6 +90,9 @@ > negotiate the > .Dv TELNET BINARY > option on both input and output. >+.It Fl B Ar baudrate >+Sets the baud rate to >+.Ar baudrate . > .It Fl E > Stops any character from being recognized as an escape character. > .It Fl F >Index: contrib/telnet/telnet/telnet.c >=================================================================== >--- contrib/telnet/telnet/telnet.c (revision 242903) >+++ contrib/telnet/telnet/telnet.c (working copy) >@@ -52,6 +52,7 @@ > #include <stdlib.h> > #include <term.h> > #include <unistd.h> >+#include <arpa/inet.h> > #include <arpa/telnet.h> > > #include "ring.h" >@@ -206,7 +207,44 @@ > * is in disagreement as to what the current state should be. > */ > >+unsigned char ComPortBaudRate[256]; >+ > void >+DoBaudRate(char *arg) >+{ >+ char *temp; >+ size_t len; >+ int baudrate, i; >+ >+ /* XXX: add support for 0 (baud rate retrieval) */ >+ baudrate = (int)strtol(arg, &temp, 10); >+ for (i = 1; termspeeds[i].speed != -1; i++) { >+ if (baudrate == termspeeds[i].speed) { >+ baudrate = termspeeds[i].speed; >+ break; >+ } >+ } >+ if (termspeeds[i].speed == -1) >+ return; >+ strcpy(ComPortBaudRate, arg); >+ >+ len = 10; >+ if (NETROOM() <= len) { >+ ExitString("No room in buffer for baud rate.\n", 1); >+ /*NOTREACHED*/ >+ } >+ if (asprintf(&temp, "%c%c%c%c....%c%c", IAC, SB, TELOPT_COMPORT, >+ COMPORT_SET_BAUDRATE, IAC, SE) < 0) { >+ ExitString("Could not allocate baud rate buffer\n", 1); >+ /* NOTREACHED */ >+ } >+ baudrate = htonl(baudrate); >+ memcpy(&temp[4], &baudrate, sizeof(baudrate)); >+ ring_supply_data(&netoring, temp, len); >+ printsub('>', &temp[2], len-2); >+} >+ >+void > send_do(int c, int init) > { > if (init) { >Index: contrib/telnet/telnet/types.h >=================================================================== >--- contrib/telnet/telnet/types.h (revision 242903) >+++ contrib/telnet/telnet/types.h (working copy) >@@ -40,13 +40,9 @@ > > extern Modelist modelist[]; > >-typedef struct { >- int >- system, /* what the current time is */ >- echotoggle, /* last time user entered echo character */ >- modenegotiated, /* last time operating mode negotiated */ >- didnetreceive, /* last time we read data from network */ >- gotDM; /* when did we last see a data mark */ >-} Clocks; >+struct termspeeds { >+ int speed; >+ int value; >+}; > >-extern Clocks clocks; >+extern struct termspeeds termspeeds[]; >Index: contrib/telnet/telnetd/sys_term.c >=================================================================== >--- contrib/telnet/telnetd/sys_term.c (revision 242903) >+++ contrib/telnet/telnetd/sys_term.c (working copy) >@@ -46,6 +46,8 @@ > > #include "telnetd.h" > #include "pathnames.h" >+#include "types.h" >+#include "baud.h" > > #ifdef AUTHENTICATION > #include <libtelnet/auth.h> >@@ -743,56 +745,6 @@ > #endif > } > >-/* >- * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD). >- */ >-#if B4800 != 4800 >-#define DECODE_BAUD >-#endif >- >-#ifdef DECODE_BAUD >- >-/* >- * A table of available terminal speeds >- */ >-struct termspeeds { >- int speed; >- int value; >-} termspeeds[] = { >- { 0, B0 }, { 50, B50 }, { 75, B75 }, >- { 110, B110 }, { 134, B134 }, { 150, B150 }, >- { 200, B200 }, { 300, B300 }, { 600, B600 }, >- { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, >- { 4800, B4800 }, >-#ifdef B7200 >- { 7200, B7200 }, >-#endif >- { 9600, B9600 }, >-#ifdef B14400 >- { 14400, B14400 }, >-#endif >-#ifdef B19200 >- { 19200, B19200 }, >-#endif >-#ifdef B28800 >- { 28800, B28800 }, >-#endif >-#ifdef B38400 >- { 38400, B38400 }, >-#endif >-#ifdef B57600 >- { 57600, B57600 }, >-#endif >-#ifdef B115200 >- { 115200, B115200 }, >-#endif >-#ifdef B230400 >- { 230400, B230400 }, >-#endif >- { -1, 0 } >-}; >-#endif /* DECODE_BAUD */ >- > void > tty_tspeed(int val) > { >Index: libexec/telnetd/Makefile >=================================================================== >--- libexec/telnetd/Makefile (revision 242903) >+++ libexec/telnetd/Makefile (working copy) >@@ -25,6 +25,7 @@ > .endif > > CFLAGS+= -I${TELNETDIR} >+CFLAGS+= -I${TELNETDIR}/telnet > > LIBTELNET= ${.OBJDIR}/../../lib/libtelnet/libtelnet.a
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 173728
: 129681