Creating a new variable in C from only part of an existing u_char -


I am writing some code to parse the IEEE 802.11 frame, but I am trying to create a new variable whose length depends on the size of the frame.

Here I currently have the code:

  frames_bab = len = pkt_hdr-> Lennon-radio_hdr- & gt; Lennon-wifi_hdr_len - 4; U_char * frame_body = (u_char *) (Packet + Radio_Hrit-> Lennon + Wifi_HDR_LN);  

Basically, the frame has a header, a body, and a checksum at the end. Calculate the length of the frame by taking the length of the packet and decreasing the length of the two headers, which appear before ( radio_hdr-> len and wifi_hdr_len respectively), plus At the end for 4 bytes checksium.

However, how can I make the frame_body variable without the checksum of the rear? Right now, I'm starting with the contents of the packet starting with the status after two headers, but there is no way to start from that position and end the 4 bytes before the end of packet ? The packet is an indicator for U_Acher, if it helps.

I am a new programmer, so you can give me any further advice about my code. I would greatly appreciate it. Thanks!

Your frame_board is just an indicator for the start of the frame, the current buffer Point to where the data is

It's OK, you can pass the bus simultaneously with your frame_body_len and everybody who cares about the data, only Observe the data starting with frame_body and does not care anything beyond frame_body_len - which you have to do anyway.

In this way, you do not really need to be a frame_blog , in which the follower checksum is not included.

If you need such a buffer, such as allocated dynamically, you have to create a space for the data, and there must be copies of the data there:

  u_char * frame_body = Malloc (frame_body_len); If (frame_bob == faucet) {// handling error} memcpy (frame_bus, and packet [radio_hdr-> len + wifi_hdr_len], frames_bas_lean);  

Comments