static logline *readline(FILE *inf, adns_state adns, int opts) { static char buf[MAXLINE]; char *str; logline *line; if (fgets(buf, MAXLINE, inf)) { str= malloc(sizeof(*line) + strlen(buf) + 1); if (!str) aargh("malloc"); line= (logline*)str; line->next= NULL; line->start= str+sizeof(logline); line->is_v6 = 0; *line->fullip = 0; strcpy(line->start, buf); str= ipaddr2domain(line->start, &line->addr, &line->rest, line->fullip, &line->is_v6, opts); if (opts & OPT_DEBUG) msg("submitting %.*s -> %s", (int)(line->rest-line->addr), guard_null(line->addr), str); /* Note: ADNS does not yet support "ptr" for IPv6. */ if (adns_submit(adns, str, line->is_v6? adns_r_ptr_raw : adns_r_ptr, adns_qf_quoteok_cname|adns_qf_cname_loose, NULL, &line->query)) aargh("adns_submit"); return line; } if (!feof(inf)) aargh("fgets"); return NULL; }
static logline *readline(FILE *inf, adns_state adns, int opts) { static char buf[MAXLINE]; char *str; logline *line; if (fgets(buf, MAXLINE, inf)) { str= malloc(sizeof(*line) + strlen(buf) + 1); if (!str) aargh("malloc"); line= (logline*)str; line->next= NULL; line->start= str+sizeof(logline); strcpy(line->start, buf); str= ipaddr2domain(line->start, &line->addr, &line->rest); if (opts & OPT_DEBUG) msg("submitting %.*s -> %s", line->rest-line->addr, guard_null(line->addr), str); if (adns_submit(adns, str, adns_r_ptr, adns_qf_quoteok_cname|adns_qf_cname_loose, NULL, &line->query)) aargh("adns_submit"); return line; } if (!feof(inf)) aargh("fgets"); return NULL; }
static void proclog(FILE *inf, FILE *outf, int maxpending, int opts) { int eof, err, len; adns_state adns; adns_answer *answer; logline *head, *tail, *line; adns_initflags initflags; initflags= (opts & OPT_DEBUG) ? adns_if_debug : 0; if (config_text) { errno= adns_init_strcfg(&adns, initflags, stderr, config_text); } else { errno= adns_init(&adns, initflags, 0); } if (errno) aargh("adns_init"); head= tail= readline(inf, adns, opts); len= 1; eof= 0; while (head) { while (head) { if (opts & OPT_DEBUG) msg("%d in queue; checking %.*s", len, (int)(head->rest-head->addr), guard_null(head->addr)); if (eof || len >= maxpending) { if (opts & OPT_POLL) err= adns_wait_poll(adns, &head->query, &answer, NULL); else err= adns_wait(adns, &head->query, &answer, NULL); } else { err= adns_check(adns, &head->query, &answer, NULL); } if (err == EAGAIN) break; if (err) { fprintf(stderr, "%s: adns_wait/check: %s", progname, strerror(err)); exit(1); } printline(outf, head->start, head->addr, head->rest, answer->status == adns_s_ok ? *answer->rrs.str : NULL, head->fullip, head->is_v6, opts); line= head; head= head->next; free(line); free(answer); len--; } if (!eof) { line= readline(inf, adns, opts); if (line) { if (!head) head= line; else tail->next= line; tail= line; len++; } else { eof= 1; } } } adns_finish(adns); }
static void proclog(FILE *inf, FILE *outf, int maxpending, int opts) { int eof, err, len; adns_state adns; adns_answer *answer; logline *head, *tail, *line; adns_initflags initflags; initflags= (opts & OPT_DEBUG) ? adns_if_debug : 0; if (config_text) { errno= adns_init_strcfg(&adns, initflags, stderr, config_text); } else { errno= adns_init(&adns, initflags, 0); } if (errno) aargh("adns_init"); head= tail= readline(inf, adns, opts); len= 1; eof= 0; while (head) { while (head) { if (head->query) { if (opts & OPT_DEBUG) msg("%d in queue; checking %.*s", len, (int)(head->rest-head->name), guard_null(head->name)); if (eof || len >= maxpending) { if (opts & OPT_POLL) err= adns_wait_poll(adns, &head->query, &answer, NULL); else err= adns_wait(adns, &head->query, &answer, NULL); } else { err= adns_check(adns, &head->query, &answer, NULL); } if (err == EAGAIN) break; if (err) { fprintf(stderr, "%s: adns_wait/check: %s", progname, strerror(err)); exit(1); } if (answer->status == adns_s_ok) { const char *addr; int ok = 0; fprintf(outf, "%.*s", (int)(head->rest-head->start), head->start); while(answer->nrrs--) { addr= inet_ntoa(answer->rrs.inaddr[answer->nrrs]); ok |= !strncmp(addr, head->addr, strlen(addr)); fprintf(outf, " [%s]", addr); } fprintf(outf, "%s%s", ok ? " OK" : "", head->rest); } else { if (opts & OPT_DEBUG) msg("query failed"); fputs(head->start, outf); } free(answer); len--; } else { if (opts & OPT_DEBUG) msg("%d in queue; no query on this line", len); fputs(head->start, outf); } line= head; head= head->next; free(line); } if (!eof) { line= readline(inf, adns, opts); if (line) { if (!head) head= line; else tail->next= line; tail= line; if (line->query) len++; } else { eof= 1; } } } adns_finish(adns); }