📄 wireless_frame_parse.c~
字号:
#include <stdio.h>#include "wireless_frame_parse.h"#include <pcap.h>#define PCAP_PATH_SIZE 30u8 *mgmt_ie[] = { "ssid", "supported rates", "fh set", "ds set", "fc set", "tim", "IBSS", "","","","","","","","","", "test text",};struct frame_list frame_captured;void dispatch_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data){ int i = 0; u8 type; u8 stype; if (frame_captured.frame_list_size > FRAME_LIST_SIZE){ printf("the frame num has surpass the max num: the capture will be ended\n"); return -1; } type = WLAN_FC_GET_TYPE(pkt_data[0]); stype = WLAN_FC_GET_STYPE(pkt_data[0]); printf("---------------------------------------------\n"); printf("this is %0d frame\n", frame_captured.frame_list_size); struct platform_ieee80211_mgmt* tmp_mgmt = NULL; u16 tmp_seq;//for mgmt frame process u16 ie_total_len; u16 offset_ie; u8 tagged_num; u8 tagged_len; u8 *tagged_ie = NULL; switch (type){ case WLAN_MANAGEMENT_FRAME: //do something for all mgmt frame printf("-------------------------------------------\n"); if ((frame_captured.frame_array[frame_captured.frame_list_size].u1.mgmt = (struct platform_ieee80211_mgmt *)malloc(header->len)) == NULL){ perror("allocate memory error\n"); return -1; } tmp_mgmt = frame_captured.frame_array[frame_captured.frame_list_size].u1.mgmt; tmp_mgmt->u1.fc.version = WLAN_FC_GET_VERSION(pkt_data[0]); tmp_mgmt->u1.fc.type = WLAN_FC_GET_TYPE(pkt_data[0]); tmp_mgmt->u1.fc.subtype = WLAN_FC_GET_STYPE(pkt_data[0]); tmp_mgmt->u1.fc.to_ds = WLAN_FC_GET_TODS(pkt_data[1]); tmp_mgmt->u1.fc.from_ds = WLAN_FC_GET_FROMDS(pkt_data[1]); tmp_mgmt->u1.fc.more_frag = WLAN_FC_GET_MOREFRAG(pkt_data[1]); tmp_mgmt->u1.fc.retry = WLAN_FC_GET_RETRY(pkt_data[1]); tmp_mgmt->u1.fc.pwrmgmt = WLAN_FC_GET_PWRMGT(pkt_data[1]); tmp_mgmt->u1.fc.more_data = WLAN_FC_GET_MOREDATA(pkt_data[1]); tmp_mgmt->u1.fc.wep = WLAN_FC_GET_ISWEP(pkt_data[1]); tmp_mgmt->u1.fc.order = WLAN_FC_GET_ORDER(pkt_data[1]); memcpy(&tmp_mgmt->duration, pkt_data + 2, 2); printf("pktdata[2] = %d, pkt_data[3] = %d\n", pkt_data[2], pkt_data[3]); printf("duration is %d\n", tmp_mgmt->duration); memcpy(&tmp_mgmt->da, pkt_data + 4, 6); memcpy(&tmp_mgmt->sa, pkt_data + 10, 6); memcpy(&tmp_mgmt->bssid, pkt_data + 16, 6); tmp_mgmt->u2.seq.fragment = WLAN_GET_SEQ_FRAG(pkt_data[22]); memcpy(&tmp_seq, pkt_data + 22, 2); tmp_mgmt->u2.seq.sequence = WLAN_GET_SEQ_SEQ(tmp_seq); printf(" seq 1 = %0x ,seq 2 = %0x \n", pkt_data[22], pkt_data[23]); printf("fragment is %d, sequence is %0d\n", tmp_mgmt->u2.seq.fragment, tmp_mgmt->u2.seq.sequence); printf("tmp fc subtype = %d\n", tmp_mgmt->u1.fc.subtype); //put the captured frame's btyes to the data structure from the frame body printf("frame len = %d\n", header->len); memcpy(&(tmp_mgmt->u), pkt_data + 24, header->len - 24); switch (stype){ case WLAN_FC_STYPE_ASSOC_REQ: break; case WLAN_FC_STYPE_ASSOC_RESP: break; case WLAN_FC_STYPE_REASSOC_REQ: break; case WLAN_FC_STYPE_REASSOC_RESP: break; case WLAN_FC_STYPE_PROBE_REQ: break; case WLAN_FC_STYPE_PROBE_RESP: break; case WLAN_FC_STYPE_BEACON: printf("beacon timestamp is "); for (i = 0; i < 8; i++){ printf("%0x:", tmp_mgmt->u.beacon.timestamp[i]); } printf("\n"); printf("beacon inter is %0x\n", tmp_mgmt->u.beacon.beacon_int); printf("beacon cap is %0x\n", tmp_mgmt->u.beacon.capab_info); //this we process ie ie_total_len = header->len - 24- 12; break; case WLAN_FC_STYPE_ATIM: break; case WLAN_FC_STYPE_DISASSOC: break; case WLAN_FC_STYPE_AUTH: break; case WLAN_FC_STYPE_DEAUTH: break; default: printf("unkonwn management frame subtype\n"); return -1; } //do other operation about the ie printf("\nshow ie\n"); printf("ie len is %d\n", ie_total_len); offset_ie = 0; while(offset_ie < ie_total_len){ tagged_num = tmp_mgmt->u.beacon.variable[offset_ie]; printf("tagged is %s ", mgmt_ie[tagged_num]); tagged_len = tmp_mgmt->u.beacon.variable[offset_ie + 1]; printf("len is %d\n", tagged_len); printf("values :"); for (i = 0; i < tagged_len; i++){ printf("%c", tmp_mgmt->u.beacon.variable[offset_ie + 2 + i]); } printf("\n"); offset_ie += 2 + tagged_len; } break; case WLAN_CONTROL_FRAME: switch (stype){ case WLAN_FC_STYPE_RTS: break; case WLAN_FC_STYPE_CTS: break; case WLAN_FC_STYPE_ACK: break; default: printf("unkonwn control frame subtype \n"); return -1; } break; case WLAN_DATA_FRAME: switch (stype){ case WLAN_FC_STYPE_DATA: break; default: printf("unknown data frame subtype\n"); return -1; } break; default: printf("unknown frame type %d\n", type); return -1; } frame_captured.frame_list_size++;// printf("----%d %d----\n",type, stype); return;}int wireless_frame_parse(char *pcap_file_path){ pcap_t *pd = NULL; char errstr[PCAP_ERRBUF_SIZE + 1]; if (pcap_file_path == NULL){//do capture from current net //to do pcap_open }else{//do capture from the pcap files printf("pcap path is %s\n", pcap_file_path); pd = pcap_open_offline(pcap_file_path, errstr); if (pd == NULL){ perror("pcap open offline"); return -1; } pcap_loop(pd, 0, dispatch_handler, NULL); } printf("\n\n wireless parse end\n\n"); return 0;}void main(){ printf("\nwireless frame parse module start!\n"); int get_packet_from_file = 1; char *pcap_file_path = NULL; char *file_path = "pcap/auth11.pcap"; if (get_packet_from_file == 1){ pcap_file_path = (char*)malloc(sizeof(char)*PCAP_PATH_SIZE); memcpy(pcap_file_path, /*"pcap/auth_ok.pcap"*/file_path, strlen(file_path/*"pcap/auth_ok.pcap"*/)); } memset(&frame_captured, 0, sizeof(struct frame_list)); wireless_frame_parse(pcap_file_path); return ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -