Results 1 to 6 of 6

Thread: Recieved TCP packet drops first byte

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    3

    Recieved TCP packet drops first byte

    Hi,

    I've been using some code which I found on the net, and have noticed that the first byte is never recieved. Annoyingly, this contains the MAC addresses, which is the bit I want. Can anyone help? Below is the relevant snippits:

    Public Sub [Start]()
    If m_Socket Is Nothing Then
    Try
    m_Socket = New Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP)
    m_Socket.Bind(New IPEndPoint(m_IP, 0))
    m_Socket.IOControl(SIO_RCVALL, BitConverter.GetBytes(1), Nothing)
    m_Socket.BeginReceive(m_Buffer, 0, m_Buffer.Length, SocketFlags.None, New AsyncCallback(AddressOf OnReceive), Nothing)
    Catch
    m_Socket = Nothing
    Throw New SocketException
    End Try
    End If
    End Sub

    Private Sub OnReceive(ByVal ar As IAsyncResult)

    Try
    Dim received As Integer = m_Socket.EndReceive(ar)
    Try
    If Not m_Socket Is Nothing Then
    ReDim m_pkt(received - 1)
    Array.Copy(Buffer, 0, m_pkt, 0, received)
    OnNewPacket(New Packet(m_pkt))

    End If
    Catch ex As Exception
    'Do Nothing -this is intended
    End Try
    m_Socket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, New AsyncCallback(AddressOf OnReceive), Nothing)

    Catch
    [Stop]()
    End Try
    End Sub

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Recieved TCP packet drops first byte

    Generally the first missing item is caused when you try to use an array and start at 1 instead of 0
    The code above seems to contain 0's are you sure your not dropping it in code somewhere else?

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    3

    Re: Recieved TCP packet drops first byte

    I've looked through, and I don't think so. I've realised I've made a mistake in the last posting though. I'm not loosing the first byte, I'm losing the first 14 bytes, which actually constitute the Ethernet 2 part of the frame. I get everything from Internet Protocol onwards. This pretty much rules out an array index problem, and rules in a code for socket problem.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Recieved TCP packet drops first byte

    Are you sure that is not done on purpose? The socket is dealing with the sending/receiving part so would remove the 'computer' bits from it to just give you the data itself. I have not used sockets directly as I use a 3rd party control, but would make sense to me that all you get is the data you sent itself.

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Recieved TCP packet drops first byte

    Here ya go, try this: msdn

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    3

    Re: Recieved TCP packet drops first byte

    Many thanks. Ended up using the arp interrogation method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width