Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

net_host.H

Go to the documentation of this file.
00001 #include "std/config.H"
00002 #include "std/strings.H"
00003 #include <ctype.h>
00004 
00005 #ifdef WIN32
00006 #include <windows.h>
00007 #include <winsock.h>
00008 #include <io.h>
00009 #else
00010 #include <sys/types.h>
00011 #include <sys/socket.h>
00012 #include <netinet/in.h>
00013 #include <arpa/inet.h>
00014 #include <netdb.h>
00015 #endif
00016 
00017 /* -----------------------  NetHost Class   ------------------------------- */
00018 //**********************************************************************
00019 //
00020 //  CLASS:  NetHost
00021 //  DESCR:  Provides information about a particular machine
00022 //          on the network.
00023 //
00024 //  USAGE:
00025 // 
00026 //     NetHost aHost("markov");
00027 //     NetHost sameHost("128.148.31.79");
00028 //     
00029 typedef const class NetHost cNetHost;
00030 class NetHost {
00031  protected:
00032    str_ptr       name_;
00033    int           port_;
00034    unsigned long addr_;
00035 
00036  public:
00037 
00038             NetHost   (const  char    *hostname);
00039             NetHost   (struct sockaddr_in *addr);
00040             NetHost   (cNetHost &rhs) : name_(rhs.name_),port_(rhs.port_), addr_(rhs.addr_) { }
00041    NetHost& operator= (cNetHost &rhs) { addr_ = rhs.addr_; name_ = rhs.name_;
00042                                         port_ = rhs.port_; return *this; }
00043 
00044    int     port(void)       const     { return port_; }
00045    str_ptr name(void)       const     { return name_; }
00046    void    get_address(struct sockaddr_in *addr) const {
00047       // DON'T free this memory; copy it
00048       // returns architecture-dependent address information
00049       memset(addr, 0, sizeof(sockaddr_in));
00050       addr->sin_family = AF_INET;
00051       addr->sin_addr.s_addr = addr_;
00052    }
00053 };

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18