浏览代码

*** empty log message ***

David Rose 25 年之前
父节点
当前提交
b0c66c8dd7

+ 1 - 1
panda/src/net/connectionListener.cxx

@@ -54,7 +54,7 @@ process_incoming_data(SocketInfo *sinfo) {
   } else {
   } else {
     NetAddress net_addr(addr);
     NetAddress net_addr(addr);
     net_cat.info()
     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()
       << " on port " << sinfo->_connection->get_address().get_port()
       << "\n";
       << "\n";
 
 

+ 2 - 2
panda/src/net/connectionManager.cxx

@@ -164,13 +164,13 @@ open_TCP_client_connection(const NetAddress &address, int timeout_ms) {
     }
     }
     net_cat.info()
     net_cat.info()
       << "Unable to open TCP connection to server " 
       << "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);
     PR_Close(socket);
     return PT(Connection)();
     return PT(Connection)();
   }
   }
 
 
   net_cat.info()
   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";
     << " on port " << address.get_port() << "\n";
 
 
   PT(Connection) connection = new Connection(this, socket);
   PT(Connection) connection = new Connection(this, socket);

+ 29 - 3
panda/src/net/netAddress.cxx

@@ -126,13 +126,13 @@ set_port(int port) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: NetAddress::get_ip
+//     Function: NetAddress::get_ip_string
 //       Access: Public
 //       Access: Public
 //  Description: Returns the IP address to which this address refers,
 //  Description: Returns the IP address to which this address refers,
 //               formatted as a string.
 //               formatted as a string.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 string NetAddress::
 string NetAddress::
-get_ip() const {
+get_ip_string() const {
   static const int buf_len = 1024;
   static const int buf_len = 1024;
   char buf[buf_len];
   char buf[buf_len];
 
 
@@ -146,6 +146,32 @@ get_ip() const {
   return string(buf);
   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
 //     Function: NetAddress::get_addr
@@ -164,5 +190,5 @@ get_addr() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void NetAddress::
 void NetAddress::
 output(ostream &out) const {
 output(ostream &out) const {
-  out << get_ip();
+  out << get_ip_string();
 }
 }

+ 4 - 1
panda/src/net/netAddress.h

@@ -7,6 +7,7 @@
 #define NETADDRESS_H
 #define NETADDRESS_H
 
 
 #include <pandabase.h>
 #include <pandabase.h>
+#include <numeric_types.h>
 
 
 #include <prio.h>
 #include <prio.h>
 
 
@@ -28,7 +29,9 @@ public:
 
 
   int get_port() const;
   int get_port() const;
   void set_port(int port);
   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;
   PRNetAddr *get_addr() const;
 
 

+ 1 - 1
panda/src/net/test_spam_client.cxx

@@ -70,7 +70,7 @@ main(int argc, char *argv[]) {
       PT(Connection) connection;
       PT(Connection) connection;
         if (cm.get_reset_connection(connection)) {
         if (cm.get_reset_connection(connection)) {
 	nout << "Lost connection from "
 	nout << "Lost connection from "
-	     << connection->get_address().get_ip() << "\n";
+	     << connection->get_address() << "\n";
 	cm.close_connection(connection);
 	cm.close_connection(connection);
 	if (connection == c) {
 	if (connection == c) {
 	  lost_connection = true;
 	  lost_connection = true;

+ 2 - 2
panda/src/net/test_spam_server.cxx

@@ -63,7 +63,7 @@ main(int argc, char *argv[]) {
       NetAddress address;
       NetAddress address;
       PT(Connection) new_connection;
       PT(Connection) new_connection;
       if (listener.get_new_connection(rv, address, 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);
 	reader.add_connection(new_connection);
 	clients.insert(new_connection);
 	clients.insert(new_connection);
       }
       }
@@ -74,7 +74,7 @@ main(int argc, char *argv[]) {
       PT(Connection) connection;
       PT(Connection) connection;
       if (cm.get_reset_connection(connection)) {
       if (cm.get_reset_connection(connection)) {
 	nout << "Lost connection from "
 	nout << "Lost connection from "
-	     << connection->get_address().get_ip() << "\n";
+	     << connection->get_address() << "\n";
 	clients.erase(connection);
 	clients.erase(connection);
 	cm.close_connection(connection);
 	cm.close_connection(connection);
       }
       }

+ 6 - 4
panda/src/net/test_tcp_client.cxx

@@ -35,8 +35,10 @@ main(int argc, char *argv[]) {
     exit(1);
     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);
   QueuedConnectionReader reader(&cm, 0);
   reader.add_connection(c);
   reader.add_connection(c);
@@ -57,7 +59,7 @@ main(int argc, char *argv[]) {
       PT(Connection) connection;
       PT(Connection) connection;
       if (cm.get_reset_connection(connection)) {
       if (cm.get_reset_connection(connection)) {
 	nout << "Lost connection from "
 	nout << "Lost connection from "
-	     << connection->get_address().get_ip() << "\n";
+	     << connection->get_address() << "\n";
 	cm.close_connection(connection);
 	cm.close_connection(connection);
 	if (connection == c) {
 	if (connection == c) {
 	  lost_connection = true;
 	  lost_connection = true;
@@ -69,7 +71,7 @@ main(int argc, char *argv[]) {
     while (reader.data_available()) {
     while (reader.data_available()) {
       if (reader.get_data(datagram)) {
       if (reader.get_data(datagram)) {
 	nout << "Got datagram " << datagram << "from " 
 	nout << "Got datagram " << datagram << "from " 
-	     << datagram.get_address().get_ip() << "\n";
+	     << datagram.get_address() << "\n";
       }
       }
     }
     }
 
 

+ 4 - 4
panda/src/net/test_tcp_server.cxx

@@ -53,7 +53,7 @@ main(int argc, char *argv[]) {
       NetAddress address;
       NetAddress address;
       PT(Connection) new_connection;
       PT(Connection) new_connection;
       if (listener.get_new_connection(rv, address, 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);
 	reader.add_connection(new_connection);
 	clients.insert(new_connection);
 	clients.insert(new_connection);
       }
       }
@@ -64,7 +64,7 @@ main(int argc, char *argv[]) {
       PT(Connection) connection;
       PT(Connection) connection;
       if (cm.get_reset_connection(connection)) {
       if (cm.get_reset_connection(connection)) {
 	nout << "Lost connection from "
 	nout << "Lost connection from "
-	     << connection->get_address().get_ip() << "\n";
+	     << connection->get_address() << "\n";
 	clients.erase(connection);
 	clients.erase(connection);
 	cm.close_connection(connection);
 	cm.close_connection(connection);
       }
       }
@@ -75,7 +75,7 @@ main(int argc, char *argv[]) {
       NetDatagram datagram;
       NetDatagram datagram;
       if (reader.get_data(datagram)) {
       if (reader.get_data(datagram)) {
 	nout << "Got datagram " << datagram << "from " 
 	nout << "Got datagram " << datagram << "from " 
-	     << datagram.get_address().get_ip() << ", sending to "
+	     << datagram.get_address() << ", sending to "
 	     << clients.size() << " clients.\n";
 	     << clients.size() << " clients.\n";
 	
 	
 	Clients::iterator ci;
 	Clients::iterator ci;
@@ -91,7 +91,7 @@ main(int argc, char *argv[]) {
 	    nout << "Empty datagram from a null connection.\n";
 	    nout << "Empty datagram from a null connection.\n";
 	  } else {
 	  } else {
 	    nout << "Closing connection from " 
 	    nout << "Closing connection from " 
-		 << connection->get_address().get_ip() << "\n";
+		 << connection->get_address() << "\n";
 	    clients.erase(connection);
 	    clients.erase(connection);
 	    cm.close_connection(connection);
 	    cm.close_connection(connection);
 	    nout << "Closed " << connection << "\n";
 	    nout << "Closed " << connection << "\n";

+ 3 - 3
panda/src/net/test_udp.cxx

@@ -37,7 +37,7 @@ main(int argc, char *argv[]) {
 
 
   nout << "Successfully opened UDP connection on port " 
   nout << "Successfully opened UDP connection on port " 
        << c->get_address().get_port() << " and IP "
        << c->get_address().get_port() << " and IP "
-       << c->get_address().get_ip() << "\n";
+       << c->get_address() << "\n";
 
 
   RecentConnectionReader reader(&cm);
   RecentConnectionReader reader(&cm);
   reader.add_connection(c);
   reader.add_connection(c);
@@ -58,7 +58,7 @@ main(int argc, char *argv[]) {
       PT(Connection) connection;
       PT(Connection) connection;
       if (cm.get_reset_connection(connection)) {
       if (cm.get_reset_connection(connection)) {
 	nout << "Lost connection from "
 	nout << "Lost connection from "
-	     << connection->get_address().get_ip() << "\n";
+	     << connection->get_address() << "\n";
 	cm.close_connection(connection);
 	cm.close_connection(connection);
 	if (connection == c) {
 	if (connection == c) {
 	  lost_connection = true;
 	  lost_connection = true;
@@ -70,7 +70,7 @@ main(int argc, char *argv[]) {
     while (reader.data_available()) {
     while (reader.data_available()) {
       if (reader.get_data(datagram)) {
       if (reader.get_data(datagram)) {
 	nout << "Got datagram " << datagram << "from " 
 	nout << "Got datagram " << datagram << "from " 
-	     << datagram.get_address().get_ip() << "\n";
+	     << datagram.get_address() << "\n";
       }
       }
     }
     }
 
 

+ 1 - 1
pandatool/src/pstatserver/pStatListener.cxx

@@ -35,7 +35,7 @@ connection_opened(const PT(Connection) &,
     return;
     return;
   }
   }
 
 
-  nout << "Got new connection from " << address.get_ip() << "\n";
+  nout << "Got new connection from " << address << "\n";
 
 
   PStatReader *reader = new PStatReader(_manager, monitor);
   PStatReader *reader = new PStatReader(_manager, monitor);
   _manager->add_reader(new_connection, reader);
   _manager->add_reader(new_connection, reader);