From b0c66c8dd7ffb9c24ff6a0582c53e7fdeedc5670 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 26 Oct 2000 18:05:15 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/net/connectionListener.cxx | 2 +- panda/src/net/connectionManager.cxx | 4 +-- panda/src/net/netAddress.cxx | 32 +++++++++++++++++++-- panda/src/net/netAddress.h | 5 +++- panda/src/net/test_spam_client.cxx | 2 +- panda/src/net/test_spam_server.cxx | 4 +-- panda/src/net/test_tcp_client.cxx | 10 ++++--- panda/src/net/test_tcp_server.cxx | 8 +++--- panda/src/net/test_udp.cxx | 6 ++-- pandatool/src/pstatserver/pStatListener.cxx | 2 +- 10 files changed, 53 insertions(+), 22 deletions(-) diff --git a/panda/src/net/connectionListener.cxx b/panda/src/net/connectionListener.cxx index e4677f3237..4d191842d8 100644 --- a/panda/src/net/connectionListener.cxx +++ b/panda/src/net/connectionListener.cxx @@ -54,7 +54,7 @@ process_incoming_data(SocketInfo *sinfo) { } else { NetAddress net_addr(addr); net_cat.info() - << "Received TCP connection from client " << net_addr.get_ip() + << "Received TCP connection from client " << net_addr.get_ip_string() << " on port " << sinfo->_connection->get_address().get_port() << "\n"; diff --git a/panda/src/net/connectionManager.cxx b/panda/src/net/connectionManager.cxx index 960db0f083..3bb1f40cff 100644 --- a/panda/src/net/connectionManager.cxx +++ b/panda/src/net/connectionManager.cxx @@ -164,13 +164,13 @@ open_TCP_client_connection(const NetAddress &address, int timeout_ms) { } net_cat.info() << "Unable to open TCP connection to server " - << address.get_ip() << " on port " << address.get_port() << "\n"; + << address.get_ip_string() << " on port " << address.get_port() << "\n"; PR_Close(socket); return PT(Connection)(); } net_cat.info() - << "Opened TCP connection to server " << address.get_ip() << " " + << "Opened TCP connection to server " << address.get_ip_string() << " " << " on port " << address.get_port() << "\n"; PT(Connection) connection = new Connection(this, socket); diff --git a/panda/src/net/netAddress.cxx b/panda/src/net/netAddress.cxx index 7a4e73f02d..3eb30622e6 100644 --- a/panda/src/net/netAddress.cxx +++ b/panda/src/net/netAddress.cxx @@ -126,13 +126,13 @@ set_port(int port) { } //////////////////////////////////////////////////////////////////// -// Function: NetAddress::get_ip +// Function: NetAddress::get_ip_string // Access: Public // Description: Returns the IP address to which this address refers, // formatted as a string. //////////////////////////////////////////////////////////////////// string NetAddress:: -get_ip() const { +get_ip_string() const { static const int buf_len = 1024; char buf[buf_len]; @@ -146,6 +146,32 @@ get_ip() const { return string(buf); } +//////////////////////////////////////////////////////////////////// +// Function: NetAddress::get_ip +// Access: Public +// Description: Returns the IP address to which this address refers, +// as a 32-bit integer, in host byte order. +//////////////////////////////////////////////////////////////////// +PN_uint32 NetAddress:: +get_ip() const { + return PR_ntohl(_addr.inet.ip); +} + +//////////////////////////////////////////////////////////////////// +// Function: NetAddress::get_ip_component +// Access: Public +// Description: Returns the nth 8-bit component of the IP address. +// An IP address has four components; component 0 is the +// first (leftmost), and component 3 is the last +// (rightmost) in the dotted number convention. +//////////////////////////////////////////////////////////////////// +PN_uint8 NetAddress:: +get_ip_component(int n) const { + nassertr(n >= 0 && n < 4, 0); + const PN_uint8 *ip = (const PN_uint8 *)&_addr.inet.ip; + return ip[n]; +} + //////////////////////////////////////////////////////////////////// // Function: NetAddress::get_addr @@ -164,5 +190,5 @@ get_addr() const { //////////////////////////////////////////////////////////////////// void NetAddress:: output(ostream &out) const { - out << get_ip(); + out << get_ip_string(); } diff --git a/panda/src/net/netAddress.h b/panda/src/net/netAddress.h index 39c5bd8832..60b1611e7f 100644 --- a/panda/src/net/netAddress.h +++ b/panda/src/net/netAddress.h @@ -7,6 +7,7 @@ #define NETADDRESS_H #include +#include #include @@ -28,7 +29,9 @@ public: int get_port() const; void set_port(int port); - string get_ip() const; + string get_ip_string() const; + PN_uint32 get_ip() const; + PN_uint8 get_ip_component(int n) const; PRNetAddr *get_addr() const; diff --git a/panda/src/net/test_spam_client.cxx b/panda/src/net/test_spam_client.cxx index 0ccf3b8897..ae5f5df658 100644 --- a/panda/src/net/test_spam_client.cxx +++ b/panda/src/net/test_spam_client.cxx @@ -70,7 +70,7 @@ main(int argc, char *argv[]) { PT(Connection) connection; if (cm.get_reset_connection(connection)) { nout << "Lost connection from " - << connection->get_address().get_ip() << "\n"; + << connection->get_address() << "\n"; cm.close_connection(connection); if (connection == c) { lost_connection = true; diff --git a/panda/src/net/test_spam_server.cxx b/panda/src/net/test_spam_server.cxx index 1f694b05d3..5ea8602d9d 100644 --- a/panda/src/net/test_spam_server.cxx +++ b/panda/src/net/test_spam_server.cxx @@ -63,7 +63,7 @@ main(int argc, char *argv[]) { NetAddress address; PT(Connection) new_connection; if (listener.get_new_connection(rv, address, new_connection)) { - nout << "Got connection from " << address.get_ip() << "\n"; + nout << "Got connection from " << address << "\n"; reader.add_connection(new_connection); clients.insert(new_connection); } @@ -74,7 +74,7 @@ main(int argc, char *argv[]) { PT(Connection) connection; if (cm.get_reset_connection(connection)) { nout << "Lost connection from " - << connection->get_address().get_ip() << "\n"; + << connection->get_address() << "\n"; clients.erase(connection); cm.close_connection(connection); } diff --git a/panda/src/net/test_tcp_client.cxx b/panda/src/net/test_tcp_client.cxx index 982af496b8..e7c7e296e1 100644 --- a/panda/src/net/test_tcp_client.cxx +++ b/panda/src/net/test_tcp_client.cxx @@ -35,8 +35,10 @@ main(int argc, char *argv[]) { exit(1); } - nout << "Successfully opened TCP connection to " << hostname - << " on port " << port << "\n"; + nout << "Successfully opened TCP connection to " << hostname + << " on port " + << c->get_address().get_port() << " and IP " + << c->get_address() << "\n"; QueuedConnectionReader reader(&cm, 0); reader.add_connection(c); @@ -57,7 +59,7 @@ main(int argc, char *argv[]) { PT(Connection) connection; if (cm.get_reset_connection(connection)) { nout << "Lost connection from " - << connection->get_address().get_ip() << "\n"; + << connection->get_address() << "\n"; cm.close_connection(connection); if (connection == c) { lost_connection = true; @@ -69,7 +71,7 @@ main(int argc, char *argv[]) { while (reader.data_available()) { if (reader.get_data(datagram)) { nout << "Got datagram " << datagram << "from " - << datagram.get_address().get_ip() << "\n"; + << datagram.get_address() << "\n"; } } diff --git a/panda/src/net/test_tcp_server.cxx b/panda/src/net/test_tcp_server.cxx index 73610c356d..8f8dcb49dc 100644 --- a/panda/src/net/test_tcp_server.cxx +++ b/panda/src/net/test_tcp_server.cxx @@ -53,7 +53,7 @@ main(int argc, char *argv[]) { NetAddress address; PT(Connection) new_connection; if (listener.get_new_connection(rv, address, new_connection)) { - nout << "Got connection from " << address.get_ip() << "\n"; + nout << "Got connection from " << address << "\n"; reader.add_connection(new_connection); clients.insert(new_connection); } @@ -64,7 +64,7 @@ main(int argc, char *argv[]) { PT(Connection) connection; if (cm.get_reset_connection(connection)) { nout << "Lost connection from " - << connection->get_address().get_ip() << "\n"; + << connection->get_address() << "\n"; clients.erase(connection); cm.close_connection(connection); } @@ -75,7 +75,7 @@ main(int argc, char *argv[]) { NetDatagram datagram; if (reader.get_data(datagram)) { nout << "Got datagram " << datagram << "from " - << datagram.get_address().get_ip() << ", sending to " + << datagram.get_address() << ", sending to " << clients.size() << " clients.\n"; Clients::iterator ci; @@ -91,7 +91,7 @@ main(int argc, char *argv[]) { nout << "Empty datagram from a null connection.\n"; } else { nout << "Closing connection from " - << connection->get_address().get_ip() << "\n"; + << connection->get_address() << "\n"; clients.erase(connection); cm.close_connection(connection); nout << "Closed " << connection << "\n"; diff --git a/panda/src/net/test_udp.cxx b/panda/src/net/test_udp.cxx index 97f237102a..033f6243cb 100644 --- a/panda/src/net/test_udp.cxx +++ b/panda/src/net/test_udp.cxx @@ -37,7 +37,7 @@ main(int argc, char *argv[]) { nout << "Successfully opened UDP connection on port " << c->get_address().get_port() << " and IP " - << c->get_address().get_ip() << "\n"; + << c->get_address() << "\n"; RecentConnectionReader reader(&cm); reader.add_connection(c); @@ -58,7 +58,7 @@ main(int argc, char *argv[]) { PT(Connection) connection; if (cm.get_reset_connection(connection)) { nout << "Lost connection from " - << connection->get_address().get_ip() << "\n"; + << connection->get_address() << "\n"; cm.close_connection(connection); if (connection == c) { lost_connection = true; @@ -70,7 +70,7 @@ main(int argc, char *argv[]) { while (reader.data_available()) { if (reader.get_data(datagram)) { nout << "Got datagram " << datagram << "from " - << datagram.get_address().get_ip() << "\n"; + << datagram.get_address() << "\n"; } } diff --git a/pandatool/src/pstatserver/pStatListener.cxx b/pandatool/src/pstatserver/pStatListener.cxx index fd5349b1cc..643d6c2789 100644 --- a/pandatool/src/pstatserver/pStatListener.cxx +++ b/pandatool/src/pstatserver/pStatListener.cxx @@ -35,7 +35,7 @@ connection_opened(const PT(Connection) &, return; } - nout << "Got new connection from " << address.get_ip() << "\n"; + nout << "Got new connection from " << address << "\n"; PStatReader *reader = new PStatReader(_manager, monitor); _manager->add_reader(new_connection, reader);