logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FBB::Hostent - Wrapper around a struct hostent

Author

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

libbobcat-dev_6.07.01                               2005-2025                              FBB::Hostent(3bobcat)

Bobcat

       Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.

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;

Bugs

       None Reported.

Constructors

       o      Hostent(hostentconst*hostentPtr):
              This constructor initializes an @CLASS object from an  existing  hostent  struct.  Functions  like
              gethostbyname(3) and gethostbyaddress(3) return pointers to hostent structs.

       The default, copy and move constructors (and the copy and move assignment operators) are available.

Description

@CLASS  objects  are wrappers around hostent structs which may be used by other objects. A structhostent
       is defined as follows:

           struct hostent
           {
               char    *h_name;        // official name of host
               char    **h_aliases;    // alias list
               int     h_addrtype;     // host address type (always AF_INET)
               int     h_length;       // length of address
               char    **h_addr_list;  // list of addresses
           }

       The address fields are binary values of the addresses, each address requiring h_length  bytes,  the  last
       address being equal to 0. The @CLASS objects offer a C++-like interface to this struct.

Example

           #include <iostream>
           #include <algorithm>
           #include <iterator>
           #include <bobcat/hostent>

           using namespace std;
           using namespace FBB;

           int main(int argc, char **argv)
           {
               Hostent he(gethostbyname("localhost"));

               cout << "The local hostname = " << he.hostname() << endl;

               cout << "All aliases: " << endl;
               copy(he.beginAlias(), he.endAlias(),
                           ostream_iterator<char const *>(cout, "\n"));

               cout << "Addresses:\n";
               for (size_t idx = 0; idx < he.nAddresses(); idx++)
                   cout << he.dottedDecimalAddress(idx) << endl;
           }

Files

bobcat/hostent - defines the class interface

Inherits From

       -

Member Functions

       o      size_taddressLength()const:
              This member returns the length of the binary addresses in bytes.

       o      size_taddressType()const:
              This member returns the type of the address. Currently this is always AF_INET.

       o      charconst*alias(size_tindex)const:
              This  member returns alias `index’ of the host. The first alias has index0. If alias `index’ does
              not exist, 0 is returned.

       o      charconst*const*beginAlias()const:
              This member returns an iterator to the first alias. The hostname itself is  not  included  in  the
              list of aliases.

       o      charconst*binaryAddress(size_tindex)const:
              This  member  returns  the  binary address `index’ of the host.  The first address has index0. If
              address `index’ does not exist, 0 is returned. The pointer to  the  binary  address  points  to  a
              series  of  addressLength() bytes. Note that the returned address is in networkbyteorder. It can
              be converted to host byte order by the functions described in byteorder(3).

       o      std::stringdottedDecimalAddress(size_tindex)const:
              This member returns address `index’ as a dotted decimal address in a string. The first address has
              index0. If address `index’ does not exist, an empty string is returned.

       o      charconst*const*endAlias()const:
              This member returns an iterator pointing beyond the last alias.

       o      charconst*hostname()const:
              This member returns the standard (first) name of the host.

       o      size_tnAddresses()const:
              This member returns the number of addresses that  are  available.  When  requesting  a  particular
              address, the requested index should be less than the value returned by this member.

       o      size_tnAliases()const:
              This  member returns the number of aliases that are available. When requesting a particular alias,
              the requested index should be less than the value returned by this member.

       o      voidswap(Hostent&other):
              The current Hostent object’s content are swapped with the other object’s content.

Name

       FBB::Hostent - Wrapper around a structhostent

Namespace

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

See Also

bobcat(7)

Synopsis

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

See Also