int sendqueries() { char buf[512]; struct sockaddr_in sadr; int rlen, rc, qid; int prand = getpid(); struct nsnode *tns = nshead; in_addr_t ipno; int sent = 0; while(tns) { if (tns->resprec == 0) { qid = tns->queryno; rlen = dnsencode(who, buf, qid, authq?0:1, qtype, 1); bzero(&sadr, sizeof(sadr)); sadr.sin_family = AF_INET; sadr.sin_port = htons(53); ipno = inet_addr(tns->nsip); if (ipno == INADDR_NONE) { upchuck("Bad IP number", tns->nsip); } sadr.sin_addr.s_addr = ipno; rc = sendto(dnsfd, buf, rlen, 0, (struct sockaddr *)&sadr, sizeof(sadr)); if (rc == -1) barf("sendto"); if (debug) fprintf(stderr, "send packet %d to %s\n", qid, tns->nsip); sent++; } tns = tns->next; } return sent; }
/* * Make a temporary directory to play in and chdir() to it, returning * pathname of previous working directory. */ const char * make_playpen(char *pen, off_t sz) { char humbuf1[6], humbuf2[6]; char cwd[FILENAME_MAX]; if (!find_play_pen(pen, sz)) return NULL; if (!mkdtemp(pen)) { cleanup(0); errx(2, "%s: can't mktemp '%s'", __func__, pen); } if (Verbose) { if (sz) { humanize_number(humbuf1, sizeof humbuf1, sz, "", HN_AUTOSCALE, HN_NOSPACE); humanize_number(humbuf2, sizeof humbuf2, min_free(pen), "", HN_AUTOSCALE, HN_NOSPACE); fprintf(stderr, "Requested space: %s bytes, free space: %s bytes in %s\n", humbuf1, humbuf2, pen); } } if (min_free(pen) < sz) { rmdir(pen); cleanup(0); errx(2, "%s: not enough free space to create '%s'.\n" "Please set your PKG_TMPDIR environment variable to a location\n" "with more space and\ntry the command again", __func__, pen); } if (!getcwd(cwd, FILENAME_MAX)) { upchuck("getcwd"); return NULL; } if (chdir(pen) == FAIL) { cleanup(0); errx(2, "%s: can't chdir to '%s'", __func__, pen); } strcpy(PenLocation, pen); return pushPen(cwd); }
void newns(char *name, int crit) { struct nsnode *tns; char *scp, *p; tns = (struct nsnode *)malloc(sizeof(struct nsnode)); if (!tns) puke("malloc failure"); scp = strdup(name); p = index(scp, ':'); if (!p) upchuck("-n arg without a colon", scp); *p++ = '\0'; tns->nsname = scp; tns->nsip = p; tns->next = nshead; tns->queryno = prand++ & 0xffff; tns->npos = nbit; tns->critns = crit ? CRITBIT : WARNBIT; tns->resprec = strcmp(scp, "_expect") ? 0 : 1; nbit <<= 1; nshead = tns; }