Here's the relevent piece of code:
Code: Select all
# convert dotted quad ip to long ip
proc inet_addr { ipaddr } {
set addr [binary format c4 [split $ipaddr .]]
binary scan $addr i bin
return $bin
}
Code: Select all
# convert long ip to dotted quad ip
proc inet_ntoa { ipaddr } {
set bin [binary format i $ipaddr]
binary scan $bin cccc a b c d
set a [expr { ($a + 0x100) % 0x100 }]
set b [expr { ($b + 0x100) % 0x100 }]
set c [expr { ($c + 0x100) % 0x100 }]
set d [expr { ($d + 0x100) % 0x100 }]
#
# Note: this is what was in the original, it presents the dotted quad ip *backwards*...
# I don't know if that is how inet_ntoa normally behaves -rosc
#return "$a.$b.$c.$d"
#
# So, for my purposes, I present the dotted quad ip in the right order.
return "$d.$c.$b.$a"
}
But, if I then take my dotted quad IP and try to run it through the inet_addr proc, it produces a number nowhere near the number eggdrop uses in its log.
For example:
<rosc> .long2quad 3473389373 (this is the number in eggdrop's log)
<TheEntity> Long IP To Dotted Quad IP: 207.7.183.61
<rosc> .quad2long 207.7.183.61
<TheEntity> Dotted Quad IP To Long IP: 1035405263
Curiously, if I then run that longip back through, I get my ip back, backwards:
<rosc> .long2quad 1035405263
<TheEntity> Long IP To Dotted Quad IP: 61.183.7.207
My question is, how to fix the proc inet_addr thing to give me the same longip number that eggdrop itself uses? I'm guessing that the proc as written, uses a different base than what eggdrop is using.
BTW, I found the above bits of code here:
http://www.mail-archive.com/aolserver@l ... 02599.html