I am writing a program on Linux that requires to to setup itself with a static IP provided by a user but the gateway and subnet mask are not. Is there a way to calculate them? If not, what do you recommend as a solution, where the least preference is to ask the user to enter them.
Well, not the gateway. The gateway IP address can be any valid address on the network. The subnet masks, on the other hand, do have default values. However, I don't know what they are, off the top of my head.
I did more research and I found out some of the things you mentioned.
3 classes with each class having its own unique set of subnets. I had to look into subnets and get a good understanding but I think I have a solution...
Class A, subnets 255.0.0.0 up to 255.255.255.224 (depending on the bit masks and # of bits)
Class B, subnets 255.255.0.0 up to 255.255.255.252 (depending on the bit masks and # of bits)
Class C, subnets 255.255.255.0 up to 255.255.255.252 (depending on the bit masks and # of bits)