Skip to content
Snippets Groups Projects
Commit e49a1bed authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Add very basic sample server.

parent 08b7151c
No related branches found
No related tags found
No related merge requests found
(use-modules (rnrs bytevectors)
(srfi srfi-1)
(srfi srfi-71)
(dns))
(define ai
(car
(getaddrinfo "::" "5353"
AI_PASSIVE
0
SOCK_DGRAM
)))
(define sock
(socket (addrinfo:fam ai)
(addrinfo:socktype ai)
(addrinfo:protocol ai)))
(bind sock (addrinfo:addr ai) )
(define (pack-bv bv size)
(let ((return (make-bytevector size)))
(bytevector-copy! bv 0 return 0 size)
return))
(define bv (make-bytevector 512))
(let ((_ return-addr (car+cdr (recvfrom! sock bv))))
(let ((q-message _ ((bytes->dns-message bv) 0)))
(let ((r-message
(make-dns-message
header: (make-dns-header id: (id (header q-message))
qr: #t
opcode: 'QUERY
qdcount: 1
ancount: 1
arcount: 0
)
questions: (questions q-message)
answers: (list (make-dns-rr-data
name: (name (car (questions q-message)))
type: (type (car (questions q-message)))
class: (class (car (questions q-message)))
ttl: 300
rdata: "10.30.40.20"))
; additionals: (additionals q-message)
)))
(let* ((_ bv ptr ((dns-message->bytes r-message) (make-bytevector 100) 0))
(bv (pack-bv bv ptr)))
(sendto sock bv return-addr)))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment