#include "transmit.h" #include #include #include #include #include #include static pthread_mutex_t socket_mutex = PTHREAD_MUTEX_INITIALIZER; int send_packet(int sock, int device_index, const unsigned char dst_addr[6], const unsigned char *packet, int packet_size) { struct sockaddr_ll socket_address = {0}; socket_address.sll_family = AF_PACKET; socket_address.sll_ifindex = device_index; socket_address.sll_halen = ETH_ALEN; memcpy(socket_address.sll_addr, dst_addr, 6); pthread_mutex_lock(&socket_mutex); int ret = 0; if (sendto(sock, packet, packet_size, 0, (struct sockaddr *)&socket_address, sizeof(struct sockaddr_ll)) < 0) { printf("Could not send packet: %d\n", errno); ret = errno; } pthread_mutex_unlock(&socket_mutex); return ret; } int send_packet_with_radiotap(int sock, int device_index, const unsigned char dst_addr[6], const unsigned char* packet, int packet_size) { struct libwifi_radiotap_info radiotap_info = {0}; radiotap_info.present = (1 << IEEE80211_RADIOTAP_FLAGS) | (1 << IEEE80211_RADIOTAP_RATE); radiotap_info.flags = IEEE80211_RADIOTAP_F_FCS | IEEE80211_RADIOTAP_F_SHORTPRE; radiotap_info.rate_raw = 4; unsigned char radiotap_buffer[256]; int radiotap_size = libwifi_create_radiotap(&radiotap_info, radiotap_buffer); int buffer_size = radiotap_size + packet_size; unsigned char* buffer = (unsigned char*)malloc(buffer_size); memcpy(buffer, radiotap_buffer, radiotap_size); memcpy(buffer + radiotap_size, packet, packet_size); int ret = send_packet(sock, device_index, dst_addr, buffer, buffer_size); return ret; }