Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:20:22+00:00 2026-05-31T00:20:22+00:00

Capturing IP Packets by my own BitReader ( Reading Bit By Bit ) public

  • 0

Capturing IP Packets by my own BitReader ( Reading Bit By Bit )

public class BitReader
{
    int Index;
    byte Current;
    Stream Reader;

    public BitReader ( Stream Memory )
    {
        Reader = Memory;
    }

    public bool? ReadBit ( )
    {
        if ( Index == 8 )
        {
            Index = 0;
            Current = ( byte ) Reader . ReadByte ( );
        }

        if ( Current == -1 )
        {
            return null;
        }
        else
        {

            return ( Current & ( 1 << ( 7 - Index++ ) ) ) != 0;
         // return ( Current & ( 1 << Index++ ) ) != 0;
        }
    }
}

Receiving a ZERO unknown byte in front of IP v4 Packets, as shown below,

00000000 01000101 00000000 00000101 11000000 01001001 00100110
01000000 00000000 10000000 00000110 10110010 01111110 11000000
10101000 00000001 00001010 01000101 10101011 11110010 00110101


Edit 2 :

private byte [ ] Buffer = new byte [ 4096 ];

                    _Socket = new Socket ( AddressFamily . InterNetwork , SocketType . Raw , ProtocolType . IP );

                    _Socket . Bind ( new IPEndPoint ( IPAddress . Parse ( Interface . Text ) , 0 ) );

                    _Socket . SetSocketOption ( SocketOptionLevel . IP , SocketOptionName . HeaderIncluded , true );

                    _Socket . IOControl ( IOControlCode . ReceiveAll , BitConverter . GetBytes ( 1 ) , BitConverter . GetBytes ( 1 ) );

                    _Socket . BeginReceive ( Buffer , 0 , Buffer . Length , SocketFlags . None , new AsyncCallback ( OnReceive ) , null );

Edit 1 :

MemoryStream _MemoryStream = new MemoryStream ( Buffer , 0 , Length );
BitReader _BitReader = new BitReader ( _MemoryStream );

            for ( int Loop = 0 ; Loop < 21 ; Loop++ )
            {
                bool? Result = _BitReader . ReadBit ( );

                if ( Loop % 8 == 0 && Loop != 0 )
                {
                    myTextBox . Invoke ( new Action ( delegate { myTextBox . Text += " "; } ) );
                }

                if ( Result . HasValue )
                {
                    myTextBox . Invoke ( new Action ( delegate { myTextBox . Text += Result . Value ? 1 : 0; } ) );
                }
            }

Edit 3 :

MemoryStream _MemoryStream = new MemoryStream(Buffer, 0, Length);
BinaryReader _BinaryReader = new BinaryReader(_MemoryStream );
private byte VersionAndHeaderLength;
VersionAndHeaderLength = _BinaryReader.ReadByte();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:20:23+00:00Added an answer on May 31, 2026 at 12:20 am

    You start with Index == 0 and only read the next byte when Index == 8. This means that the first byte you read will be always zero. To fix this, set Index = 8 in your constructor.

    Also, since byte can never be -1, the condition that checks whether Current == -1 will be always false and you will get infinite 1s at the end of the file, because that’s what you get when converting -1 to byte.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was capturing my own packets from my iPhone 4 when I was using
I am capturing an image using the following code public class PictureDemo extends Activity
Greetings, I have a method to capture packets. After capturing I want to add
I'm capturing a click on any given LI in: <ul> <li class=opt>Text 1</li> <li
What's the best way of capturing an mp3 stream coming off of http and
Alright so I have this C++ image capturing class. I was wondering if I
We are capturing packets to a file using tcpdump() . I need to write
how to disable structure padding...i am capturing the packets using pacp while displaying i
I am capturing network packets of Gtalk using Microsoft Network Monitor. Very often I
Capturing all links. $(a).live(click, function() { alert($(this).attr(class)); }); jquery.truncate.js adds in this. obj.html(str1 +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.