Thanks for your reply.&nbsp; I have tried setting answer to 1.&nbsp; 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.&nbsp; When I&nbsp; &#39;dig @localhost foo.bar&#39; I get the response:<br>
<br>&quot;&quot;&quot;<br>;; Warning: Message parser reports malformed message packet.<br><br>; &lt;&lt;&gt;&gt; DiG 9.4.1 &lt;&lt;&gt;&gt; @localhost foo.bar<br>; (1 server found)<br>;; global options:&nbsp; printcmd<br>;; Got answer:<br>
;; -&gt;&gt;HEADER&lt;&lt;- 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.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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&nbsp; rcvd: 29<br>
&quot;&quot;&quot;<br><br>Wireshark also shows the reply packet to be malformed:<br><br>0000&nbsp; 00 00 00 00 00 00 00 00&nbsp; 00 00 00 00 08 00 45 00&nbsp;&nbsp; ........ ......E.<br>0010&nbsp; 00 39 00 00 40 00 40 11&nbsp; 3c b2 7f 00 00 01 7f 00&nbsp;&nbsp; .9..@.@. &lt;.......<br>
0020&nbsp; 00 01 00 35 82 43 00 25&nbsp; fe 38 51 cf 81 00 00 01&nbsp;&nbsp; ...5.C.% .8Q.....<br>0030&nbsp; 00 01 00 00 00 00 03 66&nbsp; 6f 6f 03 62 61 72 00 00&nbsp;&nbsp; .......f oo.bar..<br>0040&nbsp; 01 00 01 0a 0b 0c 0d&nbsp;&nbsp; <br><br>You&nbsp; 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?&nbsp; If it&#39;s a bug in twisted.names, I&#39;m happy to look at fixing it (I&#39;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>
&nbsp;&nbsp;&nbsp; def messageReceived(self, m, protocol, addr):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print m, dir(m), m.queries, m.answers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # this should always answer <a href="http://10.11.12.13">10.11.12.13</a>, regardless of the query<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.answer = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.answers.append(Record_A(address=&quot;<a href="http://10.11.12.13">10.11.12.13</a>&quot;))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protocol.transport.write(m.toStr(), addr)<br><br>controller = Controller()<br><br>if __name__ == &quot;__main__&quot;:<br>
&nbsp;&nbsp;&nbsp; reactor.listenUDP(53, DNSDatagramProtocol(controller))<br>&nbsp;&nbsp;&nbsp; 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> &lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt; 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 &lt;<a href="mailto:chris@sidwells.com">chris@sidwells.com</a>&gt; wrote:<br> &gt;I have a small script which answers dns queries by returning the original<br> &gt;message.&nbsp;&nbsp;I have spent a couple of hours RTFMing, but I still cannot find<br>
 &gt;out how to correctly add answers to the message, before returning it.<br> &gt;<br> &gt;I want to add an answer, either a Record_CNAME or Record_A, so as to produce<br> &gt;a trivial authoritative-only DNS server.<br>
 &gt;<br> &gt;Adding a Record_XXX object to message.answers using the Array&#39;s &#39;append&#39;<br> &gt;method produces a MalformedPacket (according to wireshark), though the<br> &gt;server does not throw any exceptions.&nbsp;&nbsp; (In this situation, the answer<br>
 &gt;count, as shown by dig, does rise to 1, even though no answer is displayed<br> &gt;[due to malformed packet?].)<br> &gt;<br> &gt;Perhaps there is a completely different way to do this?&nbsp;&nbsp;Could I craft a<br> &gt;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>