(svn r15914) -Codechange: let the content handling make use of NetworkAddress.

pull/155/head
rubidium 15 years ago
parent 129586388d
commit 822ff14d73

@ -7,7 +7,9 @@
#ifdef ENABLE_NETWORK
#include "address.h"
#include "config.h"
#include "host.h"
#include "../../string_func.h"
const char *NetworkAddress::GetHostname() const
{
@ -27,4 +29,13 @@ uint32 NetworkAddress::GetIP()
return this->ip;
}
const char *NetworkAddress::GetAddressAsString() const
{
/* 6 = for the : and 5 for the decimal port number */
static char buf[NETWORK_HOSTNAME_LENGTH + 6];
seprintf(buf, lastof(buf), "%s:%d", this->GetHostname(), this->GetPort());
return buf;
}
#endif /* ENABLE_NETWORK */

@ -40,9 +40,9 @@ public:
* @param ip the unresolved hostname
* @param port the port
*/
NetworkAddress(const char *hostname, uint16 port) :
NetworkAddress(const char *hostname = NULL, uint16 port = 0) :
resolved(false),
hostname(strdup(hostname)),
hostname(hostname == NULL ? NULL : strdup(hostname)),
ip(0),
port(port)
{
@ -73,6 +73,12 @@ public:
*/
const char *GetHostname() const;
/**
* Get the address as a string, e.g. 127.0.0.1:12345.
* @return the address
*/
const char *GetAddressAsString() const;
/**
* Get the IP address. If the IP has not been resolved yet this will resolve
* it possibly blocking this function for a while

@ -84,9 +84,9 @@ bool NetworkContentSocketHandler::HandlePacket(Packet *p)
default:
if (this->HasClientQuit()) {
DEBUG(net, 0, "[tcp/content] received invalid packet type %d from %s:%d", type, inet_ntoa(this->client_addr.sin_addr), ntohs(this->client_addr.sin_port));
DEBUG(net, 0, "[tcp/content] received invalid packet type %d from %s", type, this->client_addr.GetAddressAsString());
} else {
DEBUG(net, 0, "[tcp/content] received illegal packet from %s:%d", inet_ntoa(this->client_addr.sin_addr), ntohs(this->client_addr.sin_port));
DEBUG(net, 0, "[tcp/content] received illegal packet from %s", this->client_addr.GetAddressAsString());
}
return false;
}
@ -114,8 +114,8 @@ void NetworkContentSocketHandler::Recv_Packets()
*/
#define DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(type) \
bool NetworkContentSocketHandler::NetworkPacketReceive_## type ##_command(Packet *p) { \
DEBUG(net, 0, "[tcp/content] received illegal packet type %d from %s:%d", \
type, inet_ntoa(this->client_addr.sin_addr), ntohs(this->client_addr.sin_port)); \
DEBUG(net, 0, "[tcp/content] received illegal packet type %d from %s", \
type, this->client_addr.GetAddressAsString()); \
return false; \
}

@ -101,7 +101,7 @@ struct ContentInfo {
/** Base socket handler for all Content TCP sockets */
class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
protected:
struct sockaddr_in client_addr; ///< The address we're connected to.
struct NetworkAddress client_addr; ///< The address we're connected to.
virtual void Close();
/**
@ -187,12 +187,12 @@ public:
/**
* Create a new cs socket handler for a given cs
* @param s the socket we are connected with
* @param sin IP etc. of the client
* @param address IP etc. of the client
*/
NetworkContentSocketHandler(SOCKET s, const struct sockaddr_in *sin) :
NetworkTCPSocketHandler(s)
NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
NetworkTCPSocketHandler(s),
client_addr(address)
{
if (sin != NULL) this->client_addr = *sin;
}
/** On destructing of this class, the socket needs to be closed */

@ -426,7 +426,7 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
* @param sin the IP/port of the server
*/
ClientNetworkContentSocketHandler::ClientNetworkContentSocketHandler() :
NetworkContentSocketHandler(INVALID_SOCKET, NULL),
NetworkContentSocketHandler(),
curFile(NULL),
curInfo(NULL),
isConnecting(false)

Loading…
Cancel
Save