Skip to content

Instantly share code, notes, and snippets.

@bethanylong
Created February 24, 2015 06:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bethanylong/eb97d15fca31dce67ade to your computer and use it in GitHub Desktop.
Save bethanylong/eb97d15fca31dce67ade to your computer and use it in GitHub Desktop.
Sample beacon frame sent over mon0
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <netdb.h>
#include <net/if.h>
#define TEST_BEACON \
"\x80\x00\x00\x00\xff\xff\xff\xff\xff\xff\xaa\xbb\xcc\xdd\xee\xff" \
"\xaa\xbb\xcc\xdd\xee\xff\xd0\xb6" \
"\x5a\x91\xa8\xd8\x76\x00\x00\x00\x64\x00\x21\x04\x00\x0b" \
"\x6c\x6f\x6e\x67\x62\x34\x20\x77\x69\x66\x69" \
"\x01\x08\x82\x84\x8b\x96\x24" \
"\xb0\x48\x6c\x03\x01\x01\x05\x04\x00\x01\x00\x00\x2a\x01\x00\x2f" \
"\x01\x00\x32\x04\x8c\x12\x98\x60\x2d\x1a\xbd\x18\x1b\xff\xff\xff" \
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
"\x00\x00\x00\x00\x3d\x16\x01\x08\x15\x00\x00\x00\x00\x00\x00\x00" \
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdd\x09\x00\x10" \
"\x18\x02\x00\x00\x1c\x00\x00\xdd\x18\x00\x50\xf2\x02\x01\x01\x84" \
"\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f" \
"\x00"
int main(int argc, char** argv) {
uint16_t proto = htons(ETH_P_ALL);
int packet_socket = socket(AF_PACKET, SOCK_RAW, proto);
printf("packet_socket == %d\n", packet_socket);
struct sockaddr_ll sa_ll;
memset(&sa_ll, 0, sizeof(sa_ll));
char *iface = "mon0";
int iface_num = if_nametoindex(iface);
sa_ll.sll_family = AF_PACKET;
sa_ll.sll_protocol = proto;
sa_ll.sll_ifindex = iface_num;
//sa_ll.sll_pkttype = PACKET_OUTGOING;
//sa_ll.sll_halen = ETHER_ADDR_LEN;
int bind_rv = bind(packet_socket, (struct sockaddr *) &sa_ll, sizeof(sa_ll));
if (bind_rv >= 0) {
printf("bind_rv == %d\n", bind_rv);
} else {
perror("bind");
}
int test_beacon_len = sizeof(TEST_BEACON);
int buf_len = test_beacon_len;
char *buf = calloc(buf_len, sizeof(char));
memcpy(buf, TEST_BEACON, buf_len);
int sendto_rv = sendto(packet_socket, buf, buf_len, 0, (struct sockaddr *) &sa_ll, sizeof(sa_ll));
if (sendto_rv >= 0) {
printf("Sent msg\n");
} else {
perror("sendto");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment