Hello.

I'm needing to store the IP adress as a variable in my application.
I was then wondering, what the most efficient way of doing this would be?

I would simply make 4 integers, and then in a setter function, read four arguments, and pass them into those four integers, and checking if it is valid for an ip. Ex. int1 = 192; int2 = 168; int3 = 1; int4 = 1;

I imagine than using hex in some way would be best? Whats your suggestion? :D

Thanks!

Well, since an IP address is a 32-bit integral value (IPv4), I would probably use a 32-bit unsigned integer.

I'm just wondering then, what about an IP like 87.185.83.120? Would I store it in the integer as 87185083120 and then assume a 0 at front for each "missing" digit?

This article has been dead for over six months. Start a new discussion instead.