summaryrefslogtreecommitdiff
path: root/pkg/auth/sip2/telnet.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-01-24 22:34:09 -0600
committerkali kaneko (leap communications) <kali@leap.se>2020-01-24 22:35:54 -0600
commit1c9220e04016d035c3c688c315ceabe274f45dfc (patch)
tree796488fe592e117fd97781a018bc4b2060a0672d /pkg/auth/sip2/telnet.go
parentd3b21e5adc27cbb472e688b7c602e3bd721dec31 (diff)
initial sip implementation
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)
+}