File: test.c

package info (click to toggle)
nessus-libraries 2.2.10-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,884 kB
  • ctags: 2,550
  • sloc: ansic: 21,402; sh: 8,231; makefile: 421; yacc: 234; lex: 203
file content (58 lines) | stat: -rw-r--r-- 1,271 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
52
53
54
55
56
57
58
#include <includes.h>
#include "hosts_gatherer.h"
/*
 * 
 * This simple program compiles when you link it against
 * the following shared libraries :
 *
 *	-lhosts_gatherer
 *	-lpcap-nessus
 *	-lnessus
 *
 * Its purpose is to demonstrate how to use the lib hosts_gatherer
 *
 */
extern int optind;
void main(int argc, char * argv[])
{
 struct hg_globals * globals;
 char m[1024];
 int e;
 int i;
 int flags = 0;
 
  struct in_addr ip;
 while((i=getopt(argc, argv, "dpsnD"))!=-1)
  switch(i)
  {
  case 'd' : flags |= HG_DNS_AXFR;break;
  case 'p' : flags |= HG_PING;break;
  case 's' : flags |= HG_SUBNET;break;
  case 'n' : flags |= HG_REVLOOKUP;
  case 'D' : flags |= HG_DISTRIBUTE;
  }
 if(!argv[optind])
 { 
  printf("Usage : test -dps hostname/netmask\n-d : DNS axfr\n-p : ping hosts\n\
-s : whole network\n-D: distribute the load\n");
  exit(0);
 }
 if((flags & HG_PING)&&geteuid()){
 	printf("the ping flag will be ignored -- you are not root\n");
	}

 
 if(hg_test_syntax(argv[optind], flags) < 0 )
 {
  printf("BAD SYNTAX\n");
  exit(1);
 }
 globals = hg_init(argv[optind], flags);
 e  = hg_next_host(globals,&ip, m, sizeof(m));
 while(e >= 0)
 {
  printf("%s (%s)\n", m, inet_ntoa(ip));
  e = hg_next_host(globals,&ip, m, sizeof(m));
 }
 hg_cleanup(globals);
}