Click here to Skip to main content
11,716,938 members (84,838 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET2.0 C# IP VB.NET convert
Im trying to convert code from the article Getting the active TCP/UDP connections using the GetExtendedTcpTable function from C# to VB.net and so far i have everything worked out except for the part that converts the binary data containing the IP and PORT numbers which returns invalid values in VB.net
What it does it just read 4 bytes of information that contains the IP and the 4 bytes that contain the PORT and create a IPEndPoint Object, but in VB.net its returning invalid values.

So far, this is what i got, can someone help me and figure out which part of the code is bad?

public static IPEndPoint BufferToIPEndPoint(byte[] buffer, ref int nOffset, bool IsRemote)
{
    //address
    Int64 m_Address = ((((buffer[nOffset + 3] << 0x18) | (buffer[nOffset + 2] << 0x10)) | (buffer[nOffset + 1] << 8)) | buffer[nOffset]) & ((long)0xffffffff);
    nOffset += 4;
    int m_Port = 0;
    m_Port = (IsRemote && (m_Address == 0))? 0 :
                (((int)buffer[nOffset]) << 8) + (((int)buffer[nOffset + 1])) + (((int)buffer[nOffset + 2]) << 24) + (((int)buffer[nOffset + 3]) << 16);
    nOffset += 4;
    // store the remote endpoint
    IPEndPoint temp = new IPEndPoint(m_Address, m_Port);
    return temp;
}


Public Shared Function BufferToIPEndPoint(buffer As Byte(), ByRef nOffset As Integer, IsRemote As Boolean) As IPEndPoint
    'address
    Dim m_Address As Int64 = ((((buffer(nOffset + 3) << &H18) Or (buffer(nOffset + 2) << &H10)) Or (buffer(nOffset + 1) << 8)) Or buffer(nOffset)) And CLng(&HffffffffUI)
    nOffset += 4
    Dim m_Port As Integer = 0
    m_Port = If((IsRemote AndAlso (m_Address = 0)), 0, (CInt(buffer(nOffset)) << 8) + CInt(buffer(nOffset + 1)) + (CInt(buffer(nOffset + 2)) << 24) + (CInt(buffer(nOffset + 3)) << 16))
    nOffset += 4
    ' store the remote endpoint
    Dim temp As New IPEndPoint(m_Address, m_Port)
    Return temp
End Function
Posted 17-Jan-11 19:54pm
Edited 17-Jan-11 20:11pm
v2
Comments
SAKryukov at 18-Jan-11 1:57am
   
Why would you ever want to translate anything to VB.NET?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hope GBVB - Converting VB.NET code to C#[^] and this[^] will give you an idea.

From this you can change it as you like.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 659
1 F-ES Sitecore 260
2 Maciej Los 185
3 OriginalGriff 175
4 Richard MacCutchan 140
0 Sergey Alexandrovich Kryukov 1,029
1 Maciej Los 464
2 Richard MacCutchan 430
3 CHill60 415
4 OriginalGriff 415


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 18 Jan 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100