Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9437 was 9426, checked in by bensch, 18 years ago

cleaner ip inclusion

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