diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-07-15 19:47:41 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-07-15 19:47:41 +0200 |
commit | c6ba94c4087c2145639492a2fd21d647138a9a6d (patch) | |
tree | c3dc4f3d39f53e06c0e44f16343bf3499aec3e25 /misc/main.go | |
parent | e2e488e5afad6e584eea894b0de5c68b78bea5db (diff) |
Separate helper network functions
Diffstat (limited to 'misc/main.go')
-rw-r--r-- | misc/main.go | 40 |
1 files changed, 7 insertions, 33 deletions
diff --git a/misc/main.go b/misc/main.go index ecbb32e..4639621 100644 --- a/misc/main.go +++ b/misc/main.go @@ -1,12 +1,13 @@ package main import ( - "encoding/binary" "encoding/hex" "flag" "fmt" "log" "net" + + "dim13.org/asn1/tde" ) /* Limits @@ -202,30 +203,6 @@ var ext = []byte{ * A0 00 MonitorFilter? */ -var nbo = binary.BigEndian // Network Byte Order - -func send(c net.Conn, b []byte) { - size := int16(len(b)) - if err := binary.Write(c, nbo, size); err != nil { - log.Fatal(err) - } - if err := binary.Write(c, nbo, b); err != nil { - log.Fatal(err) - } -} - -func recv(c net.Conn) []byte { - var size int16 - if err := binary.Read(c, nbo, &size); err != nil { - log.Fatal(err) - } - r := make([]byte, size) - if err := binary.Read(c, nbo, r); err != nil { - log.Fatal(err) - } - return r -} - func dump(b []byte) { fmt.Println(hex.Dump(b)) } @@ -233,8 +210,8 @@ func dump(b []byte) { func Ask(c net.Conn, out []byte) []byte { log.Println("Ask") dump(out) - send(c, out) - in := recv(c) + tde.Send(c, out) + in := tde.Recv(c) log.Printf("Packet length: 0x%.2X\n", len(in)) dump(in) return in @@ -242,20 +219,17 @@ func Ask(c net.Conn, out []byte) []byte { func Status(c net.Conn) { log.Println("Status") - in := recv(c) + in := tde.Recv(c) log.Printf("Packet length: 0x%.2X\n", len(in)) dump(in) out := status out[4] = in[4] dump(out) - send(c, out) + tde.Send(c, out) } func main() { - conn, err := net.Dial("tcp", *service) - if err != nil { - log.Fatal(err) - } + conn := tde.Dial(*service) defer conn.Close() Ask(conn, associate) |