Skip to content

Commit

Permalink
处理非法 IP 地址请求
Browse files Browse the repository at this point in the history
  • Loading branch information
freshcn committed Jan 22, 2016
1 parent 22e8281 commit 4544e9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ _testmain.go
.idea
qqwry.iml
qqwry.dat
qqwry
qqwry
qqwry_linux_amd64
17 changes: 15 additions & 2 deletions qqwry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net"
"os"
"strings"
)

var IpData fileData
Expand Down Expand Up @@ -62,8 +63,17 @@ func (this *QQwry) ReadData(num int, offset ...int64) (rs []byte) {
this.SetOffset(offset[0])
}
nums := int64(num)
rs = this.Data.Data[this.Offset : this.Offset+nums]
this.Offset += nums
end := this.Offset+nums
dataNum := int64(len(this.Data.Data))
if (this.Offset > dataNum) {
return nil
}

if (end > dataNum) {
end = dataNum
}
rs = this.Data.Data[this.Offset : end]
this.Offset = end
return
}

Expand All @@ -77,6 +87,9 @@ func (this *QQwry) Find(ip string) (res resultQQwry) {
res = resultQQwry{}

res.Ip = ip
if strings.Count(ip, ".") != 3 {
return res
}
offset := this.searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
if offset <= 0 {
return
Expand Down

0 comments on commit 4544e9e

Please sign in to comment.