feisty meow concerns codebase  2.140
internet_address.h
Go to the documentation of this file.
1 #ifndef INTERNET_ADDRESS_CLASS
2 #define INTERNET_ADDRESS_CLASS
3 
5 // Name : internet_address
6 // Author : Chris Koeritz
8 // Copyright (c) 1995-$now By Author. This program is free software; you can
9 // redistribute it and/or modify it under the terms of the GNU General Public
10 // License as published by the Free Software Foundation:
11 // http://www.gnu.org/licenses/gpl.html
12 // or under the terms of the GNU Library license:
13 // http://www.gnu.org/licenses/lgpl.html
14 // at your preference. Those licenses describe your legal rights to this
15 // software, and no other rights or warranties apply.
16 // Please send updates for this code to: fred@gruntose.com -- Thanks, fred.
18 
19 #include "base_address.h"
20 
22 
23 namespace sockets {
24 
25 // forward.
26 class machine_uid;
27 
29 
31 {
32 public:
36  };
37 
40  int port;
41 
43  // can be resolved to an ip_address if a domain name server
44  // is available.
45 
48  int port);
49 
50  DEFINE_CLASS_NAME("internet_address");
51 
52  machine_uid convert() const;
53  // returns the address in the uniquifying format.
54 
55  void fill(const basis::byte_array &ip_address, const basis::astring &host, int port);
56 
57  bool same_host(const base_address &to_compare) const;
58  bool same_port(const base_address &to_compare) const;
59  bool shareable(const base_address &to_compare) const;
60 
61  bool operator == (const internet_address &to_compare) const {
62  return same_host(to_compare) && same_port(to_compare);
63  }
64 
65  basis::astring text_form() const;
66 
67  basis::astring tokenize() const;
68  bool detokenize(const basis::astring &info);
69 
71  // returns a normal form for the hostname or address. this will come from
72  // the hostname member first, if it's set. next it will come from the
73  // string form of the IP address.
74 
75  static const basis::byte_array &nil_address();
76  // returns the address that is all zeros, otherwise known as INADDR_ANY.
77 
78  bool is_nil_address() const;
79  // returns true if this object's address_array is all zeros.
80 
81  static bool is_nil_address(const address_array &ip_address);
82  // returns true if the array "ip_address" is all zero.
83 
84  static bool appropriate_for_ip(const basis::astring &to_check);
85  // tests whether the string is possibly an ip address; it must have no
86  // characters in it besides dots and numbers.
87 
88  static bool valid_address(const basis::astring &to_check);
89  // returns true if the address "to_check" seems well-formed for IP. note
90  // that this will accept 0.0.0.0 as valid.
91 
92  static bool is_valid_internet_address(const basis::astring &to_check,
93  basis::byte_array &ip_form, bool &all_zeros);
94  // this function checks the string "to_check" to see if it is a valid
95  // internet address (e.g., 143.203.39.222). if it is a valid address,
96  // then the address "ip_form" is filled in with four bytes that are each
97  // in the range (0..255). if the "ip_form" is 0.0.0.0, then all_zeros
98  // is set to true.
99 
100  static bool ip_appropriate_number(const basis::astring &to_check, int indy,
101  basis::astring &accum);
103 
112  static bool has_ip_address(const basis::astring &to_check, basis::astring &ip_found);
114 
118  // returns a string containing the textual form of the "ip_address". the
119  // "ip_address" is expected to have the proper length (four bytes). if it
120  // does not, then an empty string is returned.
121 
122  static const basis::byte_array &localhost();
123  // provides the array that indicates localhost, rather than a NIC.
124  // this is commonly known to be 127.0.0.1.
125 
126  bool is_localhost() const;
127  // returns true if the address in question is the same as the localhost,
128  // either through the name matching "local" or "localhost", or through
129  // the address matching 127.0.0.1. note that the word "local" here is
130  // an "enhancement" and would not normally be considered the same as
131  // localhost. beware a networked computer that's actually named "local".
132  // also note that an address where the name disagrees with the address is
133  // basically broken, but we are not checking that here; either condition
134  // of the hostname or the address matching causes this to return true.
135 
136  base_address *create_copy() const;
137 
138  void pack(basis::byte_array &packed_form) const;
139  bool unpack(basis::byte_array &packed_form);
140 
141  virtual int packed_size() const;
142 };
143 
144 } //namespace.
145 
146 #endif
147 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
this type of address describes a destination out on the internet.
machine_uid convert() const
static bool has_ip_address(const basis::astring &to_check, basis::astring &ip_found)
returns true if "to_check" has an IP address in it somewhere.
basis::astring tokenize() const
static bool valid_address(const basis::astring &to_check)
basis::abyte address_array[ADDRESS_SIZE]
basis::astring normalize_host() const
basis::astring text_form() const
static basis::astring ip_address_text_form(const basis::byte_array &ip_address)
static const basis::byte_array & localhost()
void fill(const basis::byte_array &ip_address, const basis::astring &host, int port)
static const basis::byte_array & nil_address()
void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
bool operator==(const internet_address &to_compare) const
char hostname[MAXIMUM_HOSTNAME_LENGTH]
bool detokenize(const basis::astring &info)
bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
DEFINE_CLASS_NAME("internet_address")
bool same_host(const base_address &to_compare) const
static bool ip_appropriate_number(const basis::astring &to_check, int indy, basis::astring &accum)
returns true if "to_check" has a number at "indy" that works in ipv4.
virtual int packed_size() const
Estimates the space needed for the packed structure.
bool shareable(const base_address &to_compare) const
static bool is_valid_internet_address(const basis::astring &to_check, basis::byte_array &ip_form, bool &all_zeros)
static bool appropriate_for_ip(const basis::astring &to_check)
bool same_port(const base_address &to_compare) const
base_address * create_copy() const
unsigned char abyte
A fairly important unit which is seldom defined...
Definition: definitions.h:51
Provides access to the operating system's socket methods.
Definition: base_address.h:26