madzik4113

sieci1

Mar 10th, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1.  
  2.  
  3. #include<arpa/inet.h>
  4. #include<string>
  5. #include<stdlib.h>
  6. using namespace std;
  7.  
  8. int main(int argc, char * argv[]){
  9.  
  10. string adres = argv[1];
  11. int mask;
  12. size_t pos = adres.find('/');
  13. string _mask = adres.substr(pos+1);
  14. mask = atoi(_mask.c_str());
  15. cout << "Maska " << mask << endl;
  16.  
  17. in_addr IP;
  18. adres.erase(pos, adres.length() - pos);
  19. //IP.s_addr = inet_addr(adres.c_str());
  20. inet_aton(adres.c_str(), &IP );
  21. cout << "IP sieciowy porzadek bajtow" << hex << IP.s_addr << endl;
  22.  
  23. in_addr ip;
  24. ip.s_addr = ntohl(IP.s_addr);
  25. cout << "IP hosta " << hex << ip.s_addr;
  26. cout << " " << inet_ntoa(IP) << endl;
  27.  
  28. long MASK = 0xffffffff;
  29. MASK <<= 32 - mask;
  30. cout << "mask " << hex << MASK << endl;
  31.  
  32. long network = ip.s_addr & MASK;
  33. cout << "network " << network << endl;
  34.  
  35. long broadcast = (ip.s_addr | (!MASK));
  36. cout << "broadcast " << hex << broadcast << endl;
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment