Exemple #1
0
int main(int argc, char *argv[]) {
  if (argc == 1)
    parse_config("dns_proxy.conf");
  else if (argc == 2) {
    if (!strcmp(argv[1], "-h")) {
      printf("Usage: %s [options]\n", argv[0]);
      printf(" * With no parameters, the configuration file is read from 'dns_proxy.conf'.\n\n");
      printf(" -n          -- No configuration file (socks: 127.0.0.1:9999, listener: 0.0.0.0:53).\n");
      printf(" -h          -- Print this message and exit.\n");
      printf(" config_file -- Read from specified configuration file.\n\n");
      printf(" * The configuration file should contain any of the following options (and ignores lines that begin with '#'):\n");
      printf("   * socks_addr  -- socks listener address\n");
      printf("   * socks_port  -- socks listener port\n");
      printf("   * listen_addr -- address for the dns proxy to listen on\n");
      printf("   * listen_port -- port for the dns proxy to listen on (most cases 53)\n");
      printf("   * resolv_conf -- location of resolv.conf to read from\n");
      printf("   * log_file    -- location to log server IPs to. (only necessary for debugging)\n\n");
      printf(" * Configuration directives should be of the format:\n");
      printf("   option = value\n\n");
      printf(" * Any non-specified options will be set to their defaults:\n");
      printf("   * socks_addr   = 127.0.0.1\n");
      printf("   * socks_port   = 9050\n");
      printf("   * listen_addr  = 0.0.0.0\n");
      printf("   * listen_port  = 53\n");
      printf("   * resolv_conf  = resolv.conf\n");
      printf("   * log_file     = /dev/null\n");
      exit(0);
    }
    else {
      parse_config(argv[1]);
    }
  }

//  if (getuid() != 0) {
//    printf("Error: this program must be run as root! Quitting\n");
//    exit(1);
//  }

  printf("[*] Listening on: %s:%d\n", LISTEN_ADDR, LISTEN_PORT);
  printf("[*] Using SOCKS proxy: %s:%d\n", SOCKS_ADDR, SOCKS_PORT);
  parse_resolv_conf();
  printf("[*] Loaded %d DNS servers from %s.\n\n", NUM_DNS, RESOLVCONF);

  // start the dns proxy
  udp_listener();
  exit(EXIT_SUCCESS);
}
Exemple #2
0
int nepim_udp_listener(const char *ssm_source,
		       const char *hostname,
		       const char *portname, 
		       int mcast_join,
		       const char *join_iface)
{
  struct addrinfo hints;
  struct addrinfo *ai_res;
  struct addrinfo *ai;
  int result;
  int udp_listeners = 0;

  if (!ssm_source)
    return udp_listener(0  /* ssm_source */,
			0  /* ssm_source_addr */,
			-1 /* ssm_source_addrlen */,
			hostname,
			portname,
			mcast_join,
			join_iface);

  memset(&hints, 0, sizeof(hints));

  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = IPPROTO_UDP;
  hints.ai_flags = AI_PASSIVE | AI_CANONNAME;
  hints.ai_family = PF_UNSPEC;
  hints.ai_addrlen = 0;
  hints.ai_addr = 0;
  hints.ai_canonname = 0;

  result = getaddrinfo(ssm_source, 0, &hints, &ai_res);
  if (result) {
    fprintf(stderr, "%s: getaddrinfo(%s): %s\n",
	    __PRETTY_FUNCTION__,
            ssm_source, gai_strerror(result));
    return 0;
  }

  /* Scan ssm_source addresses */

  for (ai = ai_res; ai; ai = ai->ai_next) {

    if (nepim_global.no_inet6 && (ai->ai_family == PF_INET6))
      continue;

    if (nepim_global.no_inet4 && (ai->ai_family == PF_INET))
      continue;

    udp_listeners += udp_listener(ssm_source,
				  ai->ai_addr,
				  ai->ai_addrlen,
				  hostname,
				  portname,
				  mcast_join,
				  join_iface);
  }

  freeaddrinfo(ai_res);

  return udp_listeners;
}