crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

iphashtest.cc (948B)


      1 // C
      2 #include <errno.h>
      3 #include <fcntl.h>
      4 #include <getopt.h>
      5 #include <netdb.h>
      6 #include <signal.h>
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 #include <string.h>
     10 #include <pthread.h>
     11 #include <unistd.h>
     12 #include <arpa/inet.h>
     13 #include <netinet/in.h>
     14 #include <sys/select.h>
     15 #include <sys/socket.h>
     16 #include <sys/time.h>
     17 #include <sys/types.h>
     18 
     19 // C++
     20 #include <iostream>
     21 #include <map>
     22 #include <sstream>
     23 #include <string>
     24 #include <vector>
     25 
     26 using namespace std;
     27 
     28 int main () {
     29     for (int a = 0; a <= 255; a++) {
     30 	ostringstream o;
     31 	o << "192.168.1." << a;
     32 
     33 	struct in_addr ad;
     34 	inet_aton (o.str().c_str(), &ad);
     35 
     36 	unsigned index = 0;
     37 	for (char *cp = (char*) &ad;
     38 	     unsigned(cp - (char*)&ad) < sizeof(struct in_addr);
     39 	     cp++) {
     40 	    index += *cp;
     41 	    index %= 60;
     42 	    //cout << " " << "byte: " << hex << *cp
     43 	    // << ", index: " << index << "\n";
     44 	}
     45 
     46 	cout << inet_ntoa(ad) <<  ": " << dec << index << "\n";
     47     }
     48 
     49     return (0);
     50 }
     51