#include <jdnsshared.h>
Public Types | |
| enum | Type { Query, Publish } |
| enum | Error { ErrorNoNet, ErrorGeneric, ErrorNXDomain, ErrorTimeout, ErrorConflict } |
Signals | |
| void | resultsReady () |
Public Member Functions | |
| JDnsSharedRequest (JDnsShared *jdnsShared, QObject *parent=0) | |
| ~JDnsSharedRequest () | |
| Type | type () |
| void | query (const QByteArray &name, int type) |
| void | publish (QJDns::PublishMode m, const QJDns::Record &record) |
| void | publishUpdate (const QJDns::Record &record) |
| void | cancel () |
| bool | success () const |
| Error | error () const |
| QList< QJDns::Record > | results () const |
Friends | |
| class | JDnsShared |
Call query() to perform a query. Call publish() (or publishUpdate()) to make DNS records available on the local network (JDnsShared::Multicast mode only). When the operation has something to report, the resultsReady() signal is emitted. Call success() to determine the status of the operation. If success() returns false, then the operation has failed and the reason for the failure can be determined with error(). If success() returns true, then the meaning differs depending on the type of operation being performed:
Here is how you might look up an A record:
JDnsSharedRequest *req = new JDnsSharedRequest(jdnsShared); connect(req, SIGNAL(resultsReady()), SLOT(req_resultsReady())); req->query("psi-im.org", QJDns::A); ... void req_resultsReady() { if(req->success()) { // print all of the IP addresses obtained QList<QJDns::Record> results = req->results(); foreach(QJDns::Record r, results) { if(r.type == QJDns::A) printf("%s\n", qPrintable(r.address.toString()); } } else printf("Error resolving!\n"); }
Here is an example of publishing a record:
JDnsSharedRequest *pub = new JDnsSharedRequest(jdnsShared); connect(pub, SIGNAL(resultsReady()), SLOT(pub_resultsReady())); // let's publish an A record QJDns::Record rec; rec.owner = "SomeComputer.local."; rec.type = QJDns::A; rec.ttl = 120; rec.haveKnown = true; rec.address = QHostAddress("192.168.0.32"); pub->publish(QJDns::Unique, rec); ... void pub_resultsReady() { if(pub->success()) printf("Record published\n"); else printf("Error publishing!\n"); }
To update an existing record, use publishUpdate():
// the IP address of the host changed, so make a new record QJDns::Record rec; rec.owner = "SomeComputer.local."; rec.type = QJDns::A; rec.ttl = 120; rec.haveKnown = true; rec.address = QHostAddress("192.168.0.64"); // update it pub->publishUpdate(rec);
As a special exception, the address value can be left unspecified for A and Aaaa record types, which tells JDnsShared to substitute the address value with the address of whatever interfaces the record gets published on. This is the preferred way to publish the IP address of your own machine, and in fact it is the only way to do so if you have multiple interfaces, because there will likely be a different IP address value for each interface (the record resolves to a different answer depending on which interface a query comes from).
// let's publish our own A record QJDns::Record rec; rec.owner = "MyComputer.local."; rec.type = QJDns::A; rec.ttl = 120; rec.haveKnown = true; rec.address = QHostAddress(); pub->publish(QJDns::Unique, rec);
When you want to unpublish, call cancel() or destroy the JDnsSharedRequest.
|
|
Request error.
|
|
|
Operation type.
|
|
||||||||||||
|
Constructs a new object with the given jdnsShared and parent.
|
|
|
Destroys the object. If there is an active operation, it is cancelled. |
|
|
Cancels the current operation.
|
|
|
Returns the reason for error.
|
|
||||||||||||
|
Perform a publish operation.
|
|
|
Update a record that is currently published.
|
|
||||||||||||
|
Perform a query operation.
|
|
|
Returns the results of the operation.
|
|
|
Indicates that the operation has something to report. After receiving this signal, call success() to check on the status of the operation, followed by results() or error() as appropriate. |
|
|
Indicates whether or not the operation was successful.
|
|
|
The type of operation being performed.
|
1.4.6