/*
 *
 *
 *    hostent.h
 *
 *    C++ source for host_entry class for dealing with hostname lookups.
 *
 *    =========================================================================
 *    
 *    Copyright (C) 1999-2003 by Matt Roberts, KK5JY.
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *    =========================================================================
 *
 *    TODO:
 *       + Clean out the large inline functions, and make a library
 *         out of this.
 *       + Generalize the class to include INET6 addresses; create
 *         a template out of the existing class, and then typedef
 *         a the template into THostEntry and THostEntry6, or some-
 *         thing similar.
 *
 *
 */


#ifndef __THOSTENT_H
    #define __THOSTENT_H

    // C/C++ includes
    #include <string>
    #include <vector>
    #include <cstring>

    // system includes
    #include <netdb.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>


	namespace my {
		/*

		   class host_entry

		 */

		class host_entry {
			std::string               the_name;    // holds the hostname proper
			std::vector <std::string> the_alias;   // holds all of the applicable aliases
			std::vector <in_addr>     the_address; // holds all of the addresses
			bool                      valid;       // is 'true' if there is valid data in
			// the object, 'false' if not

			void init (void) {
				the_alias.reserve(16);
				the_address.reserve(16);
				the_alias.clear();
				the_address.clear();
				valid = false;
			}

			bool process (hostent *he_ptr);

			public:
			bool isValid (void) { return valid; };

			bool lookup (const in_addr *i);
			bool lookup (const in_addr &i);
			bool lookup (const std::string &s);

			int numAliases (void)   { return the_alias.size();   };
			int numAddresses (void) { return the_address.size(); };

			bool getHostname (std::string &a);

			bool getAddress (const size_t i, in_addr &a);
			bool getAliases (std::vector<in_addr> &l);

			bool getAlias (size_t i, std::string &a);
			bool getAliases (std::vector<std::string> &l);

			host_entry &operator = (const std::string &s);
			host_entry &operator = (const in_addr &s);
			host_entry &operator = (const host_entry &he);

			bool operator ! (void) { return !valid; };

			explicit host_entry (void) { init (); };
			explicit host_entry (const std::string &s) { init (); lookup (s); };
			explicit host_entry (const host_entry &he);

			~host_entry (void) { };
		};
	}

#endif
