File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,36 @@ func (r *Reader) findAddressInTree(ipAddress net.IP) (uint, error) {
212
212
return 0 , newInvalidDatabaseError ("invalid node in search tree" )
213
213
}
214
214
215
+ func (r * Reader ) Netmask (ipAddress net.IP ) (uint , error ) {
216
+
217
+ bitCount := uint (len (ipAddress ) * 8 )
218
+
219
+ var node , i uint
220
+ if bitCount == 32 {
221
+ node = r .ipv4Start
222
+ }
223
+
224
+ nodeCount := r .Metadata .NodeCount
225
+
226
+ for i = uint (0 ); i < bitCount && node < nodeCount ; i ++ {
227
+ bit := uint (1 ) & (uint (ipAddress [i >> 3 ]) >> (7 - (i % 8 )))
228
+
229
+ var err error
230
+ node , err = r .readNode (node , bit )
231
+ if err != nil {
232
+ return 0 , err
233
+ }
234
+ }
235
+ if node == nodeCount {
236
+ // Record is empty
237
+ return 0 , nil
238
+ } else if node > nodeCount {
239
+ return i , nil
240
+ }
241
+
242
+ return 0 , newInvalidDatabaseError ("invalid node in search tree" )
243
+ }
244
+
215
245
func (r * Reader ) readNode (nodeNumber uint , index uint ) (uint , error ) {
216
246
RecordSize := r .Metadata .RecordSize
217
247
You can’t perform that action at this time.
0 commit comments