0

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.

Veverke
  • 101
  • 4
  • 1
    IP prefixes and subnets are conceptually very similar, yes.

    When you see subnet 192.0.2.0/24 written out, the first 24-bits of 192.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:31
  • @JeffWheeler: thanks for the guidance! – Veverke Sep 24 '20 at 21:47
  • 1
    My follow up on the topic. – Veverke Sep 24 '20 at 22:23
  • By the way I am not sure the answer referred above answers this question, as the answer shows how to calculate the prefix length, but I need not only the length. Jeff, based on your comment above, by knowing the length I can infer the prefix itself, since I should take the N length first bits of the ip as the prefix. But does this go hand in hand with the method for calculating the prefix length in the selected answer to this post ? you take into account the significant bits only to determine the length - but to get the prefix itself, you consider the original ip, right ? – Veverke Sep 25 '20 at 05:22
  • That's one way to think of it, yes. If a host has IP address 192.0.2.55 and that's been assigned from a subnet 192.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

0 Answers0