An IPv4 can have more representations: as string (a.b.c.d) or numerical (as an unsigned int of 32 bits). (Maybe other, but I will ignore them.)
Is there any
I would suggest:
long ip2long(){ ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES).order(ByteOrder.BIG_ENDIAN); buffer.put(new byte[] { 0,0,0,0 }); buffer.put(socket.getInetAddress().getAddress()); buffer.position(0); return buffer.getLong(); }