ipip 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7629926327cfecda9e31fa00aa0ad2fb2b593368
4
- data.tar.gz: 5aa69af8174e1463581956f1f21f0da4fb3ded2a
3
+ metadata.gz: 6dbe208c2b3d180ac34233c7ca6d6c3ad7130b9e
4
+ data.tar.gz: 2c24cfda56a8900ec359eb7b4fd4205e62c3d587
5
5
  SHA512:
6
- metadata.gz: 2f50de124e40661d26f1867a84709e52af259dafb73c413b84b9f7f867983eae5840c7d8342e63f534bcde422325067c0396d25ab321bd4ed4e09f696b0ae3fb
7
- data.tar.gz: 715f3af052260f6785da11673219137c7847a2b9b7d967789ab6231337fcf396f9b0e977213ad105ba7b79439c0f0ce648037f7b876fdddacffbb1edfc0218fe
6
+ metadata.gz: 9b96a71626ea307fbb227e3669d41cd630ff34696587d190e0f22402c8c104d77f758516632007f9299d7646199bd8f33c9a0baf2d0896c4d110ff5bb3f1fc55
7
+ data.tar.gz: 55bd9f42dffd62fd4646bd1e95a317e2430a3090029993fa14b5d2114fd854658ab25813d4434d03a6aa02e6c1100d47969b9c8ce4fe8fdc215c4572bb32f50d
@@ -59,8 +59,6 @@ module IPIP
59
59
  start = unpack_V(buffer[first_ip_offset, 4])
60
60
  start_offset = start * IP_BLOCK_SIZE + FIRST_IP_NUMBER_INDEX_SIZE
61
61
 
62
- data_offset = data_length = 0
63
-
64
62
  lo, hi = 0, (offset - start_offset) / IP_BLOCK_SIZE
65
63
 
66
64
  while lo < hi
@@ -76,13 +74,13 @@ module IPIP
76
74
  end
77
75
 
78
76
  start_offset += lo * IP_BLOCK_SIZE
79
- return if start_offset == offset
77
+ return nil if start_offset == offset
80
78
 
81
- data_offset = unpack_V(buffer[start_offset + 4, 3] + 0.chr)
79
+ data_pos = unpack_V(buffer[start_offset + 4, 3] + 0.chr)
82
80
  data_length = unpack_C(buffer[start_offset + 7])
83
81
 
84
- data_offset = offset + data_offset - FIRST_IP_NUMBER_INDEX_SIZE - OFFSET_NUMBER_SIZE
85
- data = buffer[data_offset, data_length].encode('UTF-8', 'UTF-8')
82
+ data_offset = offset + data_pos - FIRST_IP_NUMBER_INDEX_SIZE - OFFSET_NUMBER_SIZE
83
+ data = buffer[data_offset, data_length].to_s.encode('UTF-8', 'UTF-8')
86
84
  end
87
85
 
88
86
  [:C, :N, :V].each do |format|
@@ -1,5 +1,6 @@
1
1
  require 'socket'
2
2
  require 'ipaddr'
3
+ require 'pry'
3
4
 
4
5
  module IPIPX
5
6
 
@@ -7,15 +8,15 @@ module IPIPX
7
8
  #
8
9
  # The IPIP.net data file(ipip.datx) format in bytes::
9
10
  #
10
- # ---------------------------
11
- # | 4 bytes | <- offset number
12
- # ---------------------------
13
- # | 256 * 9 bytes | <- first ip number index
14
- # ---------------------------
15
- # | offset - 2304 - 4 bytes | <- ip index
16
- # ---------------------------
17
- # | data storage |
18
- # ---------------------------
11
+ # ----------------------------------
12
+ # | 4 bytes | <- offset number
13
+ # ----------------------------------
14
+ # | 256 * 1024 bytes | <- first ip number index
15
+ # ----------------------------------
16
+ # | offset - 256 * 1024 - 4 bytes | <- ip index
17
+ # ----------------------------------
18
+ # | data storage |
19
+ # ----------------------------------
19
20
  #
20
21
  class IPv4DatabaseX
21
22
 
@@ -51,7 +52,6 @@ module IPIPX
51
52
  return unless ip.ipv4?
52
53
 
53
54
  nip = ip.hton
54
-
55
55
  first_ip = unpack_C(nip)
56
56
  ipdot = ip.to_s.split('.')
57
57
  first_ip_offset = (first_ip * 256 + ipdot[1].to_i) * 4
@@ -59,9 +59,7 @@ module IPIPX
59
59
  start = unpack_V(buffer[first_ip_offset, 4])
60
60
  start_offset = start * IP_BLOCK_SIZE + FIRST_IP_NUMBER_INDEX_SIZE
61
61
 
62
- data_offset = data_length = -1
63
-
64
- lo, hi = 0, (offset - start_offset) / IP_BLOCK_SIZE
62
+ lo, hi = 0, (offset - start_offset - OFFSET_NUMBER_SIZE) / IP_BLOCK_SIZE
65
63
 
66
64
  while lo < hi
67
65
  mid = (lo + hi) / 2
@@ -78,11 +76,11 @@ module IPIPX
78
76
  start_offset += lo * IP_BLOCK_SIZE
79
77
  return if start_offset == offset
80
78
 
81
- data_offset = unpack_V(buffer[start_offset + 4, 3] + 0.chr)
79
+ data_pos = unpack_V(buffer[start_offset + 4, 3] + 0.chr)
82
80
  data_length = unpack_C(buffer[start_offset + 8])
83
81
 
84
- data_offset = offset + data_offset - FIRST_IP_NUMBER_INDEX_SIZE - OFFSET_NUMBER_SIZE
85
- data = buffer[data_offset, data_length].encode('UTF-8', 'UTF-8')
82
+ data_offset = offset + data_pos - FIRST_IP_NUMBER_INDEX_SIZE - OFFSET_NUMBER_SIZE
83
+ data = buffer[data_offset, data_length].to_s.encode('UTF-8', 'UTF-8')
86
84
  end
87
85
 
88
86
  [:C, :N, :V].each do |format|
@@ -1,3 +1,3 @@
1
1
  module IPIP
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - liluo
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  requirements: []
73
73
  rubyforge_project:
74
- rubygems_version: 2.6.8
74
+ rubygems_version: 2.4.8
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: IP search based on ipip.net