void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, const NetworkInterface &iface) { int sock = get_ether_socket(iface); PDU::serialization_type buffer = pdu.serialize(); if(!buffer.empty()) { #if defined(BSD) || defined(__FreeBSD_kernel__) if(::write(sock, &buffer[0], buffer.size()) == -1) #else if(::sendto(sock, &buffer[0], buffer.size(), 0, link_addr, len_addr) == -1) #endif throw socket_write_error(make_error_string()); } }
void PacketWriter::write(PDU &pdu) { PDU::serialization_type buffer = pdu.serialize(); timeval tm; #ifndef _WIN32 gettimeofday(&tm, 0); #else // fixme tm = timeval(); #endif struct pcap_pkthdr header = { tm, static_cast<bpf_u_int32>(buffer.size()), static_cast<bpf_u_int32>(buffer.size()) }; pcap_dump((u_char*)dumper, &header, &buffer[0]); }
bool OfflinePacketFilter::matches_filter(PDU& pdu) const { PDU::serialization_type buffer = pdu.serialize(); return matches_filter(&buffer[0], static_cast<uint32_t>(buffer.size())); }