|
@@ -59,29 +59,87 @@ THE SOFTWARE.
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
namespace Polycode {
|
|
namespace Polycode {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * A typical network address, defined by IP and port.
|
|
|
|
|
+ */
|
|
|
class _PolyExport Address {
|
|
class _PolyExport Address {
|
|
|
public:
|
|
public:
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructor.
|
|
|
|
|
+ * @param ipAsString An IP address represented as string,
|
|
|
|
|
+ * for example "197.0.0.1"
|
|
|
|
|
+ * @param port The UDP/TCP port of the address, given in
|
|
|
|
|
+ * host byte order.
|
|
|
|
|
+ */
|
|
|
Address(String ipAsString, unsigned int port);
|
|
Address(String ipAsString, unsigned int port);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructor.
|
|
|
|
|
+ * @param ip An IP address given as integer in host byte
|
|
|
|
|
+ * order.
|
|
|
|
|
+ * @param port The UDP/TCP port of the address, given in
|
|
|
|
|
+ * host byte order.
|
|
|
|
|
+ */
|
|
|
Address(unsigned int ip, unsigned int port);
|
|
Address(unsigned int ip, unsigned int port);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructor, leaving the address uninitalized.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Address IP and port will default to 0.
|
|
|
|
|
+ */
|
|
|
Address();
|
|
Address();
|
|
|
~Address();
|
|
~Address();
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Copy the address IP and port from add2 into this.
|
|
|
|
|
+ * @param add2 The address to copy into this.
|
|
|
|
|
+ */
|
|
|
inline void operator = (const Address &add2) {
|
|
inline void operator = (const Address &add2) {
|
|
|
setAddress(add2.uintAddress, add2.port);
|
|
setAddress(add2.uintAddress, add2.port);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @return 1 if the address IP and port match, 0 otherwise.
|
|
|
|
|
+ */
|
|
|
inline bool operator == ( const Address& add2) {
|
|
inline bool operator == ( const Address& add2) {
|
|
|
return (uintAddress == add2.uintAddress && port == add2.port);
|
|
return (uintAddress == add2.uintAddress && port == add2.port);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Update the address IP and port.
|
|
|
|
|
+ * @param ipAsString An IP address represented as string,
|
|
|
|
|
+ * for example "197.0.0.1"
|
|
|
|
|
+ * @param port The UDP/TCP port of the address, given in
|
|
|
|
|
+ * host byte order.
|
|
|
|
|
+ */
|
|
|
void setAddress(String ipAsString, unsigned int port);
|
|
void setAddress(String ipAsString, unsigned int port);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Update the address IP and port.
|
|
|
|
|
+ * @param ip An IP address given as integer in host byte
|
|
|
|
|
+ * order.
|
|
|
|
|
+ * @param port The UDP/TCP port of the address, given in
|
|
|
|
|
+ * host byte order.
|
|
|
|
|
+ */
|
|
|
void setAddress(unsigned int ip, unsigned int port);
|
|
void setAddress(unsigned int ip, unsigned int port);
|
|
|
|
|
|
|
|
|
|
+ // TODO: A way to get the IP/port without exposing internal members.
|
|
|
|
|
+ // The problem here is that the IP internally is converted to
|
|
|
|
|
+ // network byte order, but the API seems to work with host byte
|
|
|
|
|
+ // order, so I'm unsure in which byte order the IP/port should
|
|
|
|
|
+ // be returned.
|
|
|
|
|
+
|
|
|
|
|
+ protected:
|
|
|
unsigned int uintAddress;
|
|
unsigned int uintAddress;
|
|
|
unsigned int port;
|
|
unsigned int port;
|
|
|
- sockaddr_in sockAddress;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ sockaddr_in sockAddress;
|
|
|
|
|
+
|
|
|
|
|
+ // This class already uses socket API structs internally,
|
|
|
|
|
+ // so it's no far stretch to make it tied to the Socket class.
|
|
|
|
|
+ friend class Socket;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|