mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2025-08-17 22:13:50 +02:00
Refactor and add tests
This commit is contained in:
parent
ecfa9e6cf4
commit
4e99b4e88f
4 changed files with 119 additions and 31 deletions
|
@ -4,7 +4,10 @@ import (
|
|||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"github.com/bolkedebruin/rdpgw/transport"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
func createPacket(pktType uint16, data []byte) (packet []byte) {
|
||||
|
@ -34,4 +37,35 @@ func readHeader(data []byte) (packetType uint16, size uint32, packet []byte, err
|
|||
return packetType, size, data[8:], nil
|
||||
}
|
||||
|
||||
// sends data wrapped inside the rdpgw protocol
|
||||
func forward(in net.Conn, out transport.Transport) {
|
||||
defer in.Close()
|
||||
|
||||
b1 := new(bytes.Buffer)
|
||||
buf := make([]byte, 4086)
|
||||
|
||||
for {
|
||||
n, err := in.Read(buf)
|
||||
if err != nil {
|
||||
log.Printf("Error reading from local conn %s", err)
|
||||
break
|
||||
}
|
||||
binary.Write(b1, binary.LittleEndian, uint16(n))
|
||||
b1.Write(buf[:n])
|
||||
out.WritePacket(createPacket(PKT_TYPE_DATA, b1.Bytes()))
|
||||
b1.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
// receive data from the wire, unwrap and forward to the client
|
||||
func receive(data []byte, out net.Conn) {
|
||||
buf := bytes.NewReader(data)
|
||||
|
||||
var cblen uint16
|
||||
binary.Read(buf, binary.LittleEndian, &cblen)
|
||||
pkt := make([]byte, cblen)
|
||||
binary.Read(buf, binary.LittleEndian, &pkt)
|
||||
|
||||
out.Write(pkt)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue