sources/network/ipaddress.h

Thu, 11 Dec 2014 05:59:43 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 11 Dec 2014 05:59:43 +0200
changeset 6
c709bb1a08e4
parent 5
146825d63b9a
child 7
01e4e9ae323a
permissions
-rw-r--r--

- udp -> udpsocket

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

struct sockaddr;

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;
};

extern const IPAddress localhost;

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