-
Notifications
You must be signed in to change notification settings - Fork 23
/
debug.go
41 lines (38 loc) · 834 Bytes
/
debug.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
package radius
import (
"fmt"
)
func asString(a AttributeType) bool {
bytes := map[AttributeType]bool{
UserName: true,
CallingStationId: true,
CalledStationId: true,
NASIdentifier: true,
ReplyMessage: true,
AcctSessionId: true,
ConnectInfo: true,
}
return bytes[a]
}
/*
type Packet struct {
secret string // shared secret
Code PacketCode
Identifier uint8
Len uint16
Auth []byte // Request Authenticator
Attrs []AttrEncoder
}
*/
func debug(p *Packet) string {
s := fmt.Sprintf("Code=%s Ident=%d\n", p.Code, p.Identifier)
for _, attr := range p.Attrs {
b := attr.Bytes()
if asString(attr.Type()) {
s += fmt.Sprintf("\t%s = %s\n", attr.Type(), string(b))
} else {
s += fmt.Sprintf("\t%s = %+v\n", attr.Type(), b)
}
}
return s + "\n"
}