PHPackages                             hoa/dns - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hoa/dns

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

hoa/dns
=======

The Hoa\\Dns library.

3.17.01.10(9y ago)241976[1 PRs](https://github.com/hoaproject/Dns/pulls)1BSD-3-ClausePHP

Since Sep 10Pushed 7y ago8 watchersCompare

[ Source](https://github.com/hoaproject/Dns)[ Packagist](https://packagist.org/packages/hoa/dns)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-dns/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (12)Used By (1)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/438d07fb52f66e427e643d85fb87d4bfbc379bfb1e45095773a1c30d0ec51006/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f646e732f6d61737465722e737667)](https://travis-ci.org/hoaproject/dns) [![Code coverage](https://camo.githubusercontent.com/dd9da5e1934845651d2de63f1b91b848b5fca02981cb41829d82c79cad2018b8/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f646e732f6d61737465722e737667)](https://coveralls.io/github/hoaproject/dns?branch=master) [![Packagist](https://camo.githubusercontent.com/6211d1da70d1067a9203e431ad89e8430f8eb71641eb0d6d88d4f3748038690c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f646e732e737667)](https://packagist.org/packages/hoa/dns) [![License](https://camo.githubusercontent.com/50ed99ace0308b55675d2c892ad6617e8208dbb230b4d7dc1c0aaa3fed18d4e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f646e732e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Dns
========

[](#hoadns)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Dns)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/dns)

This library allows to create a domain name resolver.

[Learn more](https://central.hoa-project.net/Documentation/Library/Dns).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/dns`](https://packagist.org/packages/hoa/dns):

```
$ composer require hoa/dns '~3.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

As a quick overview, we propose to create our own resolution server for the top level domain `.hoa`. We start by modifying the local resolver in order to add a new resolution host: ours.

### Specify a resolution server

[](#specify-a-resolution-server)

On Mac OS X, the simplest way is to write in `/etc/resolver/hoa` the following declarations:

```
nameserver 127.0.0.1
port 57005

```

On Linux, we will use [DNSMasq](http://thekelleys.org.uk/dnsmasq/doc.html)(often already installed). Then, we edit the file `/etc/dnsmasq.conf` by adding:

```
server=/hoa/127.0.0.1#57005

```

And do not forget to restart:

```
$ sudo /etc/init.d/dnsmasq restart
 * Restarting DNS forwarder and DHCP server dnsmasq    [OK]
```

For Windows, it is more complicated. You should read the documentation.

### Create a resolution server

[](#create-a-resolution-server)

Well, now, we will create our resolution server that will listen `127.0.0.1:57005` (`57005` = `0xDEAD`) in UDP. Thus, in the `Resolution.php`file:

```
$dns = new Hoa\Dns\Resolver(
    new Hoa\Socket\Server('udp://127.0.0.1:57005')
);
$dns->on('query', function (Hoa\Event\Bucket $bucket) {
    $data = $bucket->getData();

    echo
        'Resolving domain ', $data['domain'],
        ' of type ', $data['type'], "\n";

    return '127.0.0.1';
});
$dns->run();
```

All query for the top level domain `.hoa` will be resolved to `127.0.0.1` (note: we do not look at the type, which should be `A` or `AAAA` respectively for IPv4 and IPv6).

Finally, let say we have a HTTP server that runs on `127.0.0.1:8888` and the index responds `yeah \o/`, then we start our resolver:

```
$ php Resolver.php
```

And we make an HTTP request on `foo.hoa` (that will be resolve to `127.0.0.1`):

```
$ curl foo.hoa --verbose
* About to connect() to foo.hoa port 80 (#0)
*   Trying 127.0.0.1... connected
* Connected to foo.hoa (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/a.b.c (…) libcurl/d.e.f
> OpenSSL/g.h.i zlib/j.k.l
> Host: foo.hoa:80
> Accept: */*
>
