File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -122,13 +122,8 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
122
122
for {
123
123
if node .pointer == r .Metadata .NodeCount {
124
124
if n .includeEmptyNetworks {
125
- ip := node .ip
126
- if isInIPv4Subtree (ip ) {
127
- ip = v6ToV4 (ip )
128
- }
129
-
130
125
ok := yield (Result {
131
- ip : ip ,
126
+ ip : mappedIP ( node . ip ) ,
132
127
offset : notFound ,
133
128
prefixLen : uint8 (node .bit ),
134
129
})
@@ -146,15 +141,10 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
146
141
}
147
142
148
143
if node .pointer > r .Metadata .NodeCount {
149
- ip := node .ip
150
- if isInIPv4Subtree (ip ) {
151
- ip = v6ToV4 (ip )
152
- }
153
-
154
144
offset , err := r .resolveDataPointer (node .pointer )
155
145
ok := yield (Result {
156
146
decoder : r .decoder ,
157
- ip : ip ,
147
+ ip : mappedIP ( node . ip ) ,
158
148
offset : uint (offset ),
159
149
prefixLen : uint8 (node .bit ),
160
150
err : err ,
@@ -202,6 +192,13 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
202
192
203
193
var ipv4SubtreeBoundary = netip .MustParseAddr ("::255.255.255.255" ).Next ()
204
194
195
+ func mappedIP (ip netip.Addr ) netip.Addr {
196
+ if isInIPv4Subtree (ip ) {
197
+ return v6ToV4 (ip )
198
+ }
199
+ return ip
200
+ }
201
+
205
202
// isInIPv4Subtree returns true if the IP is in the database's IPv4 subtree.
206
203
func isInIPv4Subtree (ip netip.Addr ) bool {
207
204
return ip .Is4 () || ip .Less (ipv4SubtreeBoundary )
You can’t perform that action at this time.
0 commit comments