Page 1 of 1
Subnets?
Posted: Sat Apr 21, 2007 10:27 pm
by pcmattman
Does anyone know how I can figure out, if all I have is a subnet mask and an IP address, if the IP address is a part of a particular subnet?
I need to figure this out because my ethernet routines need to resolve IP addresses to hostnames and if the IP to send to isn't on the same subnet as the computer to send to, I need to send the ethernet packet to the gateway.
Posted: Sat Apr 21, 2007 10:37 pm
by Kevin McGuire
Code: Select all
u32 NETWORK, SUBNETMASK, HOST, IP;
NETWORK = IP & SUBNETMASK
HOST = IP & (~SUBNETMASK)
BROADCAST = NETWORK | (~SUBNETMASK);
11111111.11111111.11111111.00000000 = 255.255.255.0 (NETMASK)
11011101.10101111.10110111.11011111 = a.b.c.d (IP)
00000000.00000000.00000000.11111111 = 0.0.0.255 (HOST)
Posted: Sat Apr 21, 2007 10:41 pm
by pcmattman
Thankyou, that's what I needed.
Posted: Sat Apr 21, 2007 10:50 pm
by Kevin McGuire
Do not forget about throwing together a DNS hack to get some basic support while you are working on it. You can just about ignore all the complicated stuff when doing it for the first time.
Posted: Sat Apr 21, 2007 10:52 pm
by pcmattman
Well, now I can ping Google's servers (by using the IP) and any other computer because the ethernet layer handles physical addresses.
DNS is next thing on my list to implement, then continue on my TCP code (and probably UDP too).
Edit: wait... I'm going to have to implement UDP first.