Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. format of MIB_IPFORWARDROW structure?

format of MIB_IPFORWARDROW structure?

Scheduled Pinned Locked Moved C#
sysadminhelpquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    b_girl
    wrote on last edited by
    #1

    Hey, I'm making use of Iphlpapi.dll, particularily CreateIpForwardEntry(ref PMIB_IPFORWARDROW pRoute) I'm a little unclear as to what format I need to be using for the MIB_IPFORWARDROW structure This is my declaration (?) of the structure: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct PMIB_IPFORWARDROW { public UInt32 dwForwardDest; public UInt32 dwForwardMask; public UInt32 dwForwardPolicy; public UInt32 dwForwardNextHop; public UInt32 dwForwardIfIndex; public UInt32 dwForwardType; public UInt32 dwForwardProto; public UInt32 dwForwardAge; public UInt32 dwForwardNextHopAS; public UInt32 dwForwardMetric1; public UInt32 dwForwardMetric2; public UInt32 dwForwardMetric3; public UInt32 dwForwardMetric4; public UInt32 dwForwardMetric5; } The ones I'm most confused about are dwForwardDest, dwForwardMask and dwForwardNextHop. If I had a destination network of 10.11.0.0, mask 255.255.0.0 and the 'next hop' would be say... 10.11.7.3. The corresponding 'route add' command that I normally run from the command line is: route add 10.11.0.0 mask 255.255.0.0 10.11.7.3 I get the feeling that I need to convert each octet to hex, but what do I do from there? Any help would be greatly appreciated...

    G J 2 Replies Last reply
    0
    • B b_girl

      Hey, I'm making use of Iphlpapi.dll, particularily CreateIpForwardEntry(ref PMIB_IPFORWARDROW pRoute) I'm a little unclear as to what format I need to be using for the MIB_IPFORWARDROW structure This is my declaration (?) of the structure: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct PMIB_IPFORWARDROW { public UInt32 dwForwardDest; public UInt32 dwForwardMask; public UInt32 dwForwardPolicy; public UInt32 dwForwardNextHop; public UInt32 dwForwardIfIndex; public UInt32 dwForwardType; public UInt32 dwForwardProto; public UInt32 dwForwardAge; public UInt32 dwForwardNextHopAS; public UInt32 dwForwardMetric1; public UInt32 dwForwardMetric2; public UInt32 dwForwardMetric3; public UInt32 dwForwardMetric4; public UInt32 dwForwardMetric5; } The ones I'm most confused about are dwForwardDest, dwForwardMask and dwForwardNextHop. If I had a destination network of 10.11.0.0, mask 255.255.0.0 and the 'next hop' would be say... 10.11.7.3. The corresponding 'route add' command that I normally run from the command line is: route add 10.11.0.0 mask 255.255.0.0 10.11.7.3 I get the feeling that I need to convert each octet to hex, but what do I do from there? Any help would be greatly appreciated...

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Converting each octet to hex doesn't get you any closer to a number. Instead you should convert each octet into a number, shift them and add them together. For an example, the IP number 10.11.7.3 would add up as: (10 << 24) + (11 << 16) + (7 << 8) + 3

      --- b { font-weight: normal; }

      B 1 Reply Last reply
      0
      • B b_girl

        Hey, I'm making use of Iphlpapi.dll, particularily CreateIpForwardEntry(ref PMIB_IPFORWARDROW pRoute) I'm a little unclear as to what format I need to be using for the MIB_IPFORWARDROW structure This is my declaration (?) of the structure: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct PMIB_IPFORWARDROW { public UInt32 dwForwardDest; public UInt32 dwForwardMask; public UInt32 dwForwardPolicy; public UInt32 dwForwardNextHop; public UInt32 dwForwardIfIndex; public UInt32 dwForwardType; public UInt32 dwForwardProto; public UInt32 dwForwardAge; public UInt32 dwForwardNextHopAS; public UInt32 dwForwardMetric1; public UInt32 dwForwardMetric2; public UInt32 dwForwardMetric3; public UInt32 dwForwardMetric4; public UInt32 dwForwardMetric5; } The ones I'm most confused about are dwForwardDest, dwForwardMask and dwForwardNextHop. If I had a destination network of 10.11.0.0, mask 255.255.0.0 and the 'next hop' would be say... 10.11.7.3. The corresponding 'route add' command that I normally run from the command line is: route add 10.11.0.0 mask 255.255.0.0 10.11.7.3 I get the feeling that I need to convert each octet to hex, but what do I do from there? Any help would be greatly appreciated...

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        Hi The following CP comment should help you: http://www.codeproject.com/cs/internet/iphlpapi.asp?msg=1122768&target=netstat#xx1122768xx[^]

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Frist Psot! From Windows Live Writer The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        B 1 Reply Last reply
        0
        • J Judah Gabriel Himango

          Hi The following CP comment should help you: http://www.codeproject.com/cs/internet/iphlpapi.asp?msg=1122768&target=netstat#xx1122768xx[^]

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Frist Psot! From Windows Live Writer The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          B Offline
          B Offline
          b_girl
          wrote on last edited by
          #4

          I did see that earlier but it doesn't show the format I need to put the IP addresses in so that they are accepted. For example dwForwardDest = 10.11.0.0 would obviously not be correct.

          1 Reply Last reply
          0
          • G Guffa

            Converting each octet to hex doesn't get you any closer to a number. Instead you should convert each octet into a number, shift them and add them together. For an example, the IP number 10.11.7.3 would add up as: (10 << 24) + (11 << 16) + (7 << 8) + 3

            --- b { font-weight: normal; }

            B Offline
            B Offline
            b_girl
            wrote on last edited by
            #5

            I apologize, but I don't really understand what you're instructing me to do, what does (10 << 24) + ... mean? Does anyone maybe have a bit of example code I could use as a guideline? I've found minimal assistance online so far..

            G 1 Reply Last reply
            0
            • B b_girl

              I apologize, but I don't really understand what you're instructing me to do, what does (10 << 24) + ... mean? Does anyone maybe have a bit of example code I could use as a guideline? I've found minimal assistance online so far..

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              The << operator shifts the first operand to the left the number of bits specificed by the second operand. As you have four bytes which should be positioned after each other in the uint, you shift the values to place the bytes at the correct position before adding them. In binary it looks like this: 10 = 00001010 11 = 00001011 7 = 00000111 3 = 00000011 10 << 24 = 00001010000000000000000000000000 11 << 16 = 00000000000010110000000000000000 7 << 8 = 00000000000000000000011100000000 3 = 00000000000000000000000000000011 Adding them together gives the value: 00001010000010110000011100000011 Example code:

              uint o1 = 10;
              uint o2 = 11;
              uint o3 = 7;
              uint o4 = 3;
              uint code = (o1 << 24) + (o2 << 16) + (o3 << 8) + o4;

              --- b { font-weight: normal; }

              B 1 Reply Last reply
              0
              • G Guffa

                The << operator shifts the first operand to the left the number of bits specificed by the second operand. As you have four bytes which should be positioned after each other in the uint, you shift the values to place the bytes at the correct position before adding them. In binary it looks like this: 10 = 00001010 11 = 00001011 7 = 00000111 3 = 00000011 10 << 24 = 00001010000000000000000000000000 11 << 16 = 00000000000010110000000000000000 7 << 8 = 00000000000000000000011100000000 3 = 00000000000000000000000000000011 Adding them together gives the value: 00001010000010110000011100000011 Example code:

                uint o1 = 10;
                uint o2 = 11;
                uint o3 = 7;
                uint o4 = 3;
                uint code = (o1 << 24) + (o2 << 16) + (o3 << 8) + o4;

                --- b { font-weight: normal; }

                B Offline
                B Offline
                b_girl
                wrote on last edited by
                #7

                OOOhhhhh that makes sense! Thanks a ton. Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...

                G L 2 Replies Last reply
                0
                • B b_girl

                  OOOhhhhh that makes sense! Thanks a ton. Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  uint is just a synonyme for System.UInt32.

                  --- b { font-weight: normal; }

                  1 Reply Last reply
                  0
                  • B b_girl

                    OOOhhhhh that makes sense! Thanks a ton. Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    b_girl wrote:

                    Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...

                    It's the same, sort of. uint is a C# keyword for the System.UInt32 .NET type. However, be careful using an unsigned int. It's not CLS compilant, which means that there may exist other .NET languages that might not support unsigned integers/longs. As long as you use this struct only in your application/dll where the code is not readable from outside (marked as internal, the default one), then you're safe. But if you plan to use this code within another .NET language which does not support unsigned data types, the you must use int instead of uint regards

                    B 1 Reply Last reply
                    0
                    • L Lost User

                      b_girl wrote:

                      Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...

                      It's the same, sort of. uint is a C# keyword for the System.UInt32 .NET type. However, be careful using an unsigned int. It's not CLS compilant, which means that there may exist other .NET languages that might not support unsigned integers/longs. As long as you use this struct only in your application/dll where the code is not readable from outside (marked as internal, the default one), then you're safe. But if you plan to use this code within another .NET language which does not support unsigned data types, the you must use int instead of uint regards

                      B Offline
                      B Offline
                      b_girl
                      wrote on last edited by
                      #10

                      Thanks... I'll keep that in mind :)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups