---
name: "inetaddress"
section: "3bobcat"
platform: "linux"
package: "libbobcat-dev"
version: "6.07.01-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/inetaddress"
---

# inetaddress(3bobcat)

Converting between host byte order and network byte order

## NAME

FBB::InetAddress - Converting between host byte order and network byte order

## SYNOPSIS

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

## DESCRIPTION

Computers differ their word-byte order, called \`endianness’. A little-endian computer has its least significant byte at the byte having the lower address of a two-byte value, whereas a big-endian computer has its least significant byte at at the byte having the higher address of a two-byte value. In order to allow these computers to communicate over over Internet, *host byte order* was designed. Objects of the class **FBB::InetAddress** may be used to convert between network byte order and host byte order (and vice versa).

The class only has a few public members. Most members are protected, and **FBB::InetAddress** is therefore 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**, which is primarily a support class for the **FBB** socket-classes.

Internally, all data are stored in network byte order.

As 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)](/bind/1.md).

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:

- o

  **sa\_family\_t sin\_family**:\
   This identifies the address family or format of the socket address.  It holds the value **AF\_INET**.

- o

  **struct in\_addr sin\_addr**:\
   This is the Internet address of the host machine stored as a binary value.

- o

  **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

\-

## PROTECTED CONSTRUCTORS

- o

  **InetAddress(std::string const &host, uint16\_t port)**:\
   This constructor expects a host name or dotted decimal address and 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.

- o

  **InetAddress(uint16\_t port)**:\
   This constructor constructs the \`generic’ address information that is used when constructing, e.g. server sockets.

- o

  **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.

## MEMBER FUNCTIONS

- o

  **uint16\_t port() const**:\
   Accessor returning the object’s port value.

- o

  **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.

- o

  **size\_t size() const**:\
   Accessor returning the size of the object’s **sockaddr\_in** (address) information.

- o

  **sockaddr const \*sockaddrPtr() const**:\
   Accessor returning the pointer to the object’s **sockaddr** data member.

- o

  **sockaddr\_in const \*sockaddr\_inPtr() const**:\
   Accessor returning the pointer to the object’s **sockaddr\_in** data member.

## PROTECTED MEMBER FUNCTIONS

- o

  **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.

- o

  **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

```
#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)](/bind/1.md), [**bobcat**(7)](/bobcat/7.md), [**gethostent**(3bobcat)](/gethostent/3bobcat.md), [**socketbase**(3bobcat)](/socketbase/3bobcat.md)

## BUGS

None Reported.

## BOBCAT PROJECT FILES

- o

  *https://fbb-git.gitlab.io/bobcat/*: gitlab project page;

Debian Bobcat project files:

- o

  *libbobcat6*: debian package containing the shared library, changelog and copyright note;

- o

  *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’.

## COPYRIGHT

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

## AUTHOR

Frank B. Brokken (**f.b.brokken@rug.nl**).
