23 return _addr.sin_addr.s_addr;
31 INLINE Socket_Address::
32 Socket_Address(
unsigned short port) {
33 _addr.sin_family = AF_INET;
34 _addr.sin_addr.s_addr = INADDR_ANY;
35 _addr.sin_port = htons(port);
43 INLINE Socket_Address::
45 _addr.sin_family = inaddr._addr.sin_family;
46 _addr.sin_addr.s_addr = inaddr._addr.sin_addr.s_addr;
47 _addr.sin_port = inaddr._addr.sin_port;
55 INLINE Socket_Address::
56 Socket_Address(
const AddressType &inaddr) {
57 _addr.sin_family = inaddr.sin_family;
58 _addr.sin_addr.s_addr = inaddr.sin_addr.s_addr;
59 _addr.sin_port = inaddr.sin_port;
76 INLINE
bool Socket_Address::
78 return ((_addr.sin_family == in._addr.sin_family) &&
79 (_addr.sin_addr.s_addr == in._addr.sin_addr.s_addr) &&
80 (_addr.sin_port == in._addr.sin_port));
88 INLINE
bool Socket_Address::
90 return ((_addr.sin_family != in._addr.sin_family) ||
91 (_addr.sin_addr.s_addr != in._addr.sin_addr.s_addr) ||
92 (_addr.sin_port != in._addr.sin_port));
102 _addr.sin_family = AF_INET;
103 _addr.sin_addr.s_addr = 0xffffffff;
104 _addr.sin_port = htons(port);
115 _addr.sin_family = AF_INET;
116 _addr.sin_addr.s_addr = INADDR_ANY;
117 _addr.sin_port = htons(port);
128 _addr.sin_port = htons(port);
139 _addr.sin_family = AF_INET;
140 _addr.sin_addr.s_addr = INADDR_ANY;
141 _addr.sin_port = htons(0);
151 return ntohs(_addr.sin_port);
161 return std::string(inet_ntoa(_addr.sin_addr));
172 sprintf(buf1,
"%s:%d", inet_ntoa(_addr.sin_addr),
get_port());
173 return std::string(buf1);
186 struct hostent *hp = NULL;
192 if (hostname ==
"255.255.255.255") {
198 PN_uint32 addr = (long)inet_addr(hostname.c_str());
199 if (addr == INADDR_NONE) {
200 hp = gethostbyname(hostname.c_str());
204 memcpy(&_addr.sin_addr, hp->h_addr_list[0], (
unsigned int) hp->h_length);
207 memcpy(&_addr.sin_addr, &addr,
sizeof(addr));
210 _addr.sin_port = htons(port);
211 _addr.sin_family = AF_INET;
221 set_host(
const std::string &hostname) {
222 std::string::size_type pos = hostname.find(
':');
223 if (pos == std::string::npos)
226 std::string host = hostname.substr(0, pos);
227 std::string port = hostname.substr(pos + 1, 100);;
229 int port_dig = atoi(port.c_str());
239 set_host(PN_uint32 in_hostname,
int port) {
240 memcpy(&_addr.sin_addr, &in_hostname,
sizeof(in_hostname));
241 _addr.sin_port = htons(port);
242 _addr.sin_family = AF_INET;
251 INLINE
bool Socket_Address::
253 if (_addr.sin_port < in._addr.sin_port)
256 if (_addr.sin_port > in._addr.sin_port)
259 if (_addr.sin_addr.s_addr < in._addr.sin_addr.s_addr)
262 if (_addr.sin_addr.s_addr > in._addr.sin_addr.s_addr)
265 return (_addr.sin_family < in._addr.sin_family);
275 PN_uint32 address = ntohl(_addr.sin_addr.s_addr);
277 return (address >= 0xe0000000 && address < 0xefffffff);
virtual ~Socket_Address()
Normal Destructor.
unsigned long GetIPAddressRaw() const
Return a RAW sockaddr_in.
bool set_any_IP(int port)
Set to any address and a specified port.
std::string get_ip_port() const
Return the ip address/port in dot notation string.
unsigned short get_port() const
Get the port portion as an integer.
void clear()
Set the internal values to a suitable known value.
A simple place to store and munipulate tcp and port address for communication layer.
bool set_host(const std::string &hostname, int port)
This function will take a port and string-based TCP address and initialize the address with this info...
bool is_mcast_range() const
True if the address is in the multicast range.
std::string get_ip() const
Return the IP address portion in dot notation string.
bool set_broadcast(int port)
Set to the broadcast address and a specified port.
bool set_port(int port)
Set to a specified port.