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. managed and unmanaged code............

managed and unmanaged code............

Scheduled Pinned Locked Moved C#
csharpsysadminperformance
2 Posts 2 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.
  • 3 Offline
    3 Offline
    3bood ghzawi
    wrote on last edited by
    #1

    Hi all, pardon me, I need helping at the following code. When I run this code to get the IP address (at statement Console.WriteLine(ipAddress)) I get the IP address, subnet mask and network family at this maner: 169.254.25.129 255.255.0.0 255.255.255.255 but I need to get each of them uniqly (each one alone of others), and I need to get these using this code of the programe (this code from SharpPcap.2-1-1)…. Regards………………………….. public Sockaddr(IntPtr sockaddrPtr) { // A sockaddr struct. We use this to determine the address family PcapUnmanagedStructures.sockaddr saddr; // Marshal memory pointer into a struct saddr = (PcapUnmanagedStructures.sockaddr)Marshal.PtrToStructure(sockaddrPtr, typeof(PcapUnmanagedStructures.sockaddr)); // record the sa_family for informational purposes _sa_family = saddr.sa_family; byte[] addressBytes; if(saddr.sa_family == Pcap.AF_INET) { type = Type.AF_INET_AF_INET6; PcapUnmanagedStructures.sockaddr_in saddr_in = (PcapUnmanagedStructures.sockaddr_in)Marshal.PtrToStructure(sockaddrPtr, typeof(PcapUnmanagedStructures.sockaddr_in)); ipAddress = new System.Net.IPAddress(saddr_in.sin_addr.s_addr); Console.WriteLine(ipAddress); } }// end of Sockaddr function ///////////////////////////////////////////////////////////////////////////////// // A PcapUnmanagedStructures class is here: public class PcapUnmanagedStructures { #region Unmanaged Structs Implementation [StructLayout(LayoutKind.Sequential)] public struct sockaddr { public UInt16 sa_family; /* address family */ [MarshalAs(UnmanagedType.ByValArray, SizeConst=14)] public byte[] sa_data; /* 14 bytes of protocol address */ }; /// <summary> /// Structure that holds an ipv4 address /// </summary> public struct in_addr { public UInt32 s_addr/*= 1111*/; } /// <summary> /// Structure that holds an ipv4 address /// 'struct sockaddr' /// </summary> [StructLayout(LayoutKind.Sequential)] public struct sockaddr_in { public UInt16 sa_family; /* address

    N 1 Reply Last reply
    0
    • 3 3bood ghzawi

      Hi all, pardon me, I need helping at the following code. When I run this code to get the IP address (at statement Console.WriteLine(ipAddress)) I get the IP address, subnet mask and network family at this maner: 169.254.25.129 255.255.0.0 255.255.255.255 but I need to get each of them uniqly (each one alone of others), and I need to get these using this code of the programe (this code from SharpPcap.2-1-1)…. Regards………………………….. public Sockaddr(IntPtr sockaddrPtr) { // A sockaddr struct. We use this to determine the address family PcapUnmanagedStructures.sockaddr saddr; // Marshal memory pointer into a struct saddr = (PcapUnmanagedStructures.sockaddr)Marshal.PtrToStructure(sockaddrPtr, typeof(PcapUnmanagedStructures.sockaddr)); // record the sa_family for informational purposes _sa_family = saddr.sa_family; byte[] addressBytes; if(saddr.sa_family == Pcap.AF_INET) { type = Type.AF_INET_AF_INET6; PcapUnmanagedStructures.sockaddr_in saddr_in = (PcapUnmanagedStructures.sockaddr_in)Marshal.PtrToStructure(sockaddrPtr, typeof(PcapUnmanagedStructures.sockaddr_in)); ipAddress = new System.Net.IPAddress(saddr_in.sin_addr.s_addr); Console.WriteLine(ipAddress); } }// end of Sockaddr function ///////////////////////////////////////////////////////////////////////////////// // A PcapUnmanagedStructures class is here: public class PcapUnmanagedStructures { #region Unmanaged Structs Implementation [StructLayout(LayoutKind.Sequential)] public struct sockaddr { public UInt16 sa_family; /* address family */ [MarshalAs(UnmanagedType.ByValArray, SizeConst=14)] public byte[] sa_data; /* 14 bytes of protocol address */ }; /// <summary> /// Structure that holds an ipv4 address /// </summary> public struct in_addr { public UInt32 s_addr/*= 1111*/; } /// <summary> /// Structure that holds an ipv4 address /// 'struct sockaddr' /// </summary> [StructLayout(LayoutKind.Sequential)] public struct sockaddr_in { public UInt16 sa_family; /* address

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Read How to get an answer to your question[^] and pay attention to item #7


      I know the language. I've read a book. - _Madmatt

      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