Domain name class

Domain name class

Released 6 years ago , Last update 6 years ago

A domain name encapsulation class for servers, resolver implementations and other domain-name handling applications.

This class provides many common domain name string manipulations:

  • Manipulate individual labels in the domain name
  • Serialization and deserialization to and from character and byte strings
  • Subtraction and pruning
  • Domain name compressions as specified in RFC 1035

And more.

This class is useful for:

  • Servers
  • Resolver implementations
  • Any software that deals with domain names and their components

A comprehensive test suite is attached.

Example of usage:

    dname d1(std::string("abc.def.xyz")); // Create
    dname d2(d1);  // Copy
    dname d3(d2, 1); // Copy and strip 1 label

    d2 = d1; // Assign
    d3 = d3;

    d3.to_string(); // Convert to a string "def.xyz"
    d3.to_fqdn(); // Convert to FQDN "def.xyz."

    d2.is_subdomain(d3); // Check if d3 is a subdomain of d2

    d2.label_count(); // Get number of labels (3)

    d1.swap(d2); // Swap 2 domains

    // Subtraction
    dname d0(std::string("."));
    dname d1(std::string("abc.def.xyz"));
    dname d2(std::string("123.abc.def.xyz"));
    dname d3(std::string("456.123.abc.def.xyz"));

    d0.subtract(d0); // Returns ""
    d1.subtract(d1); // Returns ""
    d2.subtract(d1); // Returns "123"
    d3.subtract(d2); // Returns "456"
    d3.subtract(d1); // Returns "456.123"
    d3.subtract(d0); // Returns "456.123.abc.def.xyz"

    d1.subtract(d2); // Returns "-123"
    d2.subtract(d3); // Returns "-456"
    d1.subtract(d3); // Returns "-456.123"
    d0.subtract(d3); // Returns "-456.123.abc.def.xyz"

    // Prune
    dname d0(std::string("."));
    dname d1(std::string("abc.def.xyz"));
    dname d2(std::string("123.abc.def.xyz"));
    dname d3(std::string("456.123.abc.def.xyz"));

    d2.prune(4); // Returns "123"
    d3.prune(5); // Returns "456"
    d3.prune(4); // Returns "456.123"
    d3.prune(0); // Returns "456.123.abc.def.xyz"
    d3.prune(d2.label_count()); // Returns "456"

    // Serialize into a stream
    dname d1(std::string("abc.def.xyz"));
    std::ostringstream o;
    o << d1;

    // Read from a stream
    dname d;
    i >> d;

Pricing

14 day 14-day money-back guarantee

$4.99

Personal License

  • Perpetual license

  • 1 application

  • Can distribute binary products only

  • Commercial use

2 licenses, starting from From » $4.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
No comments have been posted yet.