1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use crate::constants::{
BINARY, CHARSET, ECHO, ENVIRON, GA, GMCP, LINEMODE, MCCP2, MSP, MSSP, MXP, NAWS,
REMOTE_FLOW_CONTROL, SGA, STATUS, TELOPT_EOR, TIMING_MARK,
};
/// Represents all Telnet options supported by Nectar.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum TelnetOption {
/// Echo a message back to the other side
Echo,
/// Indicates that the receiver may now send data to the sender.
///
/// This is used in half-duplex connections, where the sender and receiver
/// cannot send data at the same time. If you want bi-directional data
/// transfer, you must set `SuppressGoAhead` on the sender and receiver
/// sides.
GoAhead,
/// Indicates that the communication stream will be bi-directional.
///
/// This must be set on both sides of the data stream independently, even
/// though it is expected that if one side sets it, the other side will also
/// set it.
///
/// See <https://datatracker.ietf.org/doc/html/rfc858> for more information.
SuppressGoAhead,
/// Indicates how EOR (End Of Record) is handled between a sender and
/// receiver. Typically this is marked by Carrige Return and Line Feed. In
/// systems that have a different EOR marker, this option can be used to
/// change the EOR marker.
///
/// Like SuppressGoAhead, this must be set on both sides of the data stream
/// independently - even though it is expected that if one side sets it, the
/// other side will also set it.
///
/// See <https://datatracker.ietf.org/doc/html/rfc885> for more information.
EndOfRecord,
Charset,
MCCP2,
GMCP,
MSSP,
MSP,
MXP,
NAWS,
Status,
TimingMark,
LineMode,
RemoteFlowControl,
Binary,
Environ,
/// A generic marker indicating an unknown option.
Unknown(u8),
}
impl From<u8> for TelnetOption {
fn from(byte: u8) -> Self {
match byte {
ECHO => TelnetOption::Echo,
GA => TelnetOption::GoAhead,
SGA => TelnetOption::SuppressGoAhead,
TELOPT_EOR => TelnetOption::EndOfRecord,
CHARSET => TelnetOption::Charset,
MCCP2 => TelnetOption::MCCP2,
GMCP => TelnetOption::GMCP,
MSSP => TelnetOption::MSSP,
MSP => TelnetOption::MSP,
MXP => TelnetOption::MXP,
NAWS => TelnetOption::NAWS,
STATUS => TelnetOption::Status,
TIMING_MARK => TelnetOption::TimingMark,
LINEMODE => TelnetOption::LineMode,
REMOTE_FLOW_CONTROL => TelnetOption::RemoteFlowControl,
BINARY => TelnetOption::Binary,
ENVIRON => TelnetOption::Environ,
_ => TelnetOption::Unknown(byte),
}
}
}
impl From<TelnetOption> for u8 {
fn from(option: TelnetOption) -> Self {
match option {
TelnetOption::Echo => ECHO,
TelnetOption::GoAhead => GA,
TelnetOption::SuppressGoAhead => SGA,
TelnetOption::EndOfRecord => TELOPT_EOR,
TelnetOption::Charset => CHARSET,
TelnetOption::MCCP2 => MCCP2,
TelnetOption::GMCP => GMCP,
TelnetOption::MSSP => MSSP,
TelnetOption::MSP => MSP,
TelnetOption::MXP => MXP,
TelnetOption::NAWS => NAWS,
TelnetOption::Status => STATUS,
TelnetOption::TimingMark => TIMING_MARK,
TelnetOption::LineMode => LINEMODE,
TelnetOption::RemoteFlowControl => REMOTE_FLOW_CONTROL,
TelnetOption::Binary => BINARY,
TelnetOption::Environ => ENVIRON,
TelnetOption::Unknown(byte) => byte,
}
}
}