Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/ip.h @ 9360

Last change on this file since 9360 was 9360, checked in by patrick, 18 years ago

network ip synchronization work

File size: 1.7 KB
Line 
1
2/*!
3 * @file ip.h
4 *
5 * @brief the ip class is used to transform strings to ip's and backwards
6 * it can also be used to
7 */
8
9#ifndef __IP_H__
10#define __IP_H__
11
12#include "netdefs.h"
13#include <string>
14
15
16
17//! A class to handle time itself
18class IP
19{
20  public:
21    /// CONSTRUCTORS
22    IP();
23    IP(int ip, int port);
24    IP(const std::string& ip, bool resolve = true);
25    IP(const std::string& ip, int port = -1, bool resolve = true);
26    IP(const IPaddress& ip);
27    IP(const IP& ip);
28
29    /// OPERATORS
30    const IP& operator=(const IP& ip);
31    const IP& operator=(const IPaddress& ip);
32    bool operator==(const IP& ip);
33    bool operator!=(const IP& up);
34
35    /// RETRIVEAL
36    /** @returns the IP */
37    int host() const { return this->_ip; };
38    int* hostRef()  { return &this->_ip; }
39    /** @returns the Port */
40    int port() const { return this->_port; };
41    int* portRef() { return &this->_port; };
42
43    inline IPaddress getSDLNotation() { IPaddress sdlIP; sdlIP.host = this->_ip; sdlIP.port = this->_port; return sdlIP; }
44
45    int ipPart(unsigned int part) const;
46    std::string ipString() const;
47
48    void debug() const;
49
50  public:
51    /// SETUP
52    static IP stringToIP(const std::string& ip, int port = -1, bool resolve = true);
53
54    static std::string ipToString(const IPaddress& ipaddr);
55    static std::string ipToString(int ip, int port = -1);
56
57    static void setDefaultPort(int defaultPort);
58    static int defaultPort(int defaultPort) { return IP::_defaultPort; };
59
60  private:
61    int           _ip;           //!< The IP in int form.
62    int         _port;         //!< The Port number of the IP
63
64    static int  _defaultPort;  //!< Default Port
65};
66
67#endif /* __IP_H__ */
Note: See TracBrowser for help on using the repository browser.