DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Captive DNS Server Example (Mongoose More Than an Embedded Web Server)

Captive DNS Server Example (Mongoose More Than an Embedded Web Server)

Mongoose is simple and solid. It's one of the easiest to use embeddable servers around. It's usable in a wide range of applications, and here's yet another one.

Deomid Ryabkov user avatar by
Deomid Ryabkov
·
Apr. 30, 16 · Web Dev Zone · Tutorial
Like (2)
Save
Tweet
5.17K Views

Join the DZone community and get the full member experience.

Join For Free

This week we continue our series of examples for Mongoose Embedded Web Server with an example of a DNS server.

In this case, it is a DNS server intended to be used to build a captive portal, i.e. where the user needs to log in before using public WiFi. Such a server responds to all queries with its own IP address and an HTTP server running alongside serves the portal page to the user.

Building a DNS server with Mongoose is easy: mg_bind to a udp:// port, call mg_set_protocol_dns on the connection and handle incoming MG_DNS_MESSAGEevents.

Our captive_dns_server example puts this all together:

$ ./captive_dns_server
Listening on 'udp://:5533'
ev_handler           Q type 1 name example.org

---

$ dig @localhost -p 5533 example.org

; <<>> DiG 9.9.5-11ubuntu1.3-Ubuntu <<>> @localhost -p 5533 example.org
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44936
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITHY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;example.org.                   IN      A

;; ANSWER SECTION:
example.org.            10      IN      A       127.0.0.1

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5533(127.0.0.1)
;; WHEN: Mon Apr 18 19:56:51 IST 2016
;; MSG SIZE  rcvd: 56

Follow the Example

To follow the example download Mongoose Embedded Webserver. It's open source under GPLv2, so free of charge for non-commercial use. 

Download Mongoose

Domain Name System Web server Mongoose (web server)

Published at DZone with permission of Deomid Ryabkov, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Synchronization Methods for Many-To-Many Associations
  • Application Scalability — How To Do Efficient Scaling
  • Making Machine Learning More Accessible for Application Developers
  • Migrating Secrets Using HashiCorp Vault and Safe CLI

Comments

Web Dev Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo