sources/network/ipaddress.h

Thu, 11 Dec 2014 07:18:11 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 11 Dec 2014 07:18:11 +0200
changeset 8
8b697d30c49f
parent 7
01e4e9ae323a
child 9
e7a09ceb4505
permissions
-rw-r--r--

- added huffman lib, now capable of initializing an rcon connection!

#pragma once
#include "../main.h"

struct sockaddr;
struct sockaddr_in;

enum WithPort { IP_WITH_PORT, IP_NO_PORT };

struct IPAddress
{
	unsigned long host;
	unsigned short port;
	static bool sink;

	IPAddress();
	IPAddress (unsigned long host, unsigned short port);
	IPAddress (const IPAddress& other);

	       METHOD compare (const IPAddress& other) const -> bool;
	       METHOD octet (int n) const -> unsigned char;
	       METHOD set_octet (int n, unsigned char oct) -> void;
	       METHOD to_string (WithPort withport = IP_NO_PORT) const -> String;
	       METHOD to_sockaddr_in() const -> sockaddr_in;
	       METHOD operator< (const IPAddress& other) const -> bool;
	inline METHOD operator== (const IPAddress& other) const -> bool;
	inline METHOD operator!= (const IPAddress& other) const -> bool;
	inline METHOD operator[] (int n) const -> unsigned char;

	static METHOD from_string (String input, bool* ok = &sink) -> IPAddress;
	static METHOD resolve (String node, bool* ok = &sink) -> IPAddress;
};

static const unsigned long localhost = 0x7F000001;

inline METHOD
IPAddress::operator[] (int n) const -> unsigned char
{
	return octet (n);
}

inline METHOD
IPAddress::operator== (const IPAddress& other) const -> bool
{
	return compare (other);
}

inline METHOD
IPAddress::operator!= (const IPAddress& other) const -> bool
{
	return not operator== (other);
}

mercurial