summaryrefslogtreecommitdiff
path: root/pkg/auth/sip2/telnet.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/auth/sip2/telnet.go')
-rw-r--r--pkg/auth/sip2/telnet.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/pkg/auth/sip2/telnet.go b/pkg/auth/sip2/telnet.go
new file mode 100644
index 0000000..b5abd5f
--- /dev/null
+++ b/pkg/auth/sip2/telnet.go
@@ -0,0 +1,43 @@
+package sip2
+
+import (
+ "github.com/reiver/go-telnet"
+)
+
+// TODO depends on how terminator is configured -- take it from config file
+// const terminator string = "\r\n"
+const terminator string = "\r"
+
+func telnetRead(conn *telnet.Conn) (out string) {
+ var buffer [1]byte
+ recvData := buffer[:]
+ var n int
+ var err error
+
+ for {
+ n, err = conn.Read(recvData)
+ if n <= 0 || err != nil {
+ break
+ } else {
+ out += string(recvData)
+ }
+ if len(out) > 1 && out[len(out)-len(terminator):] == terminator {
+ break
+ }
+ }
+ return out
+}
+
+func telnetSend(conn *telnet.Conn, command string) {
+ var commandBuffer []byte
+ for _, char := range command {
+ commandBuffer = append(commandBuffer, byte(char))
+ }
+
+ var crlfBuffer [2]byte = [2]byte{'\r', '\n'}
+
+ crlf := crlfBuffer[:]
+
+ conn.Write(commandBuffer)
+ conn.Write(crlf)
+}