2023-08-30 17:32:36 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net.Sockets;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using IPMeow.Dns;
|
|
|
|
|
|
|
|
namespace IPMeow.Test;
|
|
|
|
|
|
|
|
public class DnsTest
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public async Task TestDns()
|
|
|
|
{
|
2023-10-19 18:25:22 +02:00
|
|
|
using UdpClient udp = new UdpClient(AddressFamily.InterNetwork);
|
|
|
|
udp.Connect(IPAddress.Parse("1.1.1.1"), 53);
|
|
|
|
|
2023-08-30 17:32:36 +02:00
|
|
|
DnsMessage msg = new()
|
|
|
|
{
|
|
|
|
IsRecursionDesired = true,
|
|
|
|
IsRecursionAvailable = true,
|
|
|
|
MessageId = 0xbabe,
|
|
|
|
MessageType = DnsMessageType.Query,
|
|
|
|
Opcode = DnsMessageOpcode.Query,
|
2023-09-30 08:49:12 +02:00
|
|
|
Questions = new List<QueryResourceRecord>()
|
2023-08-30 17:32:36 +02:00
|
|
|
{
|
2023-09-30 08:49:12 +02:00
|
|
|
new QueryResourceRecord()
|
2023-08-30 17:32:36 +02:00
|
|
|
{
|
|
|
|
Class = ResourceRecordClass.IN,
|
|
|
|
Name = "meow.lgbt",
|
|
|
|
Type = ResourceRecordType.A
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ResponseCode = 0,
|
|
|
|
};
|
|
|
|
|
2023-10-19 18:25:22 +02:00
|
|
|
var data = msg.Serialize();
|
|
|
|
await udp.SendAsync(data);
|
2023-08-30 17:32:36 +02:00
|
|
|
|
2023-10-19 18:25:22 +02:00
|
|
|
var rec = await udp.ReceiveAsync();
|
2023-08-30 17:32:36 +02:00
|
|
|
|
2023-10-19 18:25:22 +02:00
|
|
|
var res = DnsMessage.Deserialize(rec.Buffer);
|
2023-08-30 17:32:36 +02:00
|
|
|
|
2023-10-19 18:25:22 +02:00
|
|
|
Assert.Equal(DnsMessageType.Reply, res.MessageType);
|
|
|
|
Assert.Equal(0xbabe, res.MessageId);
|
2023-08-30 17:32:36 +02:00
|
|
|
}
|
|
|
|
}
|