summary refs log tree commit diff stats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-06-27 00:05:27 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2025-06-27 00:05:27 -0400
commitf8c2c11a4513aeda91aad9a7d199a2b0b1042111 (patch)
tree01cf4b64cbe5b65422ec6836cdb246f0bdd65eb8 /src/main.cpp
downloadgen4uploader-f8c2c11a4513aeda91aad9a7d199a2b0b1042111.tar.gz
gen4uploader-f8c2c11a4513aeda91aad9a7d199a2b0b1042111.tar.bz2
gen4uploader-f8c2c11a4513aeda91aad9a7d199a2b0b1042111.zip
Format beacon frames
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..aad5545 --- /dev/null +++ b/src/main.cpp
@@ -0,0 +1,97 @@
1#include <fcntl.h>
2#include <libwifi.h>
3#include <net/if.h>
4#include <netinet/ip.h>
5#include <pcap/pcap.h>
6#include <stdio.h>
7#include <sys/ioctl.h>
8#include <unistd.h>
9
10#include "beacon_data.h"
11
12int get_interface_mac_address(int sock, const char *interface, unsigned char *output)
13{
14 struct ifreq ifr = {0};
15 strcpy(ifr.ifr_name, interface);
16
17 if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
18 {
19 return -1;
20 }
21
22 memcpy(output, ifr.ifr_hwaddr.sa_data, 6);
23 return 0;
24}
25
26int main(int argc, char **argv)
27{
28 int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
29 if (sock == -1)
30 {
31 printf("Could not open socket.\n");
32 return 1;
33 }
34
35 unsigned char tx_addr[6];
36 if (get_interface_mac_address(sock, "wlo1", tx_addr))
37 {
38 printf("Could not get hardware address.\n");
39 return 2;
40 }
41
42 static unsigned char bcast[] = "\xFF\xFF\xFF\xFF\xFF\xFF";
43 struct libwifi_beacon beacon = {0};
44
45 if (libwifi_create_beacon(&beacon, bcast, tx_addr, tx_addr, "ballze", 7))
46 {
47 printf("Could not create beacon frame.\n");
48 return 3;
49 }
50
51 libwifi_remove_tag(&beacon.tags, TAG_SSID);
52
53 unsigned char payload_data[BEACON_PAYLOAD_LENGTH + 8];
54 payload_data[0] = 0x00;
55 payload_data[1] = 0x09;
56 payload_data[2] = 0xBF;
57 payload_data[3] = 0x00;
58 payload_data[4] = 0xFF;
59 payload_data[5] = 0xFF;
60 payload_data[6] = 0x00;
61 payload_data[7] = 0x00;
62 memcpy(payload_data + 8, kBeaconPayloads[0], BEACON_PAYLOAD_LENGTH);
63
64 if (libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, payload_data, BEACON_PAYLOAD_LENGTH + 8))
65 {
66 printf("Could not add beacon data tag.\n");
67 return 6;
68 }
69
70 size_t beacon_size = libwifi_get_beacon_length(&beacon);
71 unsigned char *beacon_output = (unsigned char *)malloc(beacon_size);
72 if (beacon_output == NULL)
73 {
74 printf("Could not allocate beacon output.\n");
75 return 4;
76 }
77
78 if (libwifi_dump_beacon(&beacon, beacon_output, beacon_size) < 0)
79 {
80 printf("Could not dump beacon.\n");
81 return 5;
82 }
83
84 libwifi_free_beacon(&beacon);
85
86 int fd = open("output.dat", O_WRONLY | O_CREAT, 00600);
87
88 static unsigned char radiotap[] = "\x00\x00\x08\x00\x00\x00\x00\x00";
89 write(fd, radiotap, 8);
90
91 write(fd, beacon_output, beacon_size);
92 close(fd);
93
94 free(beacon_output);
95
96 return 0;
97}