I have it working now. I have attached a working programme below. (Note: the RRHeader's name should be gathered from one of the queries, rather than being hard-coded, as in my example below. I did it this way, as it more obviously illustrates RRHeader's constructor.)<br>
<br>Thanks for your help, <br><br>Chris.<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(RRHeader(name="foo.bar", payload=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><div><span class="gmail_quote">On 13/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 Thu, 13 Mar 2008 07:52:24 +0000, Chris Dew <<a href="mailto:chris@sidwells.com">chris@sidwells.com</a>> wrote:<br> >Thanks for your reply. I have tried setting answer to 1. I have included<br> >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<br> >foo.bar' I get the response:<br> ><br> <br>> [snip]<br> <br>><br> >Could you point out my mistake? If it's a bug in twisted.names, I'm happy<br>
>to look at fixing it (I've worked with the dns protocol at packet level<br> >before), but I first want to make sure that I am using the API correctly.<br> <br> <br>See below. I think it's a documentation deficiency, but probably not a<br>
bug in the code.<br> <br> > [snip]<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,<br> >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> <br>Answers should be a list of RRHeaders, not bare Record_As.<br>
<br><br> ><br> >controller = Controller()<br> ><br> >if __name__ == "__main__":<br> > reactor.listenUDP(53, DNSDatagramProtocol(controller))<br> > reactor.run()<br> ><br> <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>