diff -r 0000000000000000000000000000000000000000 -r 8c8754db0e1e527ed2bbeefc2f624b53a3cacab1 build.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.bat Sun Aug 18 22:15:40 2013 -0500 @@ -0,0 +1,2 @@ +call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 +cl.exe /clr ip2long.cpp \ No newline at end of file diff -r 0000000000000000000000000000000000000000 -r 8c8754db0e1e527ed2bbeefc2f624b53a3cacab1 ip2long.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ip2long.cpp Sun Aug 18 22:15:40 2013 -0500 @@ -0,0 +1,115 @@ +#include +#include +#include //atoi +#include +#include +#include +#include + +using namespace std; + +typedef std::string::size_type (std::string::*find_t)(const std::string& delim, + std::string::size_type offset) const; + +template +inline string ToString(const T& t) +{ + stringstream ss; + ss << t; + return ss.str(); +} + +string str_pad(string s, unsigned int num, char pad) +{ + string tmppad; + if (s.length() <= num) + for(unsigned int i = (num - s.length()); i > 0; i--) + tmppad = tmppad + pad; + return tmppad + s; +} + +vector split(const string& s, + const string& match, + bool removeEmpty=false, + bool fullMatch=false) +{ + vector result; // return container for tokens + string::size_type start = 0, // starting position for searches + skip = 1; // positions to skip after a match + find_t pfind = &string::find_first_of; // search algorithm for matches + + if (fullMatch) + { + // use the whole match string as a key + // instead of individual characters + // skip might be 0. see search loop comments + skip = match.length(); + pfind = &string::find; + } + + while (start != string::npos) + { + // get a complete range [start..end) + string::size_type end = (s.*pfind)(match, start); + + // null strings always match in string::find, but + // a skip of 0 causes infinite loops. pretend that + // no tokens were found and extract the whole string + if (skip == 0) end = string::npos; + + string token = s.substr(start, end - start); + + if (!(removeEmpty && token.empty())) + { + // extract the token and add it to the result list + result.push_back(token); + } + + // start the next range + if ((start = end) != string::npos) start += skip; + } + + return result; +} + +string tobin(int dec) +{ + if (dec > 0) + return tobin(dec/2) + ToString(dec%2); + return ""; +} + +int main(int argc,char *argv[]) +{ + vector ip_addr_arr; + int oct1, oct2, oct3, oct4; + unsigned int addr; + string combinedoct; + string ip_addr; + string nlopt = ""; + if (argc == 2) + nlopt = argv[1]; + try + { + cin >> ip_addr; + ip_addr_arr = split(ip_addr, "."); + + oct1 = atoi(ip_addr_arr.at(0).c_str()); + oct2 = atoi(ip_addr_arr.at(1).c_str()); + oct3 = atoi(ip_addr_arr.at(2).c_str()); + oct4 = atoi(ip_addr_arr.at(3).c_str()); + + combinedoct = str_pad(tobin(oct1), 8, '0'); + combinedoct += str_pad(tobin(oct2), 8, '0'); + combinedoct += str_pad(tobin(oct3), 8, '0'); + combinedoct += str_pad(tobin(oct4), 8, '0'); + + addr = bitset<32>(combinedoct).to_ulong(); + cout << addr; + if (argc == 2 && nlopt == "-n") + cout << endl; + } catch (exception& e) { + cout << e.what() << endl; + } + return 0; +} diff -r 0000000000000000000000000000000000000000 -r 8c8754db0e1e527ed2bbeefc2f624b53a3cacab1 ip2long/DEBIAN/control --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ip2long/DEBIAN/control Sun Aug 18 22:15:40 2013 -0500 @@ -0,0 +1,8 @@ +Package: ip2long +Version: 1 +Section: base +Priority: optional +Architecture: all +Depends: bash +Maintainer: adamsna@datanethost.net +Description: Converts an IP to a long