File: iphashtest.cc

package info (click to toggle)
crossroads 2.65-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,664 kB
  • ctags: 355
  • sloc: cpp: 4,212; perl: 1,658; xml: 269; makefile: 186; sh: 46
file content (51 lines) | stat: -rw-r--r-- 948 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// C
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>

// C++
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main () {
    for (int a = 0; a <= 255; a++) {
	ostringstream o;
	o << "192.168.1." << a;

	struct in_addr ad;
	inet_aton (o.str().c_str(), &ad);

	unsigned index = 0;
	for (char *cp = (char*) &ad;
	     unsigned(cp - (char*)&ad) < sizeof(struct in_addr);
	     cp++) {
	    index += *cp;
	    index %= 60;
	    //cout << " " << "byte: " << hex << *cp
	    // << ", index: " << index << "\n";
	}

	cout << inet_ntoa(ad) <<  ": " << dec << index << "\n";
    }

    return (0);
}