root/foundation-apps/grosview-maxx/Host.h

Revision 2, 2.5 KB (checked in by emasson, 3 years ago)

initial import for the community edition

Line 
1//
2//  Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
3//
4//  This file may be distributed under terms of the GPL
5//
6//
7// $Id: Host.h,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $
8//
9
10#ifndef _Host_h
11#define _Host_h
12
13#define HOST_H_CVSID "$Id: Host.h,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $"
14
15#include <sys/types.h>
16#include <sys/socket.h>
17#include <netinet/in.h>
18#include <netdb.h>
19#include <arpa/inet.h>
20#ifdef HAVE_IOSTREAM
21#include <iostream>
22#else
23#include <iostream.h>
24#endif
25#include "bool.h"
26
27class Host {
28public:
29  Host(const char *hostname);
30  Host(const struct in_addr *address);
31  Host(unsigned int addr);
32  Host(const Host& host) { copy(host); _failure = host._failure; }
33  virtual ~Host(void);
34
35  Host &operator=(const Host& host) {
36    clear();
37    copy(host);
38    _failure = host._failure;
39
40    return *this;
41  }
42
43  bool operator==(const Host& host) const;
44  bool operator!=(const Host& host) const { return !(*this == host); }
45
46  // indicates a valid Host.
47  bool valid(void) const { return _valid; }
48  operator bool(void) const { return _valid; }
49  int reasonForFailure(void) const// returns h_errno at time of failure
50  bool tryAgain(void) const;         // Ok to try again?
51
52  const char *officialName(void) const { return _hent.h_name; }
53
54  int numAliases(void) const { return _numAliases; }
55  const char *alias(int num) const { return _hent.h_aliases[num]; }
56
57  int addrType(void) const { return _hent.h_addrtype; }
58  int addrLength(void) const { return _hent.h_length; }
59
60  int numAddresses(void) const { return _numAddresses; }
61  struct in_addr *address(int num) const {
62    return (in_addr *)_hent.h_addr_list[num];
63  }
64
65  // Linux will choke and die inside of inet_ntoa() when
66  // this function is called.  The Host class has been run
67  // through purify and the problem is not in it.  Must be
68  // another linux library problem :(.
69  const char *strAddress(int num) const { return inet_ntoa(*address(num)); }
70
71  // Should not use this under linux for the same reashon as the above
72  // function.
73  std::ostream &print(std::ostream &os) const;
74
75protected:
76private:
77  struct hostent _hent;
78  int _numAliases;
79  int _numAddresses;
80  bool _valid;
81  int  _failure;
82
83  void copy(const Host& host) { copy(&host._hent); }
84  void copy(const struct hostent *hent);
85  void clear(void);
86  bool check(const struct hostent *hent);
87  bool constuct(const struct in_addr *address);
88};
89
90// Do not use this under linux until inet_ntoa() is fixed.
91inline std::ostream &operator<<(std::ostream &os, const Host& host) {
92  return host.print(os);
93}
94
95#endif
Note: See TracBrowser for help on using the browser.