diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-05-12 17:24:51 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-05-12 17:28:25 -0700 |
commit | c87b1dc338eadc68accac02563a487d7d8e1c9a0 (patch) | |
tree | 4333dca2f664bd7170a7ff984abc8a2d1a643fb2 /src/mmo/ip.cpp | |
parent | 0659ef14f64e2c5d71601060717a761aded8381f (diff) | |
download | tmwa-c87b1dc338eadc68accac02563a487d7d8e1c9a0.tar.gz tmwa-c87b1dc338eadc68accac02563a487d7d8e1c9a0.tar.bz2 tmwa-c87b1dc338eadc68accac02563a487d7d8e1c9a0.tar.xz tmwa-c87b1dc338eadc68accac02563a487d7d8e1c9a0.zip |
Split net/ from mmo/
Diffstat (limited to 'src/mmo/ip.cpp')
-rw-r--r-- | src/mmo/ip.cpp | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/mmo/ip.cpp b/src/mmo/ip.cpp deleted file mode 100644 index 7c243ea..0000000 --- a/src/mmo/ip.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "ip.hpp" -// ip.cpp - Implementation of IP address functions. -// -// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. - -#include "../strings/xstring.hpp" -#include "../strings/vstring.hpp" - -#include "../io/cxxstdio.hpp" - -#include "extract.hpp" - -#include "../poison.hpp" - -bool extract(XString str, IP4Address *rv) -{ - if (str.endswith('.')) - return false; - uint8_t buf[4]; - if (extract(str, record<'.'>(&buf[0], &buf[1], &buf[2], &buf[3]))) - { - *rv = IP4Address(buf); - return true; - } - return false; -} - -bool extract(XString str, IP4Mask *rv) -{ - IP4Address a, m; - unsigned b; - XString l, r; - if (str.endswith('/')) - return false; - if (extract(str, record<'/'>(&l, &r))) - { - // a.b.c.d/e.f.g.h or a.b.c.d/n - if (!extract(l, &a)) - return false; - if (extract(r, &m)) - { - *rv = IP4Mask(a, m); - return true; - } - if (!extract(r, &b) || b > 32) - return false; - } - else - { - // a.b.c.d or a.b.c.d. or a.b.c. or a.b. or a. - if (extract(str, &a)) - { - *rv = IP4Mask(a, IP4_BROADCAST); - return true; - } - if (!str.endswith('.')) - return false; - uint8_t d[4] {}; - if (extract(str, record<'.'>(&d[0], &d[1], &d[2], &d[3]))) - b = 32; - else if (extract(str, record<'.'>(&d[0], &d[1], &d[2]))) - b = 24; - else if (extract(str, record<'.'>(&d[0], &d[1]))) - b = 16; - else if (extract(str, record<'.'>(&d[0]))) - b = 8; - else - return false; - a = IP4Address(d); - } - // a is set; need to construct m from b - if (b == 0) - m = IP4Address(); - else if (b == 32) - m = IP4_BROADCAST; - else - { - uint32_t s = -1; - s <<= (32 - b); - m = IP4Address({ - static_cast<uint8_t>(s >> 24), - static_cast<uint8_t>(s >> 16), - static_cast<uint8_t>(s >> 8), - static_cast<uint8_t>(s >> 0), - }); - } - *rv = IP4Mask(a, m); - return true; -} - -VString<15> convert_for_printf(IP4Address a_) -{ - const uint8_t *a = a_.bytes(); - return STRNPRINTF(16, "%hhu.%hhu.%hhu.%hhu"_fmt, a[0], a[1], a[2], a[3]); -} - -VString<31> convert_for_printf(IP4Mask a) -{ - return STRNPRINTF(32, "%s/%s"_fmt, - a.addr(), a.mask()); -} |