It sounds like someone is using little-endian and someone is using network byte order (big-endian) for the packed value. For instance the octect sequence compromising an integer, AA,BB,CC,DD
in LE is DD,CC,BB,AA
in BE/NBO -- a nice symmetrical reverse!
Since the IPAddress(Int64) constructor documentations says:
The Int64 value is assumed to be in network byte order.
I would imagine that ip2long
in PHP is generating a value in little-endian. Good thing IPAddress
also takes byte[]
for the constructor, now get those elbows greasy... just pass the bytes in the "correct" order.
Happy coding.
The code at How to convert an int to a little endian byte array? should give some ideas.
Or, as Josh points out, there is a HostToNetworkOrder method to do this.