In the 4.x API, addresses and DNS Names are not passed as strings but as native objects. This allows for
easy checking against netmasks and domain sets. It also means that to print such names, the `:toString`
-method must be used.
+method must be used (or even `:toStringWithPort` for addresses).
Comparing IP addresses and DNSNames is not done with '==' but with the `:equal` method.
```
function nxdomain(dq)
print("Intercepting NXDOMAIN for: ",dq.qname:toString())
- if dq.qtype == pdns.A
+ if dq.qtype == pdns.A
then
dq.rcode=0 -- make it a normal answer
dq:addAnswer(pdns.A, "192.168.1.1")
To compare the address (so not the port) of two ComboAddresses, use `:equal`.
+To convert an address to human-friendly representation, use `:toString()` or `:toStringWithPort()`. To
+get only the port number, use `:getPort()`.
+
### Metrics
You can custom metrics which will be shown in the output of 'rec_control get-all' and sent to the metrics server over the Carbon protocol,
and also appear in the JSON HTTP API.
* Advanced functions for writing your own policies and hooks
* ComboAddress related:
* `newCA(address)`: return a new ComboAddress
+ * `getPort()`: return the port number
* `tostring()`: return in human-friendly format
+ * `tostringWithPort()`: return in human-friendly format, with port number
* DNSName related:
* `newDNSName(name)`: make a DNSName based on this .-terminated name
* member `isPartOf(dnsname)`: is this dnsname part of that dnsname
print(string.format("Have %d entries in truncate NMG", truncateNMG:size()))
function blockFilter(remote, qname, qtype, dh)
+ print(string.format("Got query from %s, (%s) port number: %d", remote:tostring(), remote:tostringWithPort(), remote:getPort()))
if(qtype==255 or truncateNMG:match(remote))
then
-- print("any query, tc=1")