Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
sockaddr_in (Structures)
 
.
Summary
TODO - a short description

C# Definition:

    [StructLayout(LayoutKind.Sequential)]
    internal struct sockaddr_in
    {
        internal EnumLib.ADDRESS_FAMILIES sin_family;
        internal ushort sin_port;
        internal in_addr sin_addr;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] internal byte[] sin_zero;

        internal string Host
        {
        get
        {
            var local = this;
            var length = (uint) 256;
            var builder = new StringBuilder((int) length);

            var data = new WSAData();
            WSAStartup(2, ref data);
            WSAAddressToString(ref local, (uint) Marshal.SizeOf(local), IntPtr.Zero, builder,
                          ref length);
            WSACleanup();

            return builder.ToString().Split(':')[0];
        }

        }

        internal string Port
        {
        get
        {
            var local = this;
            var length = (uint) 256;
            var builder = new StringBuilder((int) length);

            var data = new WSAData();
            WSAStartup(2, ref data);
            WSAAddressToString(ref local, (uint) Marshal.SizeOf(local), IntPtr.Zero, builder,
                          ref length);
            WSACleanup();

            return builder.ToString().Split(':')[1];
        }

        }

        internal static sockaddr_in FromString(string host, int port)
        {
        var sockaddr = new sockaddr_in();
        var lpAddressLength = Marshal.SizeOf(sockaddr);
        WSAStringToAddress(host + ":" + port, EnumLib.ADDRESS_FAMILIES.AF_INET, IntPtr.Zero,
                          ref sockaddr, ref lpAddressLength);
        return sockaddr;
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    internal unsafe struct sockaddr_in_UNSAFE
    {
        internal EnumLib.ADDRESS_FAMILIES sin_family;
        internal ushort sin_port;
        internal in_addr sin_addr;
        internal fixed byte sin_zero [8];

        internal string Host
        {
        get
        {
            var local = this;
            var length = (uint) 256;
            var builder = new StringBuilder((int) length);

            var data = new WSAData();
            WSAStartup(2, ref data);
            WSAAddressToString(ref local, (uint) Marshal.SizeOf(local), IntPtr.Zero, builder,
                          ref length);
            WSACleanup();

            return builder.ToString().Split(':')[0];
        }

        }

        internal string Port
        {
        get
        {
            var local = this;
            var length = (uint) 256;
            var builder = new StringBuilder((int) length);

            var data = new WSAData();
            WSAStartup(2, ref data);
            WSAAddressToString(ref local, (uint) Marshal.SizeOf(local), IntPtr.Zero, builder,
                          ref length);
            WSACleanup();

            return builder.ToString().Split(':')[1];
        }

        }

        internal static sockaddr_in FromString(string host, int port)
        {
        var sockaddr = new sockaddr_in();
        var lpAddressLength = Marshal.SizeOf(sockaddr);
        WSAStringToAddress(host + ":" + port, EnumLib.ADDRESS_FAMILIES.AF_INET, IntPtr.Zero,
                          ref sockaddr, ref lpAddressLength);
        return sockaddr;
        }
    }

VB Definition:

Structure sockaddr_in
   Public TODO
End Structure

User-Defined Field Types:

None.

Notes:

None.

Documentation
sockaddr_in on MSDN

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions