Thanks for your reply. I have tried setting answer to 1. I have included an amended version of my programme at the end of this email.<br><br>When I run this, the server reports no error. When I 'dig @localhost foo.bar' I get the response:<br>
<br>"""<br>;; Warning: Message parser reports malformed message packet.<br><br>; <<>> DiG 9.4.1 <<>> @localhost foo.bar<br>; (1 server found)<br>;; global options: printcmd<br>;; Got answer:<br>
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18948<br>;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0<br>;; WARNING: recursion requested but not available<br>;; WARNING: Messages has 4 extra bytes at end<br>
<br>;; QUESTION SECTION:<br>;foo.bar. IN A<br><br>;; Query time: 1 msec<br>;; SERVER: 127.0.0.1#53(<a href="http://127.0.0.1">127.0.0.1</a>)<br>;; WHEN: Thu Mar 13 07:37:50 2008<br>;; MSG SIZE rcvd: 29<br>
"""<br><br>Wireshark also shows the reply packet to be malformed:<br><br>0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 ........ ......E.<br>0010 00 39 00 00 40 00 40 11 3c b2 7f 00 00 01 7f 00 .9..@.@. <.......<br>
0020 00 01 00 35 82 43 00 25 fe 38 51 cf 81 00 00 01 ...5.C.% .8Q.....<br>0030 00 01 00 00 00 00 03 66 6f 6f 03 62 61 72 00 00 .......f oo.bar..<br>0040 01 00 01 0a 0b 0c 0d <br><br>You can see the <a href="http://10.11.12.13">10.11.12.13</a> at the end (hex), but something about the packet is wrong.<br>
<br>Could you point out my mistake? If it's a bug in twisted.names, I'm happy to look at fixing it (I've worked with the dns protocol at packet level before), but I first want to make sure that I am using the API correctly.<br>
<br>Thanks,<br><br>Chris.<br><br><br><br><br><br>#!/usr/bin/python<br><br>from twisted.internet.protocol import Protocol, Factory<br>from twisted.internet import reactor<br>from twisted.names.server import DNSServerFactory<br>
from twisted.names.dns import Query, DNSDatagramProtocol, RRHeader, Record_CNAME, Record_A, Message<br>from twisted.names import dns<br>from twisted.internet.interfaces import IAddress<br><br>class Controller(object):<br>
def messageReceived(self, m, protocol, addr):<br> print m, dir(m), m.queries, m.answers<br> # this should always answer <a href="http://10.11.12.13">10.11.12.13</a>, regardless of the query<br> m.answer = 1<br>
m.answers.append(Record_A(address="<a href="http://10.11.12.13">10.11.12.13</a>"))<br> protocol.transport.write(m.toStr(), addr)<br><br>controller = Controller()<br><br>if __name__ == "__main__":<br>
reactor.listenUDP(53, DNSDatagramProtocol(controller))<br> reactor.run()<br><br><br><br><br><br><br><br><br><div><span class="gmail_quote">On 12/03/2008, <b class="gmail_sendername">Jean-Paul Calderone</b> <<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, 12 Mar 2008 08:04:21 +0000, Chris Dew <<a href="mailto:chris@sidwells.com">chris@sidwells.com</a>> wrote:<br> >I have a small script which answers dns queries by returning the original<br> >message. I have spent a couple of hours RTFMing, but I still cannot find<br>
>out how to correctly add answers to the message, before returning it.<br> ><br> >I want to add an answer, either a Record_CNAME or Record_A, so as to produce<br> >a trivial authoritative-only DNS server.<br>
><br> >Adding a Record_XXX object to message.answers using the Array's 'append'<br> >method produces a MalformedPacket (according to wireshark), though the<br> >server does not throw any exceptions. (In this situation, the answer<br>
>count, as shown by dig, does rise to 1, even though no answer is displayed<br> >[due to malformed packet?].)<br> ><br> >Perhaps there is a completely different way to do this? Could I craft a<br> >message with answers from scratch?<br>
<br> <br>Did you set `m.answerŽ to 1?<br> <br> Jean-Paul<br> <br> _______________________________________________<br> Twisted-Python mailing list<br> <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br> </blockquote></div><br>