I want to run a program for sending my own packet to the environment over wifi radio. As my knowledge, this work can be done if I send a ethernet frame to the dest Mac address ff:ff:ff:ff:ff:ff. So i opened a raw socket and constructed the ethernet header following code.
/* Open RAW socket to send on */
if ((sockfd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1) {
perror("socket");
}
/* Get the index of the interface to send on */
memset(&if_idx, 0, sizeof(struct ifreq));
strncpy(if_idx.ifr_name, ifName, IFNAMSIZ-1);
if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0)
perror("SIOCGIFINDEX");
/* Get the MAC address of the interface to send on */
memset(&if_mac, 0, sizeof(struct ifreq));
strncpy(if_mac.ifr_name, ifName, IFNAMSIZ-1);
if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0)
perror("SIOCGIFHWADDR");
/* Construct the Ethernet header */
memset(sendbuf, 0, BUF_SIZ);
/* Ethernet header */
eh->ether_shost[0] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[0];
eh->ether_shost[1] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[1];
eh->ether_shost[2] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[2];
eh->ether_shost[3] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[3];
eh->ether_shost[4] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[4];
eh->ether_shost[5] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[5];
eh->ether_dhost[0] = 0xff;
eh->ether_dhost[1] = 0xff;
eh->ether_dhost[2] = 0xff;
eh->ether_dhost[3] = 0xff;
eh->ether_dhost[4] = 0xff;
eh->ether_dhost[5] = 0xff;
/* Ethertype field */
eh->ether_type = htons(ETH_P_BATMAN);
tx_len += sizeof(struct ether_header);
/* Packet data */
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
sendbuf[tx_len++] = 0xaa;
I tested this program on an router run in AP mode, but the problem is I could only receive this packet when i access in it WLAN SSID. My question is how i can receive this packet when i am in this router transmission range without connect to it ssid. Any help would be appreciated.