DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

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 · Tutorial
Like (3)
Save
Tweet
Share
5.40K 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

  • What Is JavaScript Slice? Practical Examples and Guide
  • Getting a Private SSL Certificate Free of Cost
  • How Elasticsearch Works
  • mTLS Everywere

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: