title: Unpacking _WTS_CLIENT_ADDRESS.Address in vb.net (retrieving IP address from Terminal Services Client)
body: <p>I have the following structure:</p>
  
  <pre><code>    &lt;StructLayout(LayoutKind.Sequential)&gt; _
      Public Structure _WTS_CLIENT_ADDRESS
          Public AddressFamily As Integer
          &lt;MarshalAs(UnmanagedType.ByValArray, SizeConst:=20)&gt; _
          Public Address() As Byte
      End Structure
  </code></pre>
  
  <p>Which is populated by the following call:</p>
  
  <pre><code>        Dim _ClientIPAddress As New _WTS_CLIENT_ADDRESS
          Dim rtnPtr As IntPtr
          Dim rtncount As Int32
  
          NativeMethods.WTSQuerySessionInformation(CInt(NativeMethods.WTS_CURRENT_SERVER_HANDLE), NativeMethods.WTS_CURRENT_SESSION, NativeMethods.WTS_INFO_CLASS.WTSClientAddress, rtnPtr, rtncount)
          '_ClientIPAddress()
          _ClientIPAddress = _
              CType(System.Runtime.InteropServices.Marshal.PtrToStructure(rtnPtr, GetType(_WTS_CLIENT_ADDRESS)), _WTS_CLIENT_ADDRESS)
  </code></pre>
  
  <p>The address byte array is being populated, but I have no idea how to convert it into a useful string or integer values.  The MDSN documentation is sparse: <a href="http://msdn.microsoft.com/en-us/library/aa383857(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa383857(VS.85).aspx</a></p>