Panda3D
Loading...
Searching...
No Matches
netAddress.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file netAddress.h
10 * @author drose
11 * @date 2000-02-08
12 */
13
14#ifndef NETADDRESS_H
15#define NETADDRESS_H
16
17#include "pandabase.h"
18#include "numeric_types.h"
19#include "socket_address.h"
20
21/**
22 * Represents a network address to which UDP packets may be sent or to which a
23 * TCP socket may be bound.
24 */
25class EXPCL_PANDA_NET NetAddress {
26PUBLISHED:
27 NetAddress();
28 NetAddress(const Socket_Address &addr);
29
30 bool set_any(int port);
31 bool set_localhost(int port);
32 bool set_broadcast(int port);
33 bool set_host(const std::string &hostname, int port);
34
35 void clear();
36
37 int get_port() const;
38 void set_port(int port);
39 std::string get_ip_string() const;
40 bool is_any() const;
41 uint32_t get_ip() const;
42 uint8_t get_ip_component(int n) const;
43
44 const Socket_Address &get_addr() const;
45
46 void output(std::ostream &out) const;
47
48 size_t get_hash() const;
49 bool operator == (const NetAddress &other) const;
50 bool operator != (const NetAddress &other) const;
51
52private:
53 Socket_Address _addr;
54};
55
56INLINE std::ostream &operator << (std::ostream &out, const NetAddress &addr) {
57 addr.output(out);
58 return out;
59}
60
61#endif
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.
Definition netAddress.h:25
void clear()
Resets the NetAddress to its initial state.
bool set_host(const std::string &hostname, int port)
Sets the address up to refer to a particular port on a particular host.
bool set_localhost(int port)
Sets the address up to refer to a particular port, on this host.
std::string get_ip_string() const
Returns the IP address to which this address refers, formatted as a string.
int get_port() const
Returns the port number to which this address refers.
bool set_any(int port)
Sets the address up to refer to a particular port, but not to any particular IP.
const Socket_Address & get_addr() const
Returns the Socket_Address for this address.
bool is_any() const
Returns true if the IP address has only zeroes.
uint8_t get_ip_component(int n) const
Returns the nth 8-bit component of the IP address.
uint32_t get_ip() const
Returns the IP address to which this address refers, as a 32-bit integer, in host byte order.
bool set_broadcast(int port)
Sets the address to the broadcast address.
NetAddress()
Constructs an unspecified address.
void set_port(int port)
Resets the port number without otherwise changing the address.
A simple place to store and manipulate tcp and port address for communication layer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.