Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<arpa/inet.h>
- #include<string>
- #include<stdlib.h>
- using namespace std;
- int main(int argc, char * argv[]){
- string adres = argv[1];
- int mask;
- size_t pos = adres.find('/');
- string _mask = adres.substr(pos+1);
- mask = atoi(_mask.c_str());
- cout << "Maska " << mask << endl;
- in_addr IP;
- adres.erase(pos, adres.length() - pos);
- //IP.s_addr = inet_addr(adres.c_str());
- inet_aton(adres.c_str(), &IP );
- cout << "IP sieciowy porzadek bajtow" << hex << IP.s_addr << endl;
- in_addr ip;
- ip.s_addr = ntohl(IP.s_addr);
- cout << "IP hosta " << hex << ip.s_addr;
- cout << " " << inet_ntoa(IP) << endl;
- long MASK = 0xffffffff;
- MASK <<= 32 - mask;
- cout << "mask " << hex << MASK << endl;
- long network = ip.s_addr & MASK;
- cout << "network " << network << endl;
- long broadcast = (ip.s_addr | (!MASK));
- cout << "broadcast " << hex << broadcast << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment