Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some devices that send a standard beacon and then a user data(38 bytes). So to get it I set a socket. I'm programming in C#.

C#
private void buttonStart_Click(object sender, EventArgs e)
    {
        if (comboBoxInterfaces.SelectedIndex == -1)
        {
            MessageBox.Show("Select an Interface to capture the   packets.", "WIFI Sniffer",
               MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }

        try
        {
            if (!continue_capturing)
            {
                //Start capturing the packets...

                buttonStart.Text = "&Stop";

                continue_capturing = true;

                //For sniffing the socket to capture the packets has to be a raw socket, with the
                //address family being of type internetwork, and protocol being IP
                mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

                //Bind the socket to the selected IP address
                mainSocket.Bind(new IPEndPoint(IPAddress.Parse(comboBoxInterfaces.SelectedItem.ToString()), 0));

                //Set the socket  options
                mainSocket.SetSocketOption(SocketOptionLevel.IP,            //Applies only to IP packets
                                           SocketOptionName.HeaderIncluded, //Set the include the header
                                           true);                           //option to true

                byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
                byte[] byOut = new byte[4] { 1, 0, 0, 0 }; //Capture outgoing packets

                //Socket.IOControl is analogous to the WSAIoctl method of Winsock 2
                mainSocket.IOControl(IOControlCode.ReceiveAll,              //Equivalent to SIO_RCVALL constant
                    //of Winsock 2
                                     byTrue,
                                     byOut);

                //Start receiving the packets asynchronously
                mainSocket.BeginReceive(byte_data, 0, byte_data.Length, SocketFlags.None,
                    new AsyncCallback(OnReceive), null);
            }
            else
            {
                buttonStart.Text = "&Start";
                continue_capturing = false;
                //To stop capturing the packets close the socket
                mainSocket.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "WIFI Sniffer", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }


When I parse received packets I see only TCP, UDP packets also socket type - SocketType.Raw. How can I get beacons? May be I should configure it differently?
Posted
Updated 12-Mar-15 0:44am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900