It's not easy. Now the write_packet function is available.

Source: Internet
Author: User
Write_packet:

If (ap_cur! = NULL)
{
If (h80211 [0] = 0x80 & G. one_beacon ){
If (! Ap_cur-> beacon_logged)
Ap_cur-> beacon_logged = 1;
Else return (0 );
}
}

If (G. record_data)
{
If (h80211 [0] & 0x0c) = 0x00) & (h80211 [0] & 0xf0) = 0xb0 ))
{
/* Authentication packet */
Check_shared_key (h80211, caplen );
}
}

If (ap_cur! = NULL)
{
If (ap_cur-> Security! = 0 & G. f_encrypt! = 0 & (ap_cur-> Security & G. f_encrypt) = 0 ))
{
Return (1 );
}
}

/* This changes the local ap_cur, st_cur and na_cur variables and shoshould be the last check befor the actual write */
If (caplen = 10 & h80211 [0])
{
/* TX | CTS | ACK | CF-END & CF-ACK */
// (H80211 [0] = 0xb4 | h80211 [0] = 0xc4 | h80211 [0] = 0xd4 | h80211 [0] = 0xe4 | h80211 [0] = 0xf4)

/* Use general control frame detection, as the structure is always the same: Mac (s) starting at [4] */
If (h80211 [0] & 0x04)
{
P = h80211 + 4;
While (P bssid, namac, 6 ))
Break;

Ap_prv = ap_cur;
Ap_cur = ap_cur-> next;
}

/* If it's an AP, try next Mac */

If (ap_cur! = NULL)
{
P + = 6;
Continue;
}

/* Check st list */
St_cur = G. st_1st;
St_prv = NULL;

While (st_cur! = NULL)
{
If (! Memcmp (st_cur-> stmac, namac, 6 ))
Break;

St_prv = st_cur;
St_cur = st_cur-> next;
}

/* If it's a client, try next Mac */

If (st_cur! = NULL)
{
P + = 6;
Continue;
}
}

/* Not found in either AP list or St list, look through na list */
Na_cur = G. na_1st;
Na_prv = NULL;

While (na_cur! = NULL)
{
If (! Memcmp (na_cur-> namac, namac, 6 ))
Break;

Na_prv = na_cur;
Na_cur = na_cur-> next;
}

/* Update our Chained List of unknown stations */
/* If it's a new Mac, add it */

If (na_cur = NULL)
{
If (! (Na_cur = (struct na_info *) malloc (
Sizeof (struct na_info ))))
{
Perror ("malloc failed ");
Return (1 );
}

Memset (na_cur, 0, sizeof (struct na_info ));

If (G. na_1st = NULL)
G. na_1st = na_cur;
Else
Na_prv-> next = na_cur;

Memcpy (na_cur-> namac, namac, 6 );

Na_cur-> Prev = na_prv;

Gettimeofday (& (na_cur-> TV), null );
Na_cur-> tinit = Time (null );
Na_cur-> tlast = Time (null );

Na_cur-> power =-1;
Na_cur-> channel =-1;
Na_cur-> ACK = 0;
Na_cur-> ack_old = 0;
Na_cur-> ackps = 0;
Na_cur-> CTS = 0;
Na_cur-> rts_r = 0;
Na_cur-> rts_t = 0;
}

/* Update the last time seen & Power */

Na_cur-> tlast = Time (null );
Na_cur-> power = ri-> ri_power;
Na_cur-> channel = ri-> ri_channel;

Switch (h80211 [0] & 0xf0)
{
Case 0xb0:
If (P = h80211 + 4)
Na_cur-> rts_r ++;
If (P = h80211 + 10)
Na_cur-> rts_t ++;
Break;

Case 0xc0:
Na_cur-> CTS ++;
Break;

Case 0xd0:
Na_cur-> ack ++;
Break;

Default:
Na_cur-> Other ++;
Break;
}

/* Grab next MAC (for RTS frames )*/
P + = 6;
}
}
}

If (G. f_cap! = NULL & caplen> = 10)
{
PKH. caplen = PKH. Len = caplen;

Gettimeofday (& TV, null );

PKH. TV _sec = TV. TV _sec;
PKH. TV _usec = (TV. TV _usec &~ 0x1ff) + Ri-> ri_power + 64;

N = sizeof (PKH );

If (fwrite (& PKH, 1, n, G. f_cap )! = (Size_t) N)
{
Perror ("fwrite (packet header) failed ");
Return (1 );
}

Fflush (stdout );

N = PKH. caplen;

If (fwrite (h80211, 1, n, G. f_cap )! = (Size_t) N)
{
Perror ("fwrite (Packet Data) failed ");
Return (1 );
}

Fflush (stdout );
}

Return (0 );
}
After a long time, I want to know which function is used to capture packets. Is it possible to establish raw socket directly? However, it is still not mentioned here, but it is also useful, look at this structure,
Fwrite (h80211, 1, n, G. f_cap )! = (Size_t) N
It indicates that the character string h80211 is written at the end. Continue to see: unsigned char * h80211; defined in main as follows. Then read here
Wi_read (WI [I], h80211, sizeof (buffer), & RI)
I went on to look for this function, but I didn't know where it was defined. Let's see what this Ri is. It is the pointer rx_info of this structure, and I don't know where it is. It should be in which header file. It will be solved later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.