|
30 | 30 | -define(IF(Cond), (case (Cond) of true -> (0); false -> (1) end)). |
31 | 31 |
|
32 | 32 | apiversion() -> |
33 | | - "8.6.2". |
| 33 | + "8.6.3". |
34 | 34 |
|
35 | 35 | getapiversion() -> |
36 | 36 | io:format("API Version: ~p~n", [apiversion()]). |
@@ -302,37 +302,49 @@ searchtree(S, Ipnum, Dbtype, Low, High, BaseAddr, Colsize, Iptype) -> |
302 | 302 | end. |
303 | 303 |
|
304 | 304 | search4(S, Ipnum, Dbtype, Low, High, Baseaddr, Indexbaseaddr, Colsize) -> |
| 305 | + if |
| 306 | + Ipnum == 4294967295 -> |
| 307 | + Ipnum2 = Ipnum - 1; |
| 308 | + true -> |
| 309 | + Ipnum2 = Ipnum |
| 310 | + end, |
305 | 311 | if |
306 | 312 | Indexbaseaddr > 0 -> |
307 | | - Indexpos = ((Ipnum bsr 16) bsl 3) + Indexbaseaddr, |
| 313 | + Indexpos = ((Ipnum2 bsr 16) bsl 3) + Indexbaseaddr, |
308 | 314 | case file:pread(S, Indexpos - 1, 8) of % 4 bytes for each IP From & IP To |
309 | 315 | eof -> |
310 | 316 | io:format("Error: IP address not found.~n", []), |
311 | 317 | {}; % return empty |
312 | 318 | {ok, R} -> |
313 | 319 | Low2 = readuint32row(R, 0), |
314 | 320 | High2 = readuint32row(R, 4), |
315 | | - searchtree(S, Ipnum, Dbtype, Low2, High2, Baseaddr, Colsize, ipv4) |
| 321 | + searchtree(S, Ipnum2, Dbtype, Low2, High2, Baseaddr, Colsize, ipv4) |
316 | 322 | end; |
317 | 323 | true -> |
318 | | - searchtree(S, Ipnum, Dbtype, Low, High, Baseaddr, Colsize, ipv4) |
| 324 | + searchtree(S, Ipnum2, Dbtype, Low, High, Baseaddr, Colsize, ipv4) |
319 | 325 | end. |
320 | 326 |
|
321 | 327 | search6(S, Ipnum, Dbtype, Low, High, Baseaddr, Indexbaseaddr, Colsize) -> |
| 328 | + if |
| 329 | + Ipnum == 340282366920938463463374607431768211455 -> |
| 330 | + Ipnum2 = Ipnum - 1; |
| 331 | + true -> |
| 332 | + Ipnum2 = Ipnum |
| 333 | + end, |
322 | 334 | if |
323 | 335 | Indexbaseaddr > 0 -> |
324 | | - Indexpos = ((Ipnum bsr 112) bsl 3) + Indexbaseaddr, |
| 336 | + Indexpos = ((Ipnum2 bsr 112) bsl 3) + Indexbaseaddr, |
325 | 337 | case file:pread(S, Indexpos - 1, 8) of % 4 bytes for each IP From & IP To |
326 | 338 | eof -> |
327 | 339 | io:format("Error: IP address not found.~n", []), |
328 | 340 | {}; % return empty |
329 | 341 | {ok, R} -> |
330 | 342 | Low2 = readuint32row(R, 0), |
331 | 343 | High2 = readuint32row(R, 4), |
332 | | - searchtree(S, Ipnum, Dbtype, Low2, High2, Baseaddr, Colsize, ipv6) |
| 344 | + searchtree(S, Ipnum2, Dbtype, Low2, High2, Baseaddr, Colsize, ipv6) |
333 | 345 | end; |
334 | 346 | true -> |
335 | | - searchtree(S, Ipnum, Dbtype, Low, High, Baseaddr, Colsize, ipv6) |
| 347 | + searchtree(S, Ipnum2, Dbtype, Low, High, Baseaddr, Colsize, ipv6) |
336 | 348 | end. |
337 | 349 |
|
338 | 350 | query(Ip) -> |
@@ -369,53 +381,20 @@ query(Ip) -> |
369 | 381 | Result = case inet:parse_address(Ip) of |
370 | 382 | {ok, {X1, X2, X3, X4}} -> |
371 | 383 | Ipnum = (X1 bsl 24) + (X2 bsl 16) + (X3 bsl 8) + (X4), |
372 | | - if |
373 | | - Ipnum == 4294967295 -> |
374 | | - Ipnum2 = Ipnum - 1; |
375 | | - true -> |
376 | | - Ipnum2 = Ipnum |
377 | | - end, |
378 | | - search4(S, Ipnum2, Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
| 384 | + search4(S, Ipnum, Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
379 | 385 | {ok, {X1, X2, X3, X4, X5, X6, X7, X8}} -> |
380 | 386 | Ipnum = (X1 bsl 112) + (X2 bsl 96) + (X3 bsl 80) + (X4 bsl 64) + (X5 bsl 48) + (X6 bsl 32) + (X7 bsl 16) + X8, |
381 | 387 | if |
382 | 388 | Ipnum >= Fromv4mapped andalso Ipnum =< Tov4mapped -> |
383 | | - Ipnum2 = Ipnum - Fromv4mapped, |
384 | | - if |
385 | | - Ipnum2 == 4294967295 -> |
386 | | - Ipnum3 = Ipnum2 - 1; |
387 | | - true -> |
388 | | - Ipnum3 = Ipnum2 |
389 | | - end, |
390 | | - search4(S, Ipnum3, Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
| 389 | + search4(S, (Ipnum - Fromv4mapped), Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
391 | 390 | Ipnum >= From6to4 andalso Ipnum =< To6to4 -> |
392 | | - Ipnum2 = (Ipnum bsr 80) band Last32bits, |
393 | | - if |
394 | | - Ipnum2 == 4294967295 -> |
395 | | - Ipnum3 = Ipnum2 - 1; |
396 | | - true -> |
397 | | - Ipnum3 = Ipnum2 |
398 | | - end, |
399 | | - search4(S, Ipnum3, Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
| 391 | + search4(S, ((Ipnum bsr 80) band Last32bits), Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
400 | 392 | Ipnum >= Fromteredo andalso Ipnum =< Toteredo -> |
401 | | - Ipnum2 = (bnot Ipnum) band Last32bits, |
402 | | - if |
403 | | - Ipnum2 == 4294967295 -> |
404 | | - Ipnum3 = Ipnum2 - 1; |
405 | | - true -> |
406 | | - Ipnum3 = Ipnum2 |
407 | | - end, |
408 | | - search4(S, Ipnum3, Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
| 393 | + search4(S, ((bnot Ipnum) band Last32bits), Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize); |
409 | 394 | true -> |
410 | 395 | if |
411 | 396 | Ipv6databasecount > 0 -> |
412 | | - if |
413 | | - Ipnum == 340282366920938463463374607431768211455 -> |
414 | | - Ipnum2 = Ipnum - 1; |
415 | | - true -> |
416 | | - Ipnum2 = Ipnum |
417 | | - end, |
418 | | - search6(S, Ipnum2, Databasetype, 0, Ipv6databasecount, Ipv6databaseaddr, Ipv6indexbaseaddr, Ipv6columnsize); |
| 397 | + search6(S, Ipnum, Databasetype, 0, Ipv6databasecount, Ipv6databaseaddr, Ipv6indexbaseaddr, Ipv6columnsize); |
419 | 398 | true -> |
420 | 399 | io:format("Error: IPv6 address is missing in IPv4 BIN.~n", []), |
421 | 400 | {} % return empty |
|
0 commit comments