internet_address.h
Go to the documentation of this file.00001 #ifndef INTERNET_ADDRESS_CLASS
00002 #define INTERNET_ADDRESS_CLASS
00003
00005
00006
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #include "base_address.h"
00020
00021 #include <configuration/configurator.h>
00022
00023 namespace sockets {
00024
00025
00026 class machine_uid;
00027
00029
00030 class internet_address : public base_address
00031 {
00032 public:
00033 enum internet_address_constraints {
00034 ADDRESS_SIZE = 4,
00035 MAXIMUM_HOSTNAME_LENGTH = 128
00036 };
00037
00038 typedef basis::abyte address_array[ADDRESS_SIZE];
00039 address_array ip_address;
00040 int port;
00041
00042 char hostname[MAXIMUM_HOSTNAME_LENGTH];
00043
00044
00045
00046 internet_address();
00047 internet_address(const basis::byte_array &ip_address, const basis::astring &host,
00048 int port);
00049
00050 DEFINE_CLASS_NAME("internet_address");
00051
00052 machine_uid convert() const;
00053
00054
00055 void fill(const basis::byte_array &ip_address, const basis::astring &host, int port);
00056
00057 bool same_host(const base_address &to_compare) const;
00058 bool same_port(const base_address &to_compare) const;
00059 bool shareable(const base_address &to_compare) const;
00060
00061 bool operator == (const internet_address &to_compare) const {
00062 return same_host(to_compare) && same_port(to_compare);
00063 }
00064
00065 basis::astring text_form() const;
00066
00067 basis::astring tokenize() const;
00068 bool detokenize(const basis::astring &info);
00069
00070 basis::astring normalize_host() const;
00071
00072
00073
00074
00075 static const basis::byte_array &nil_address();
00076
00077
00078 bool is_nil_address() const;
00079
00080
00081 static bool is_nil_address(const address_array &ip_address);
00082
00083
00084 static bool appropriate_for_ip(const basis::astring &to_check);
00085
00086
00087
00088 static bool valid_address(const basis::astring &to_check);
00089
00090
00091
00092 static bool is_valid_internet_address(const basis::astring &to_check,
00093 basis::byte_array &ip_form, bool &all_zeros);
00094
00095
00096
00097
00098
00099
00100 static bool ip_appropriate_number(const basis::astring &to_check, int indy,
00101 basis::astring &accum);
00103
00112 static bool has_ip_address(const basis::astring &to_check, basis::astring &ip_found);
00114
00117 static basis::astring ip_address_text_form(const basis::byte_array &ip_address);
00118
00119
00120
00121
00122 static const basis::byte_array &localhost();
00123
00124
00125
00126 bool is_localhost() const;
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 base_address *create_copy() const;
00137
00138 void pack(basis::byte_array &packed_form) const;
00139 bool unpack(basis::byte_array &packed_form);
00140
00141 virtual int packed_size() const;
00142 };
00143
00144 }
00145
00146 #endif
00147