Ejemplo n.º 1
0
void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) {
    if(!iface)
        throw invalid_interface();

#if !defined(BSD) && !defined(__FreeBSD_kernel__)
    struct sockaddr_ll addr;

    memset(&addr, 0, sizeof(struct sockaddr_ll));

    addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
    addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
    addr.sll_halen = 6;
    addr.sll_ifindex = iface.id();

    const Tins::Dot11 *wlan = tins_cast<Tins::Dot11*>(inner_pdu());
    if(wlan) {
        Tins::Dot11::address_type dot11_addr(wlan->addr1());
        std::copy(dot11_addr.begin(), dot11_addr.end(), addr.sll_addr);
    }

    sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
#else
    sender.send_l2(*this, 0, 0, iface);
#endif
}
Ejemplo n.º 2
0
void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
    if(!iface)
        throw invalid_interface();
    
    #if !defined(BSD) && !defined(__FreeBSD_kernel__)
        sockaddr_ll addr;

        memset(&addr, 0, sizeof(struct sockaddr_ll));

        addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
        addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
        addr.sll_halen = 6;
        addr.sll_ifindex = iface.id();
        memcpy(&(addr.sll_addr), _header.addr1, 6);
        sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
    #else
        sender.send_l2(*this, 0, 0, iface);
    #endif
}
Ejemplo n.º 3
0
void EthernetII::send(PacketSender &sender, const NetworkInterface &iface) {
    if(!iface)
        throw invalid_interface();
    #if defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) || defined(BSD) || defined(__FreeBSD_kernel__)
        // Sending using pcap_sendpacket/BSD bpf packet mode is the same here
        sender.send_l2(*this, 0, 0, iface);
    #elif defined(WIN32)
        // On Windows we can only send l2 PDUs using pcap_sendpacket
        throw std::runtime_error("LIBTINS_USE_PCAP_SENDPACKET is not enabled");
    #else
        // Default GNU/Linux behaviour
        struct sockaddr_ll addr;

        memset(&addr, 0, sizeof(struct sockaddr_ll));

        addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
        addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
        addr.sll_halen = address_type::address_size;
        addr.sll_ifindex = iface.id();
        memcpy(&(addr.sll_addr), _eth.dst_mac, address_type::address_size);

        sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
    #endif
}