Skip to content

Commit

Permalink
Retry sending DNS packets when no response is received.
Browse files Browse the repository at this point in the history
  • Loading branch information
froggey committed Jan 24, 2015
1 parent 0e5c891 commit 5f8ec34
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions net/ethernet.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,20 +1333,21 @@ the seperator character."
(reverse additional-records)))))

(defun dns-request (domain)
(dolist (server *dns-servers*)
(let ((id (random (expt 2 16))))
(with-udp-connection (conn server +dns-port+)
(send (build-dns-packet id +dns-standard-query+
:questions `((,domain :a :in)))
conn)
(let ((response (receive conn 15)))
(when response
(multiple-value-bind (rx-id flags questions answers authority-rrs additional-rrs)
(decode-dns-packet response)
(when (eql rx-id id)
(dolist (a answers)
(when (eql (second a) :a)
(return-from dns-request (fifth a))))))))))))
(dotimes (i 3) ; UDP is unreliable.
(dolist (server *dns-servers*)
(let ((id (random (expt 2 16))))
(with-udp-connection (conn server +dns-port+)
(send (build-dns-packet id +dns-standard-query+
:questions `((,domain :a :in)))
conn)
(let ((response (receive conn 10)))
(when response
(multiple-value-bind (rx-id flags questions answers authority-rrs additional-rrs)
(decode-dns-packet response)
(when (eql rx-id id)
(dolist (a answers)
(when (eql (second a) :a)
(return-from dns-request (fifth a)))))))))))))

;;; High-level address resolution.

Expand Down

0 comments on commit 5f8ec34

Please sign in to comment.