tcpip_stack.h

Go to the documentation of this file.
00001 #ifndef TCPIP_STACK_GROUP
00002 #define TCPIP_STACK_GROUP
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : tcpip_stack                                                       *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *     Grab bag of functions for interacting with TCP/IP stacks.  This class   *
00012 *  hides details of the platform specifics of the stack.                      *
00013 *                                                                             *
00014 *******************************************************************************
00015 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00016 * redistribute it and/or modify it under the terms of the GNU General Public  *
00017 * License as published by the Free Software Foundation; either version 2 of   *
00018 * the License or (at your option) any later version.  This is online at:      *
00019 *     http://www.fsf.org/copyleft/gpl.html                                    *
00020 * Please send any updates to: fred@gruntose.com                               *
00021 \*****************************************************************************/
00022 
00023 #include "sockets_dll.h"
00024 
00025 #include <basis/object_base.h>
00026 
00027 // forward:
00028 class internet_address;
00029 class machine_uid;
00030 class machine_uid_array;
00031 struct sockaddr;
00032 
00033 class SOCKETS_CLASS_STYLE tcpip_stack : public virtual object_base
00034 {
00035 public:
00036   tcpip_stack();
00037   virtual ~tcpip_stack();
00038 
00039   bool healthy() const { return _healthy; }
00040     // returns true if the stack seems to be functioning properly.
00041 
00042   IMPLEMENT_CLASS_NAME("tcpip_stack");
00043 
00044   static istring tcpip_error_name(int error_value);
00045     // returns the name for the "error_value" specified, according to the
00046     // WinSock 1.1 specification.
00047 
00048   istring hostname() const;
00049     // gets the string form of the host's name for tcp/ip.
00050 
00051   machine_uid this_host(int location_type) const;
00052     // returns the unique identifier of "this" host given the "location_type"
00053     // of interest.  the type should be a member of the machine_uid::
00054     // known_location_types enum.
00055 
00056   static sockaddr convert(const internet_address &to_convert);
00057     // returns a low-level address created from our style of address.
00058   static internet_address convert(const sockaddr &to_convert);
00059     // returns our style address from the low-level address.
00060 
00061   byte_array full_resolve(const istring &hostname, istring &full_host) const;
00062     // finds the ip address for a "hostname".  the array will have zero
00063     // length on failure.  on success, the "full_host" will have the
00064     // possibly more authoratitative name for the host.
00065 
00066   bool resolve_any(const istring &name, internet_address &resolved) const;
00067     // translates "name" into a resolved form, where "name" can be either a
00068     // hostname or an ip address.  true is returned on success.
00069 
00070   istring dns_resolve(const istring &hostname) const;
00071     // returns a string form of the IP address for "hostname" or an empty
00072     // string if hostname cannot be found.
00073 
00074   bool enumerate_adapters(string_array &ip_addresses,
00075           bool add_local = false) const;
00076     // returns a list of the ip addresses that TCP/IP reports for this machine.
00077     // if there's more than one address, then this machine is multi-homed,
00078     // which could be due to an active dialup networking session or due to
00079     // there being more than one network interface.  if the function returns
00080     // false, then tcp/ip failed to report any addresses at all.  if the
00081     // "add_local" parameter is true, then the localhost IP address is added
00082     // to the list also.
00083 
00084   internet_address fill_and_resolve(const istring &machine, int port,
00085           bool &worked) const;
00086     // creates an address for TCP/IP given the "machine" and the "port".
00087     // the "machine" can either be in dotted number notation or can be a
00088     // hostname.  a special value of "local" or the empty string in "machine"
00089     // causes _this_ host to be used in the address.  otherwise, if the
00090     // "machine" is a textual hostname, then it is plugged into the returned
00091     // address and resolved if possible.  if the resolution of the "machine"
00092     // is successful, then "worked" is set to true.
00093 
00094   bool enumerate_adapters(machine_uid_array &ip_addresses,
00095           bool add_local = false) const;
00096     // similar to other function of same name but provides a list of
00097     // machine_uid objects.
00098 
00099 private:
00100   bool _healthy;  // records if stack started properly.
00101 
00102   static bool initialize_tcpip();
00103     // starts up the socket mechanisms.  true is returned on success.  if
00104     // true is returned, each call to initialize must be paired with a call
00105     // to deinitialize.
00106 
00107   static void deinitialize_tcpip();
00108     // shuts down the socket mechanisms.
00109 };
00110 
00111 #endif
00112 

Generated on Fri Nov 21 04:29:17 2008 for HOOPLE Libraries by  doxygen 1.5.1