FBB::InetAddress(3bobcat)

πŸ‘‘ NAME πŸ‘‘

FBB::InetAddress β€” converting between host byte order and network byte order 🌐✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <bobcat/inetaddress>
Linking option: -lbobcat

πŸ¦‹ DESCRIPTION πŸ¦‹

okay bestie, storytime, because this one actually slaps πŸ’– Computers are not all built the same when it comes to word-byte order, and the whole vibe of that is called endianness. A little-endian computer keeps its least significant byte at the byte having the lower address of a two-byte value, and a big-endian computer keeps its least significant byte at the byte having the higher address of a two-byte value. Two completely different energy signatures, no cap.

Sooo, in order to allow these computers to communicate over the Internet, host byte order was designed. 🌈 Objects of the class FBB::InetAddress are what you use to convert between network byte order and host byte order (and vice versa). It's giving translator, it's giving interpreter, it's giving "we can be friends despite our endianness" 🫢

Now, the class only has a few public members. Most members are protected, which means FBB::InetAddress is primarily used as a base class from which other classes are derived. In practice there will be little need to construct objects of the class FBB::InetAddress β€” it's lowkey a support class for the FBB socket-classes, and honestly that's iconic of it πŸ’…

Internally, all data are stored in network byte order. periodt.

Since the class' constructors depend on the proper functioning of members of the FBB:GetHostent class, the class' objects can only be constructed when the host whose name or address is searched can be resolved by a name resolution process, e.g., bind(1). So if resolution says no, construction says no too. 😭

Objects of the class FBB::InetAddress store address information about a host in a struct sockaddr_in data member. A struct sockaddr_in is the data type used to represent socket addresses in the Internet namespace. 🧚 It has the following members:

  • sa_family_t sin_family: this identifies the address family or format of the socket address. It holds the value AF_INET. πŸ’«
  • struct in_addr sin_addr: this is the Internet address of the host machine, stored as a binary value. πŸ”₯
  • size_t short int sin_port: this field holds the port number. πŸ“

🌸 NAMESPACE 🌸

FBB

All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. ✨


πŸ’œ INHERITS FROM πŸ’œ

-

(nothing, bestie, it's a root-level main character πŸ‘‘)


πŸ’… PROTECTED CONSTRUCTORS πŸ’…

  • InetAddress(std::string const &host, uint16_t port) β€” this constructor expects a host name or dotted decimal address and an (size_t) port number, and determines the host's address information. An FBB::Exception exception is thrown if the address could not be determined. πŸ™ˆ
  • InetAddress(uint16_t port) β€” this constructor constructs the generic address information that is used when constructing, e.g., server sockets. 🌐
  • InetAddress(sockaddr_in const &address) β€” this constructor constructs an FBB::InetAddress object from an initialized sockaddr_in object. It is primarily used to promote a sockaddr_in to an FBB::InetAddresss. πŸ¦‹

The (public) copy and move constructors (and assignment operators) are available. so you can copy and move them around all you want, slay ✨


⭐ MEMBER FUNCTIONS ⭐

  • uint16_t port() const β€” accessor returning the object's port value. πŸŽ€
  • std::string dottedDecimalAddress() const β€” accessor returning the object's Internet address as a dotted decimal string. If the address could not be determined, an FBB::Exception object is thrown. 😭
  • size_t size() const β€” accessor returning the size of the object's sockaddr_in (address) information. πŸ“
  • sockaddr const *sockaddrPtr() const β€” accessor returning the pointer to the object's sockaddr data member. πŸ’«
  • sockaddr_in const *sockaddr_inPtr() const β€” accessor returning the pointer to the object's sockaddr_in data member. πŸ’«

πŸ”₯ PROTECTED MEMBER FUNCTIONS πŸ”₯

  • sockaddr *sockaddrPtr() β€” this member returns the object's address information as a pointer to a modifiable struct sockaddr. This allows (contrary to the public member having the same name) derived objects to manipulate the object's address information directly. πŸ‘€
  • sockaddr_in *sockaddr_inPtr() β€” this member returns the object's address information as a pointer to a modifiable struct sockaddr_in. This allows (contrary to the public member having the same name) derived objects to manipulate the object's address information directly. πŸ‘€

🌈 EXAMPLE 🌈

here's the whole thing, copy it, run it, live your truth πŸ’–

#include <iostream>

#include <bobcat/inetaddress>
#include <bobcat/exception>

using namespace std;
using namespace FBB;

InetAddress X()
{
    class A: public InetAddress
    {
        public:
        A(uint16_t port)
        :
            InetAddress(port)
        {}
    };

    return A(2000);
}

int main(int argc, char **argv)
try
{
    InetAddress const &ia = X();

    cout << "A InetAddress was constructed for port " << ia.port() <<
            endl;
    cout << "It has the generic `ANY’ address: " <<
            ia.dottedDecimalAddress() << endl;
}
catch (exception const &e)
{
    cout << "Exception: " << e.what() << endl;
}

πŸŽ€ FILES πŸŽ€

  • bobcat/inetaddress β€” defines the class interface πŸ“

🫢 SEE ALSO 🫢

bind(1), bobcat(7), gethostent(3bobcat), socketbase(3bobcat)

go read those too, bestie, iykyk πŸ’œ


πŸ’€ BUGS πŸ’€

None Reported. (we stay unproblematic ✨)


🌟 BOBCAT PROJECT FILES 🌟

Debian Bobcat project files:

  • libbobcat6: debian package containing the shared library, changelog and copyright note πŸ“¦
  • libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info πŸ“¦

πŸ‘‘ BOBCAT πŸ‘‘

Bobcat is an acronym of Brokken’s Own Base Classes And Templates. cute, right? πŸ₯Ή


This is free software, distributed under the terms of the GNU General Public License (GPL). 🫢


🌸 AUTHOR 🌸

Frank B. Brokken (f.b.brokken@rug.nl). πŸ’œ


and that's the whole page, bestie!! this one shipped in libbobcat-dev_6.15.01, dated 2005-2026, and it lives at FBB::InetAddress(3bobcat). go forth and convert those byte orders, you absolute icon πŸ¦‹βœ¨πŸ’…

πŸ“¦ where this page comes from