-
Notifications
You must be signed in to change notification settings - Fork 12
/
isp.go
49 lines (47 loc) · 1.21 KB
/
isp.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
package geoip2
import "errors"
func readISPMap(result *ISP, buffer []byte, mapSize uint, offset uint) (uint, error) {
var key []byte
var err error
for i := uint(0); i < mapSize; i++ {
key, offset, err = readMapKey(buffer, offset)
if err != nil {
return 0, err
}
switch b2s(key) {
case "autonomous_system_number":
result.AutonomousSystemNumber, offset, err = readUInt32(buffer, offset)
if err != nil {
return 0, err
}
case "autonomous_system_organization":
result.AutonomousSystemOrganization, offset, err = readString(buffer, offset)
if err != nil {
return 0, err
}
case "isp":
result.ISP, offset, err = readString(buffer, offset)
if err != nil {
return 0, err
}
case "organization":
result.Organization, offset, err = readString(buffer, offset)
if err != nil {
return 0, err
}
case "mobile_country_code":
result.MobileCountryCode, offset, err = readString(buffer, offset)
if err != nil {
return 0, err
}
case "mobile_network_code":
result.MobileNetworkCode, offset, err = readString(buffer, offset)
if err != nil {
return 0, err
}
default:
return 0, errors.New("unknown isp key: " + string(key))
}
}
return offset, nil
}