コード例 #1
0
ファイル: printer.c プロジェクト: mit-athena/larvnetd
static void printer_poll(void *arg)
{
  struct printer_poll_args *pargs = (struct printer_poll_args *) arg;
  struct serverstate *state = pargs->state;
  struct printer *printer = pargs->printer;
  char *hesname;

  /* Null out the timer, since it may have just gone off. */
  printer->timer = NULL;
  hesname = hesiod_to_bind(state->hescontext, printer->name, "pcap");
  if (hesname == NULL)
    {
      syslog(LOG_ERR, "printer_poll: can't convert printer name %s to "
	     "hesiod name: %m", printer->name);
      printer->timer = timer_set_rel(60, printer_poll, pargs);
      return;
    }

  syslog(LOG_DEBUG, "printer_poll: printer %s starting query for %s",
	 printer->name, hesname);
  ares_query(state->channel, hesname, C_IN, T_TXT, printer_hes_callback,
	     pargs);
  hesiod_free_string(state->hescontext, hesname);
}
コード例 #2
0
int 
main(int argc, char **argv)
{
	char  **list, **p, *bindname, *name, *type;
	int     lflag = 0, errflg = 0, bflag = 0, c;
	void   *context;

	while ((c = getopt(argc, argv, "lb")) != -1) {
		switch (c) {
		case 'l':
			lflag = 1;
			break;
		case 'b':
			bflag = 1;
			break;
		default:
			errflg++;
			break;
		}
	}
	if (argc - optind != 2 || errflg) {
		fprintf(stderr, "usage: hesinfo [-bl] name type\n");
		fprintf(stderr, "\t-l selects long format\n");
		fprintf(stderr, "\t-b also does hes_to_bind conversion\n");
		exit(2);
	}
	name = argv[optind];
	type = argv[optind + 1];

	if (hesiod_init(&context) < 0) {
		if (errno == ENOEXEC)
			warnx(
			    "hesiod_init: Invalid Hesiod configuration file.");
		else
			warn("hesiod_init");
	}
	/* Display bind name if requested. */
	if (bflag) {
		if (lflag)
			printf("hes_to_bind(%s, %s) expands to\n", name, type);
		bindname = hesiod_to_bind(context, name, type);
		if (!bindname) {
			if (lflag)
				printf("nothing\n");
			if (errno == ENOENT)
				warnx("hesiod_to_bind: Unknown rhs-extension.");
			else
				warn("hesiod_to_bind");
			exit(1);
		}
		printf("%s\n", bindname);
		free(bindname);
		if (lflag)
			printf("which ");
	}
	if (lflag)
		printf("resolves to\n");

	/* Do the hesiod resolve and check for errors. */
	list = hesiod_resolve(context, name, type);
	if (!list) {
		if (lflag)
			printf("nothing\n");
		if (errno == ENOENT)
			warnx("hesiod_resolve: Hesiod name not found.");
		else
			warn("hesiod_resolve");
		exit(1);
	}
	/* Display the results. */
	for (p = list; *p; p++)
		printf("%s\n", *p);

	hesiod_free_list(context, list);
	hesiod_end(context);
	exit(0);
}