Skip to content

Commit

Permalink
Minor Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikubill committed Jan 20, 2020
1 parent c1fda77 commit 2323df5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,20 @@ func cmd() {
switch {
case contains(commands, os.Args[1]):
execute(strings.Join(os.Args[1:], " ") + " | " + os.Args[0])
os.Exit(0)
case contains(help, os.Args[1]):
fmt.Printf(helper, os.Args[0])
os.Exit(0)
case contains(ver, os.Args[1]):
_version()
os.Exit(0)
case os.Args[1] == "update":
_update(false, contains(os.Args, "--force"))
os.Exit(0)
case os.Args[1] == "delete":
_update(true, contains(os.Args, "--force"))
os.Exit(0)
}
os.Exit(0)
}

func _version() {
Expand Down Expand Up @@ -217,7 +221,7 @@ func ipv6Update(force bool, del bool) {
filename := "ipv6.dat"
if _, err := os.Stat(filename); err == nil || os.IsExist(err) {
if force != true {
if del != true {
if del == true {
question("删除现有 IPv6 数据库", "正在删除 IPv6 数据库...")
} else {
question("更新现有 IPv6 数据库", "")
Expand All @@ -242,7 +246,7 @@ func allUpdate(force bool, del bool) {
_, er2 := os.Stat("ipv6.dat")
if er1 == nil || er2 == nil {
if force != true {
if del != true {
if del == true {
question("删除现有所有 IP 数据库", "正在删除数据库...")
} else {
question("更新现有所有 IP 数据库", "")
Expand Down
8 changes: 4 additions & 4 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (q *pointer) searchIndexV4(ip uint32) uint32 {
_ip := binary.LittleEndian.Uint32(buf[:q.ItemLen])

if end-start == q.IndexLen {
if ip > _ip {
if ip >= binary.LittleEndian.Uint32(q.Data.Data[end:end+q.ItemLen]) {
buf = q.Data.Data[end : end+q.IndexLen]
}
return byteToUInt32(buf[q.ItemLen:])
Expand Down Expand Up @@ -200,9 +200,9 @@ func (q *pointer) searchIndexV6(ip uint64) uint32 {
_ip := binary.LittleEndian.Uint64(buf[:q.ItemLen])

if end-start == q.IndexLen {
//if ip > _ip {
// buf = q.Data.Data[end : end+q.IndexLen]
//}
if ip >= binary.LittleEndian.Uint64(q.Data.Data[end:end+q.ItemLen]) {
buf = q.Data.Data[end : end+q.IndexLen]
}
return byteToUInt32(buf[q.ItemLen:])
}

Expand Down

0 comments on commit 2323df5

Please sign in to comment.