forked from sijms/go-ora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect_packet.go
71 lines (65 loc) · 1.59 KB
/
redirect_packet.go
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
package network
import (
"encoding/binary"
)
type RedirectPacket struct {
packet Packet
redirectAddr string
reconnectData string
}
func (pck *RedirectPacket) bytes() []byte {
output := pck.packet.bytes()
data := append([]byte(pck.redirectAddr), 0)
data = append(data, []byte(pck.reconnectData)...)
binary.BigEndian.PutUint16(output[8:], uint16(len(data)))
output = append(output, data...)
return output
}
func (pck *RedirectPacket) getPacketType() PacketType {
return pck.packet.packetType
}
func newRedirectPacketFromData(packetData []byte) *RedirectPacket {
if len(packetData) < 10 {
return nil
}
pck := RedirectPacket{
packet: Packet{
dataOffset: 10,
length: uint32(binary.BigEndian.Uint16(packetData)),
packetType: PacketType(packetData[4]),
flag: packetData[5],
},
}
//data := string(packetData[10 : 10+dataLen])
//if pck.packet.flag&0x2 == 0 {
// pck.redirectAddr = data
// return &pck
//}
//length := strings.Index(data, "\x00")
//if length > 0 {
// pck.redirectAddr = data[:length]
// pck.reconnectData = data[length:]
//} else {
// pck.redirectAddr = data
//}
return &pck
}
//func (pck *RedirectPacket) findValue(key string) string {
// redirectAddr := strings.ToUpper(pck.redirectAddr)
// start := strings.Index(redirectAddr, key)
// if start < 0 {
// return ""
// }
// end := strings.Index(redirectAddr[start:], ")")
// if end < 0 {
// return ""
// }
// end = start + end
// substr := pck.redirectAddr[start:end]
// words := strings.Split(substr, "=")
// if len(words) == 2 {
// return strings.TrimSpace(words[1])
// } else {
// return ""
// }
//}