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::GetHostent - Obtain hostent struct from hostname or -address

Author

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

libbobcat-dev_6.07.01                               2005-2025                           FBB::GetHostent(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

       All  members  of  the  class  FBB::GetHostent  are  static. Consequently, there is no need to construct a
       FBB::GetHostent object.

Description

FBB::GetHostent  objects  produce  hostent  structs  which  may  be  used  by other types of objects. The
       FBB::GetHostent class is therefore primarily used as a base-class for other classes and is seldomly  used
       `stand-alone’.  The  hostent  structs  are static structs, but a non-static copy may be obtained using an
       FBB::Hostent object.

       A hostent struct 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.  These  binary  values may be converted to character-representations by the
       addressToString() member, which uses inet_ntop(), internally.

Example

           #include <iostream>
           #include <algorithm>
           #include <iterator>

           #include <bobcat/hostent>
           #include <bobcat/gethostent>

           using namespace std;
           using namespace FBB;

           int main(int argc, char **argv)
           try
           {
               if (argc == 1)
               {
                   cerr << "Provide a host name or host address to solve\n";
                   return 1;
               }

               Hostent he(GetHostent::gethostent(argv[1], argv[1]));
               cout << "Hostname: " << he.hostname() << endl;

               cout << "Aliases:\n";
               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;
           }
           catch (Exception const &err)
           {
               cout << err.what() << endl;
               return 1;
           }

Files

bobcat/gethostent - defines the class interface

Inherits From

       -

Name

       FBB::GetHostent - Obtain hostent struct from hostname or -address

Namespace

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

See Also

bind(1),   bobcat(7),   gethostbyaddr(3)   gethostbyname(3),   hostent(3bobcat),    inetaddress(3bobcat),
       inet_ntop(3)

Static Members

       o      hostentconst*gethostent(charconst*errorprefix,std::stringconst&nameOrAddress):
              The gethostent() member returns a pointer to a static structhostent. It contains the  information
              about the host whose name or dotted decimal address was provided as its second argument. Its first
              argument  is an error string prefix, prefixing the error message in an FBB::Exception object. Such
              an object is thrown as an exception when the host’s information could not be retrieved.

       o      std::stringaddressToString(charconst*errorprefix,voidconst*ads):
              This member returns the dotted decimal address of the host whose binary  address  is  provided  at
              ads.  Its  first  argument  is  an  error  string  prefix,  prefixing  the  error  message  in  an
              FBB::Exception object. Such an object is thrown as an exception when the  dotted  decimal  address
              could not be determined.

              The  class’  members  can  only  be  used  when  the host whose name or address is searched can be
              resolved by a name resolution process, e.g., bind(1).

Synopsis

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

See Also