Skip to content

Commit

Permalink
Update telnet code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Downarowicz committed Mar 1, 2022
1 parent e721c0b commit 78a746a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/at/downardo/j3270Server/Telnet.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
import java.io.IOException;

public class Telnet {


private static final byte BINARY = (byte)0x00;
private static final byte SEND = (byte)0x01;
private static final byte SE = (byte)0xf0;
private static final byte SB = (byte)0xfa;
private static final byte WILL = (byte)0xfb;
private static final byte WONT = (byte)0xfc;
private static final byte DO = (byte)0xfd;
private static final byte DONT = (byte)0xfe;
private static final byte IAC = (byte)0xff;
private static final byte TERMINALTYPE = (byte)0x18;
private static final byte EOR = (byte)0x19;



/**
* NegotiateTelnet will naively (e.g. not checking client responses)
* negotiate the options necessary for tn3270 on a new telnet connection
Expand All @@ -20,34 +36,34 @@ public class Telnet {
*/
public static void NegotiateTelnet(BufferedOutputStream out, BufferedInputStream in) {
byte[] _trash = new byte[255];
byte[] _t = {(byte) 0xff, (byte) 0xfd, 0x18};
byte[] _t = {IAC,DO,TERMINALTYPE};

try {
out.write(_t);
out.flush();
in.read(_trash);

byte[] _2t = {(byte) 0xff, (byte) 0xfd, 0x18, 0x01, (byte) 0xff, (byte) 0xf0};
byte[] _2t = {IAC,SB,TERMINALTYPE,SEND,IAC,SE};
out.write(_2t);
out.flush();

in.read(_trash);

byte[] _3t = {(byte) 0xff, (byte) 0xfd, 0x19};
byte[] _3t = {IAC,DO,EOR};

out.write(_3t);
out.flush();

in.read(_trash);

byte[] _4t = {(byte) 0xff, (byte) 0xfd, 0x00};
byte[] _4t = {IAC,DO,BINARY};

out.write(_4t);
out.flush();

in.read(_trash);

byte[] _5t = {(byte) 0xff, (byte) 0xfd, 0x19, (byte) 0xff, (byte) 0xfb, 0x00};
byte[] _5t = {IAC,WILL,EOR,IAC,WILL,BINARY};

out.write(_5t);
out.flush();
Expand Down

0 comments on commit 78a746a

Please sign in to comment.