int main (void) { dbug_init(); sock_init(); print_hosts (host_root); return (0); }
/* * Print binary tree ASCII-sorted on `h_name' (in-order) */ static void print_hosts (TreeNode *node) { if (node) { print_hosts (node->left); if (node->info) { int i; _hostent *h = (_hostent*) node->info; printf ("address = %-17.17s name = %s; ", inet_ntoa (*(struct in_addr*)&h->h_address), h->h_name); for (i = 0; h->h_aliases && h->h_aliases[i]; i++) printf ("%s,",h->h_aliases[i]); puts (""); } print_hosts (node->right); } }
int main (void) { const struct hostent *h; const char *host_name = "test-host"; int wait_time; DWORD addr_list [MAX_ADDRESSES+1]; dbug_init(); sock_init(); print_hosts(); wait_time = netdbCacheLife + 1; memset (&addr_list, 0, sizeof(addr_list)); addr_list[0] = htonl (_inet_addr("80.22.33.45")); addr_list[1] = htonl (_inet_addr("222.22.33.46")); addr_list[2] = htonl (_inet_addr("217.22.33.47")); addr_list[3] = htonl (_inet_addr("81.22.33.48")); addr_list[4] = INADDR_NONE; SOCK_DEBUGF (("\nadd_hostent: `%s'", host_name)); add_hostent (NULL, host_name, "some.cname.org", &addr_list[1], addr_list[0], netdbCacheLife); h = gethostbyname (host_name); if (!h) { fprintf (stderr, "gethostbyname() failed!. h_errno = %d\n", h_errno); return (1); } fprintf (stderr, "Waiting for cache-entry to timeout.."); Sleep (wait_time); fprintf (stderr, "gethostbyname() should do a DNS lookup now.\n"); h = gethostbyname (host_name); if (h) fprintf (stderr, "entry didn't timeout!.\n"); #if defined(USE_FORTIFY) Fortify_ListAllMemory(); Fortify_OutputStatistics(); #endif return (0); }
int passive_main(int argc, char *argv[]) { register int c, i; /* Temporary variable */ bpf_u_int32 mask; /* our netmask */ bpf_u_int32 net; /* our IP adx */ uint32_t npolls; /* Number of pcap polls */ char errbuf[PCAP_ERRBUF_SIZE]; /* pcap error buffer */ char *filter = NULL; /* pcap filter */ pcap_t *handle; /* pcap handle */ struct bpf_program program; /* BPF filter program */ npolls = NPOLLS_DEFAULT; port_threshold = PORT_THRESHOLD_DEFAULT; /* This is a trick to have long options only as this is the standard for how netstr works. However, if one wanted to unglue this piece it wouldn't be too difficult */ while (1) { static struct option long_options[] = { {"if", required_argument, 0, 'i'}, {"threshold", required_argument, 0, 'T'}, {"polls", required_argument, 0, 'p'}, {"no-verify", no_argument, 0, 'V'}, {"extra", no_argument, 0, 'X'}, {0, 0, 0, 0} }; int option_index = 0; c = getopt_long(argc, argv, "", long_options, &option_index); if (c == -1) break; switch (c) { case 'i': pcap_dev = optarg; break; case 'T': port_threshold = u_int_check(optarg); break; case 'p': npolls = u_int_check(optarg); break; case 'V': verify_port = 0; break; case 'X': xflag = 1; break; case 'u': printf("%s\n", PASSIVE_USAGE); return EXIT_SUCCESS; break; default: printf("%s\n", PASSIVE_USAGE); return EXIT_FAILURE; break; } } isroot_uid(); /* call utils isroot_uid? */ /* Strip off any none getopt arguments for pcap filter */ if (!filter) filter = copy_argv(&argv[optind]); /* Initialize the interface to listen on */ if ((!pcap_dev) && ((pcap_dev = pcap_lookupdev(errbuf)) == NULL)) { fprintf(stderr, "%s\n", errbuf); return EXIT_FAILURE; } if ((handle = pcap_open_live(pcap_dev, 68, 0, 0, errbuf)) == NULL) { fprintf(stderr, "%s\n", errbuf); return EXIT_FAILURE; } pcap_lookupnet(pcap_dev, &net, &mask, errbuf); /* Get netinfo */ if (filter) { if (pcap_compile(handle, &program, filter, 0, net) == -1) { fprintf(stderr, "Error - `IP: pcap_compile() IP'\n"); return EXIT_FAILURE; } if (pcap_setfilter(handle, &program) == -1) { fprintf(stderr, "Error - `IP: pcap_setfilter()'\n"); return EXIT_FAILURE; } pcap_freecode(&program); } printf("Starting capturing engine on %s...\n", pcap_dev); pcap_loop(handle, npolls, passive_pcap4, NULL); printf("Closing capturing engine...\n"); pcap_close(handle); print_hosts(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { FILE *pfile, *gfile, *hfile, *mfile; int qflag = 0, ch; char *domain = NULL; while ((ch = getopt(argc, argv, "d:g:h:m:p:P:q")) != -1) switch (ch) { case 'd': domain = optarg; break; case 'g': GroupFile = optarg; break; case 'h': HostFile = optarg; break; case 'm': NetidFile = optarg; break; case 'p': PasswdFile = optarg; break; case 'P': MasterPasswdFile = optarg; break; case 'q': qflag = 1; break; default: usage(); break; } if (argc > optind) usage(); if (domain == NULL) yp_get_default_domain(&domain); pfile = fopen(PasswdFile, "r"); if (pfile == NULL) pfile = fopen(MasterPasswdFile, "r"); if (pfile == NULL) err(1, "%s", MasterPasswdFile); gfile = fopen(GroupFile, "r"); if (gfile == NULL) err(1, "%s", GroupFile); hfile = fopen(HostFile, "r"); if (hfile == NULL) err(1, "%s", HostFile); mfile = fopen(NetidFile, "r"); read_passwd(pfile, PasswdFile); read_group(gfile, GroupFile); print_passwd_group(qflag, domain); print_hosts(hfile, HostFile, domain); if (mfile != NULL) print_netid(mfile, NetidFile); return 0; }