~kf5jwc/dns-server-rs

25e7152abd5c10e69978e2e19ee773b3f9ee1273 — Kyle Jones 6 months ago 133f5da
Small tidying.
2 files changed, 4 insertions(+), 6 deletions(-)

M src/bin/stub_resolver.rs
M src/dns_packet.rs
M src/bin/stub_resolver.rs => src/bin/stub_resolver.rs +3 -5
@@ 11,13 11,14 @@ use dns_server::{
    DnsQuestion,
    QueryType,
};
use QueryType::A as QTypeA;

fn main() {
    env_logger::init();

    let server = ("10.0.0.1", 53);
    let socket = UdpSocket::bind(("0.0.0.0", 43210)).expect("UDP socket server");
    let packet = make_dns_packet();
    let packet = make_dns_packet("yahoo.com", QTypeA);
    let req_buffer: BytePacketBuffer = packet.into();
    socket.send_to(&req_buffer.buf[0..req_buffer.pos], server).expect("Sending message to upstream server");



@@ 41,10 42,7 @@ fn main() {
    }
}

fn make_dns_packet() -> DnsPacket {
    let qname = "google.com";
    let qtype = QueryType::A;

fn make_dns_packet(qname: &str, qtype: QueryType) -> DnsPacket {
    let mut rng = rand::thread_rng();
    let mut packet = DnsPacket::default();
    packet.header.id = rng.gen();

M src/dns_packet.rs => src/dns_packet.rs +1 -1
@@ 22,7 22,6 @@ pub struct DnsPacket {

impl Into<BytePacketBuffer> for DnsPacket {
    fn into(mut self) -> BytePacketBuffer {
        let mut buffer = BytePacketBuffer::default();
        debug!("DnsPacket -> BytePacketBuffer");
        self.header.questions = self.questions.len() as u16;
        debug!("Questions: {}", self.header.questions);


@@ 33,6 32,7 @@ impl Into<BytePacketBuffer> for DnsPacket {
        self.header.resource_entries = self.resources.len() as u16;
        debug!("Resource entries: {}", self.header.questions);

        let mut buffer = BytePacketBuffer::default();
        self.header.write(&mut buffer).expect("Writing to header");

        for question in &self.questions {