Books of Note

Practical Common
LispThe best intro to start your journey. Excellent coverage of CLOS.

ANSI Common
LispAnother great starting point with a different focus.

Paradigms of Artificial Intelligence
ProgrammingA superb set of Lisp examples. Not just for the AI crowd.

Saturday, April 17, 2004

My resolver library 

I'm putting the finishing touches on my resolver library. This is an FFI library that interfaces with Linux's resolver.so. This allows you to do random DNS queries and returns the DNS reply packet as a set of lists. For instance:

* (lookup "www.findinglisp.com" 'a)

((3254 T QUERY T NIL T T NO-ERROR 1 1 2 2) (("www.findinglisp.com." A IN))
 (("www.findinglisp.com." A IN 10800 #(217 160 226 69)))
 (("findinglisp.com." NS IN 172800 "ns27.1and1.com.")
  ("findinglisp.com." NS IN 172800 "ns28.1and1.com."))
 (("ns27.1and1.com." A IN 113098 #(217 160 224 3))
  ("ns28.1and1.com." A IN 157740 #(217 160 228 3))))
* (lookup "www.findinglisp.com" 'mx)

((3255 T QUERY T NIL T T NO-ERROR 1 2 2 8) (("www.findinglisp.com." MX IN))
 (("www.findinglisp.com." MX IN 86400 10 "mx01.1and1.com.")
  ("www.findinglisp.com." MX IN 86400 10 "mx00.1and1.com."))
 (("findinglisp.com." NS IN 172786 "ns27.1and1.com.")
  ("findinglisp.com." NS IN 172786 "ns28.1and1.com."))
 (("mx01.1and1.com." A IN 71326 #(217 160 230 11))
  ("mx01.1and1.com." A IN 71326 #(217 160 230 12))
  ("mx01.1and1.com." A IN 71326 #(217 160 230 10))
  ("mx00.1and1.com." A IN 71335 #(217 160 230 12))
  ("mx00.1and1.com." A IN 71335 #(217 160 230 10))
  ("mx00.1and1.com." A IN 71335 #(217 160 230 11))
  ("ns27.1and1.com." A IN 113084 #(217 160 224 3))
  ("ns28.1and1.com." A IN 157726 #(217 160 228 3))))
* (lookup "aol.com" 'txt)

((3256 T QUERY T NIL T T NO-ERROR 1 1 4 4) (("aol.com." TXT IN))
 (("aol.com." TXT IN 300
   "©v=spf1 ip4:152.163.225.0/24 ip4:205.188.139.0/24 ip4:205.188.144.0/24 ip4:205.188.156.0/23 ip4:205.188.159.0/24 ip4:64.12.136.0/23 ip4:64.12.138.0/24 ptr:mx.aol.com ?all"))
 (("aol.com." NS IN 3600 "dns-01.ns.aol.com.")
  ("aol.com." NS IN 3600 "dns-02.ns.aol.com.")
  ("aol.com." NS IN 3600 "dns-06.ns.aol.com.")
  ("aol.com." NS IN 3600 "dns-07.ns.aol.com."))
 (("dns-01.ns.aol.com." A IN 3600 #(152 163 159 232))
  ("dns-02.ns.aol.com." A IN 3600 #(205 188 157 232))
  ("dns-06.ns.aol.com." A IN 3600 #(149 174 211 8))
  ("dns-07.ns.aol.com." A IN 3600 #(64 12 51 132))))

That last query was for AOL's SPF record. A good description of SPF can be found in a couple of recent Linux Journal articles, here and here.

To interpret all this, you probably want to read the DNS spec, RFC 1035. The first sublist represents the header section of a DNS reply message. The next four sections are the query, answer, name server, and additional sections, respectively.

Anyway, this was done with about 500 lines of Lisp, using UFFI to interface with resolver.so. I'll post a fully-baked version of this as soon as I can pull it together. I still need to learn a bit about packaging as I'm not sure I have all the packaging and loading forms built correctly.


Comments:
Post a Comment


Links to this post:

Create a Link

This page is powered by Blogger. Isn't yours?