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.

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?

Realise that IPv4 runs from 0.0.0.0 to 255.255.255.255
Each dotted number fits neatly into a single byte, that's how it's normally stored.

Yeah, okay - So, you suggest a bytearray? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.