I know barely nothing about computer networks. I am currently porting some windows code to linux, using .NET core. Some parts have not been implemented for linux, and determining an IP prefix is one of them. I am searching the web in order to understand what is an IP prefix to start with, and, ultimately, figure out if I can determine the logic to define the prefix for a given IP.
To be more specific, the code actually only cares to determine the "prefix origin" of the ip - or, in the documentation terms: specifies how an IP address network prefix was located
". The possible values for this piece of data are
Other = 0,
Manual,
WellKnown,
Dhcp,
RouterAdvertisement,
First question: Are IP prefix/suffixes the same topic as subnetwork? In laymen terms, a prefix identifies the sender (network component that sent the packet) and the suffix the destination ?
Now, the main question: Given an IP address (either v4 or v6), is there a simple deterministic way to define its prefix ? If v6 makes things more complex, I would still be happy to know how to handle v4 ips.
When you see subnet
192.0.2.0/24
written out, the first 24-bits of192.0.2.0
are the prefix.24
is the prefix length.The remaining part of your question would be answered better by a .NET community or other section of Stack Exchange more suited to software development. I don't know which specific library call you're invoking, but if you're examining the subnets configured on an interface, the resulting MIB_x_ROW structure should indicate the prefix length.
– Jeff Wheeler Sep 24 '20 at 21:31192.0.2.55
and that's been assigned from a subnet192.0.2.0/24
which is used on its LAN, the first 24 bits of the IP address will be equal for all IP addresses within that subnet. That's how the host knows if other addresses are within its configured subnet. – Jeff Wheeler Sep 25 '20 at 12:54