Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9310 in orxonox.OLD for branches/proxy/src


Ignore:
Timestamp:
Jul 18, 2006, 1:30:58 AM (18 years ago)
Author:
bensch
Message:

ip is ready for deplyment

Location:
branches/proxy/src/lib/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/ip.cc

    r9307 r9310  
    3737 * @brief constructor from a String
    3838 * @param ip the IP as a String.
    39  * @return self
    40  */
    41 IP::IP(const std::string& ip)
    42 {
    43   *this = IP::stringToIP(ip);
     39 * @param port The port to be resolved.
     40 * @param resolve if true, the IP is resolved via DNS,
     41 * @return self
     42 */
     43IP::IP(const std::string& ip, int port, bool resolve)
     44{
     45  *this = IP::stringToIP(ip, port, resolve);
    4446}
    4547
     
    98100 * @brief converts a String into an IP Object.
    99101 * @param ip The string holding an IP.
    100  * @return a constructed IP.
    101  */
    102 IP IP::stringToIP(const std::string& ip)
    103 {
    104   IPaddress ipaddr;
    105 
    106   SDLNet_ResolveHost(&ipaddr, NULL, 2000);
    107 
    108   return IP(ipaddr);
    109 
    110   /*
    111   SubString addr(ip, '.');
    112   if(ip.size() != 4 )
    113     return -1;
    114 
    115   MultiType part0(ip[0]);
    116   MultiType part1(ip[1]);
    117   MultiType part2(ip[2]);
    118   MultiType part3(ip[3]);
    119   */
     102 * @param port The port to be resolved.
     103 * @param resolve if true, the IP is resolved via DNS,
     104 * otherwise (resolve == false) the IP is being transformed
     105 * from a String (xxx.xxx.xxx.xxx) to an integer.
     106 *
     107 * @return A newly constructed IP.
     108 */
     109IP IP::stringToIP(const std::string& ip, int port, bool resolve)
     110{
     111  if (resolve)
     112  {
     113    IPaddress ipaddr;
     114
     115    SDLNet_ResolveHost(&ipaddr, NULL, 2000);
     116
     117    return IP(ipaddr.host, port);
     118  }
     119  else
     120  {
     121    SubString ipaddr(ip, '.');
     122    if(ip.size() != 4 )
     123      return IP();
     124
     125    MultiType part0(ipaddr[0]);
     126    MultiType part1(ipaddr[1]);
     127    MultiType part2(ipaddr[2]);
     128    MultiType part3(ipaddr[3]);
     129
     130    int addr = (part0.getInt() << 24) +
     131               (part1.getInt() << 16) +
     132               (part2.getInt() <<  8) +
     133               part3.getInt();
     134    return IP(addr, port);
     135  }
    120136}
    121137
     
    170186
    171187/**
    172  * converts a IP into a String (without port).
     188 * @brief converts a IP into a String (without port).
    173189 * @param ip the IP to put into the string.
    174190 * @param port -1 if not wanted
  • branches/proxy/src/lib/network/ip.h

    r9307 r9310  
    2121  public:
    2222    IP();
    23     IP(const std::string& ip);
     23    IP(const std::string& ip, int port = -1, bool resolve = true);
    2424    IP(int ip, int port);
    2525    IP(const IPaddress& ip);
     
    3030
    3131
     32    /** @returns the IP */
    3233    int ip() const { return this->_ip; };
     34    /** @returns the Port */
    3335    short port() const { return this->_port; };
    3436
     
    3638    std::string ipString() const;
    3739
    38 
    39 
    4040  public:
    41     static IP stringToIP(const std::string& ip);
     41    static IP stringToIP(const std::string& ip, int port = -1, bool resolve = true);
    4242
    4343
Note: See TracChangeset for help on using the changeset viewer.