static void do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) { int n, sflag, rrnum; ns_opcode opcode; ns_rr rr; /* * Print answer records. */ sflag = (int)(_res.pfcode & pflag); if (_res.pfcode && !sflag) return; opcode = ns_msg_getflag(*handle, ns_f_opcode); rrnum = 0; for (;;) { if (ns_parserr(handle, section, rrnum, &rr)) { if (errno != ENODEV) fprintf(file, ";; ns_parserr: %s\n", strerror(errno)); else if (rrnum > 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1)) putc('\n', file); return; } if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1)) fprintf(file, ";; %s SECTION:\n", p_section(section, opcode)); if (section == ns_s_qd) fprintf(file, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr), p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else { char *buf; buf = (char*)malloc(2024); if (buf) { n = ns_sprintrr(handle, &rr, NULL, NULL, buf, sizeof buf); if (n < 0) { fprintf(file, ";; ns_sprintrr: %s\n", strerror(errno)); free(buf); return; } fputs(buf, file); fputc('\n', file); free(buf); } } rrnum++; } }
static void do_section(const res_state statp, ns_msg *handle, ns_sect section, int pflag, FILE *file) { int n, sflag, rrnum; int buflen = 2048; char *buf; ns_opcode opcode; ns_rr rr; /* * Print answer records. */ sflag = (statp->pfcode & pflag); if (statp->pfcode && !sflag) return; buf = malloc((size_t)buflen); if (buf == NULL) { fprintf(file, ";; memory allocation failure\n"); return; } opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode); rrnum = 0; for (;;) { if (ns_parserr(handle, section, rrnum, &rr)) { if (errno != ENODEV) fprintf(file, ";; ns_parserr: %s\n", strerror(errno)); else if (rrnum > 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1)) putc('\n', file); goto cleanup; } if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1)) fprintf(file, ";; %s SECTION:\n", p_section(section, opcode)); if (section == ns_s_qd) fprintf(file, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr), p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { u_int32_t ttl = ns_rr_ttl(rr); fprintf(file, "; EDNS: version: %u, udp=%u, flags=%04x\n", (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); } else {
void val_log_val_rrset_pfx(const val_context_t * ctx, int level, const char *pfx, struct val_rrset_rec *val_rrset_rec) { char buf1[2049], buf2[2049]; if (!val_rrset_rec) return; val_log(ctx, level, "%srrs->val_rrset_name=%s rrs->val_rrset_type=%s " "rrs->val_rrset_class=%s rrs->val_rrset_ttl=%d " "rrs->val_rrset_section=%s\nrrs->val_rrset_data=%s\n" "rrs->val_rrset_sig=%s", pfx ? pfx : "", val_rrset_rec->val_rrset_name, p_type(val_rrset_rec->val_rrset_type), p_class(val_rrset_rec->val_rrset_class), val_rrset_rec->val_rrset_ttl, p_section(val_rrset_rec->val_rrset_section - 1, !ns_o_update), get_rr_string(val_rrset_rec->val_rrset_data, buf1, 2048), get_rr_string(val_rrset_rec->val_rrset_sig, buf2, 2048)); }
void TestSendRecv() throw (Exception) { if (PetscTools::GetNumProcs() == 2) { MPI_Status status; ObjectCommunicator<ClassOfSimpleVariables> communicator; // Create a simple class to send std::vector<double> doubles(3); doubles[0] = 1.1; doubles[1] = 1.2; doubles[2] = 1.3; std::vector<bool> bools(2); bools[0] = true; bools[1] = true; boost::shared_ptr<ClassOfSimpleVariables> p_send_class(new ClassOfSimpleVariables(42,"hello",doubles,bools)); boost::shared_ptr<ClassOfSimpleVariables> p_class(new ClassOfSimpleVariables); // Arguments are object, destination, tag p_class = communicator.SendRecvObject(p_send_class, 1-PetscTools::GetMyRank(), 123, 1-PetscTools::GetMyRank(), 123, status); // Check that the values are correct TS_ASSERT_EQUALS(p_class->GetNumber(),42); TS_ASSERT_EQUALS(p_class->GetString(),"hello"); TS_ASSERT_EQUALS(p_class->GetVectorOfDoubles().size(),3u); TS_ASSERT_EQUALS(p_class->GetVectorOfBools().size(),2u); TS_ASSERT_DELTA(p_class->GetVectorOfDoubles()[0],1.1,1e-12); TS_ASSERT_DELTA(p_class->GetVectorOfDoubles()[1],1.2,1e-12); TS_ASSERT_DELTA(p_class->GetVectorOfDoubles()[2],1.3,1e-12); TS_ASSERT(p_class->GetVectorOfBools()[0]); TS_ASSERT(p_class->GetVectorOfBools()[1]); } }
void val_log_authentication_chain(const val_context_t * ctx, int level, const char * name_p, int class_h, int type_h, struct val_result_chain *results) { struct val_result_chain *next_result; int real_type_h; int real_class_h; if (results == NULL) { return; } for (next_result = results; next_result; next_result = next_result->val_rc_next) { struct val_authentication_chain *next_as; int i; /* Display the correct owner name, class,type for the record */ if (next_result->val_rc_rrset) { real_type_h = next_result->val_rc_rrset->val_rrset_type; real_class_h = next_result->val_rc_rrset->val_rrset_class; } else { real_type_h = type_h; real_class_h = class_h; } if (val_isvalidated(next_result->val_rc_status)) { val_log(ctx, level, "Validation result for {%s, %s(%d), %s(%d)}: %s:%d (Validated)", name_p, p_class(real_class_h), real_class_h, p_type(real_type_h), real_type_h, p_val_status(next_result->val_rc_status), next_result->val_rc_status); } else if (val_istrusted(next_result->val_rc_status)) { val_log(ctx, level, "Validation result for {%s, %s(%d), %s(%d)}: %s:%d (Trusted but not Validated)", name_p, p_class(real_class_h), real_class_h, p_type(real_type_h), real_type_h, p_val_status(next_result->val_rc_status), next_result->val_rc_status); } else { val_log(ctx, level, "Validation result for {%s, %s(%d), %s(%d)}: %s:%d (Untrusted)", name_p, p_class(real_class_h), real_class_h, p_type(real_type_h), real_type_h, p_val_status(next_result->val_rc_status), next_result->val_rc_status); } for (next_as = next_result->val_rc_answer; next_as; next_as = next_as->val_ac_trust) { if (next_as->val_ac_rrset == NULL) { val_log(ctx, level, " Assertion status = %s:%d", p_ac_status(next_as->val_ac_status), next_as->val_ac_status); } else { const char *t_name; t_name = next_as->val_ac_rrset->val_rrset_name; if (t_name == NULL) t_name = (const char *) "NULL_DATA"; val_log_assertion_pfx(ctx, level, " ", t_name, next_as); // val_log_val_rrset_pfx(ctx, level, " ", // next_as->val_ac_rrset); } } for (i = 0; i < next_result->val_rc_proof_count; i++) { val_log(ctx, level, " Proof of non-existence [%d of %d]", i+1, next_result->val_rc_proof_count); for (next_as = next_result->val_rc_proofs[i]; next_as; next_as = next_as->val_ac_trust) { if (next_as->val_ac_rrset == NULL) { val_log(ctx, level, " Assertion status = %s:%d", p_ac_status(next_as->val_ac_status), next_as->val_ac_status); } else { const char *t_name; t_name = next_as->val_ac_rrset->val_rrset_name; if (t_name == NULL) t_name = (const char *) "NULL_DATA"; val_log_assertion_pfx(ctx, level, " ", t_name, next_as); } } } } }
void val_log_assertion_pfx(const val_context_t * ctx, int level, const char *prefix, const char * name_pr, struct val_authentication_chain *next_as) { char name_buf[INET6_ADDRSTRLEN + 1]; const char *serv_pr; int tag = 0; int class_h; int type_h; struct val_rr_rec *data; struct sockaddr *serv; val_astatus_t status; struct val_rr_rec *curkey; #undef VAL_LOG_SIG #ifdef VAL_LOG_SIG struct val_rr_rec *sig; struct val_rr_rec *cursig; #endif if (next_as == NULL) return; class_h = next_as->val_ac_rrset->val_rrset_class; type_h = next_as->val_ac_rrset->val_rrset_type; data = next_as->val_ac_rrset->val_rrset_data; #ifdef VAL_LOG_SIG sig = next_as->val_ac_rrset->val_rrset_sig; #endif serv = next_as->val_ac_rrset->val_rrset_server; status = next_as->val_ac_status; if (NULL == prefix) prefix = ""; if (serv) serv_pr = ((serv_pr = val_get_ns_string(serv, name_buf, sizeof(name_buf))) == NULL) ? "VAL_CACHE" : serv_pr; else serv_pr = "NULL"; if (type_h == ns_t_dnskey) { for (curkey = data; curkey; curkey = curkey->rr_next) { if ((curkey->rr_status == VAL_AC_VERIFIED_LINK) || (curkey->rr_status == VAL_AC_TRUST_POINT) || (curkey->rr_status == VAL_AC_UNKNOWN_ALGORITHM_LINK)) { /* * Extract the key tag */ val_dnskey_rdata_t dnskey; if (VAL_NO_ERROR != val_parse_dnskey_rdata(curkey->rr_rdata, curkey->rr_rdata_length, &dnskey)) { val_log(ctx, LOG_INFO, "val_log_assertion_pfx(): Cannot parse DNSKEY data"); } else { tag = dnskey.key_tag; if (dnskey.public_key) FREE(dnskey.public_key); } break; } } } if (tag != 0) { val_log(ctx, level, "%sname=%s class=%s type=%s[tag=%d] from-server=%s " "status=%s:%d", prefix, name_pr, p_class(class_h), p_type(type_h), tag, serv_pr, p_ac_status(status), status); } else { val_log(ctx, level, "%sname=%s class=%s type=%s from-server=%s status=%s:%d", prefix, name_pr, p_class(class_h), p_type(type_h), serv_pr, p_ac_status(status), status); } #ifdef VAL_LOG_SIG for (cursig = sig; cursig; cursig = cursig->rr_next) { char incpTime[1028]; char exprTime[1028]; struct timeval tv_sig; val_rrsig_rdata_t rrsig; val_parse_rrsig_rdata(cursig->rr_rdata, cursig->rr_rdata_length, &rrsig); memset(&tv_sig, 0, sizeof(tv_sig)); tv_sig.tv_sec = rrsig.sig_incp; GET_TIME_BUF((const time_t *)(&tv_sig.tv_sec), incpTime); memset(&tv_sig, 0, sizeof(tv_sig)); tv_sig.tv_sec = rrsig.sig_expr; GET_TIME_BUF((const time_t *)(&tv_sig.tv_sec), exprTime); val_log(ctx, level, "%s ->tag=%d status=%s sig-incep=%s sig-expr=%s", prefix, rrsig.key_tag, p_ac_status(cursig->rr_status), incpTime, exprTime); } #endif #ifdef VAL_LOG_SIG struct val_rr_rec *rr; struct val_rr_rec *sig = next_as->val_ac_rrset->val_rrset_sig; for (rr = data; rr; rr = rr->rr_next) { val_log(ctx, level, " data_status=%s:%d", p_ac_status(rr->rr_status), rr->rr_status); } for (rr = sig; rr; rr = rr->rr_next) { val_log(ctx, level, " sig_status=%s:%d", p_ac_status(rr->rr_status), rr->rr_status); } #endif }
void txtout_output(const char* descr, iaddr from, iaddr to, uint8_t proto, unsigned flags, unsigned sport, unsigned dport, my_bpftimeval ts, const u_char* pkt_copy, unsigned olen, const u_char* payload, unsigned payloadlen) { /* * Short output, only print QTYPE and QNAME for IN records */ if (opt_s) { if (flags & DNSCAP_OUTPUT_ISDNS) { ns_msg msg; int qdcount, err = 0; ns_rr rr; if (ns_initparse(payload, payloadlen, &msg) < 0) { if (tcpstate_getcurr && tcpstate_reset) tcpstate_reset(tcpstate_getcurr(), ""); return; } qdcount = ns_msg_count(msg, ns_s_qd); if (qdcount > 0 && 0 == (err = ns_parserr(&msg, ns_s_qd, 0, &rr)) && ns_rr_class(rr) == 1) { fprintf(out, "%s %s\n", p_type(ns_rr_type(rr)), ns_rr_name(rr)); } if (err < 0) { if (tcpstate_getcurr && tcpstate_reset) tcpstate_reset(tcpstate_getcurr(), ""); } } return; } /* * IP Stuff */ fprintf(out, "%10ld.%06ld", (long)ts.tv_sec, (long)ts.tv_usec); fprintf(out, " %s %u", ia_str(from), sport); fprintf(out, " %s %u", ia_str(to), dport); fprintf(out, " %hhu", proto); if (flags & DNSCAP_OUTPUT_ISDNS) { ns_msg msg; int qdcount, err = 0; ns_rr rr; if (ns_initparse(payload, payloadlen, &msg) < 0) { if (tcpstate_getcurr && tcpstate_reset) tcpstate_reset(tcpstate_getcurr(), ""); fprintf(out, "\n"); return; } /* * DNS Header */ fprintf(out, " %u", ns_msg_id(msg)); fprintf(out, " %u", ns_msg_getflag(msg, ns_f_opcode)); fprintf(out, " %u", ns_msg_getflag(msg, ns_f_rcode)); fprintf(out, " |"); if (ns_msg_getflag(msg, ns_f_qr)) fprintf(out, "QR|"); if (ns_msg_getflag(msg, ns_f_aa)) fprintf(out, "AA|"); if (ns_msg_getflag(msg, ns_f_tc)) fprintf(out, "TC|"); if (ns_msg_getflag(msg, ns_f_rd)) fprintf(out, "RD|"); if (ns_msg_getflag(msg, ns_f_ra)) fprintf(out, "RA|"); if (ns_msg_getflag(msg, ns_f_ad)) fprintf(out, "AD|"); if (ns_msg_getflag(msg, ns_f_cd)) fprintf(out, "CD|"); qdcount = ns_msg_count(msg, ns_s_qd); if (qdcount > 0 && 0 == (err = ns_parserr(&msg, ns_s_qd, 0, &rr))) { fprintf(out, " %s %s %s", p_class(ns_rr_class(rr)), p_type(ns_rr_type(rr)), ns_rr_name(rr)); } if (err < 0) { if (tcpstate_getcurr && tcpstate_reset) tcpstate_reset(tcpstate_getcurr(), ""); } } /* * Done */ fprintf(out, "\n"); }
static void do_section(const res_state statp, ns_msg *handle, ns_sect section, int pflag, FILE *file) { int n, sflag, rrnum; static int buflen = 2048; char *buf; ns_opcode opcode; ns_rr rr; /* * Print answer records. */ sflag = (statp->pfcode & pflag); if (statp->pfcode && !sflag) return; buf = malloc(buflen); if (buf == NULL) { fprintf(file, ";; memory allocation failure\n"); return; } opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode); rrnum = 0; for (;;) { if (ns_parserr(handle, section, rrnum, &rr)) { if (errno != ENODEV) fprintf(file, ";; ns_parserr: %s\n", strerror(errno)); else if (rrnum > 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1)) putc('\n', file); goto cleanup; } if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1)) fprintf(file, ";; %s SECTION:\n", p_section(section, opcode)); if (section == ns_s_qd) fprintf(file, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr), p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { u_int16_t optcode, optlen, rdatalen = ns_rr_rdlen(rr); u_int32_t ttl = ns_rr_ttl(rr); fprintf(file, "; EDNS: version: %u, udp=%u, flags=%04x\n", (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); while (rdatalen >= 4) { const u_char *cp = ns_rr_rdata(rr); int i; GETSHORT(optcode, cp); GETSHORT(optlen, cp); if (optcode == NS_OPT_NSID) { fputs("; NSID: ", file); if (optlen == 0) { fputs("; NSID\n", file); } else { fputs("; NSID: ", file); for (i = 0; i < optlen; i++) fprintf(file, "%02x ", cp[i]); fputs(" (",file); for (i = 0; i < optlen; i++) fprintf(file, "%c", isprint(cp[i])? cp[i] : '.'); fputs(")\n", file); } } else { if (optlen == 0) { fprintf(file, "; OPT=%u\n", optcode); } else { fprintf(file, "; OPT=%u: ", optcode); for (i = 0; i < optlen; i++) fprintf(file, "%02x ", cp[i]); fputs(" (",file); for (i = 0; i < optlen; i++) fprintf(file, "%c", isprint(cp[i]) ? cp[i] : '.'); fputs(")\n", file); } } rdatalen -= 4 + optlen; } } else {
/* * Print the contents of a query. * This is intended to be primarily a debugging routine. */ void fp_query(char *msg, FILE *file) { register char *cp; register HEADER *hp; register int n; /* * Print header fields. */ hp = (HEADER *)msg; cp = msg + sizeof(HEADER); fprintf(file,"HEADER:\n"); fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]); fprintf(file,", id = %d", ntohs(hp->id)); fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]); fprintf(file,"\theader flags: "); if (hp->qr) fprintf(file," qr"); if (hp->aa) fprintf(file," aa"); if (hp->tc) fprintf(file," tc"); if (hp->rd) fprintf(file," rd"); if (hp->ra) fprintf(file," ra"); if (hp->pr) fprintf(file," pr"); fprintf(file,"\n\tqdcount = %d", ntohs(hp->qdcount)); fprintf(file,", ancount = %d", ntohs(hp->ancount)); fprintf(file,", nscount = %d", ntohs(hp->nscount)); fprintf(file,", arcount = %d\n\n", ntohs(hp->arcount)); /* * Print question records. */ if (n = ntohs(hp->qdcount)) { fprintf(file,"QUESTIONS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_cdname(cp, msg, file); if (cp == NULL) return; fprintf(file,", type = %s", p_type(_getshort(cp))); cp += sizeof(u_short); fprintf(file,", class = %s\n\n", p_class(_getshort(cp))); cp += sizeof(u_short); } } /* * Print authoritative answer records */ if (n = ntohs(hp->ancount)) { fprintf(file,"ANSWERS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_rr(cp, msg, file); if (cp == NULL) return; } } /* * print name server records */ if (n = ntohs(hp->nscount)) { fprintf(file,"NAME SERVERS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_rr(cp, msg, file); if (cp == NULL) return; } } /* * print additional records */ if (n = ntohs(hp->arcount)) { fprintf(file,"ADDITIONAL RECORDS:\n"); while (--n >= 0) { fprintf(file,"\t"); cp = p_rr(cp, msg, file); if (cp == NULL) return; } } }
static void do_section (int pfcode, ns_msg *handle, ns_sect section, int pflag, FILE *file) { int n, sflag, rrnum; static int buflen = 2048; char *buf; ns_opcode opcode; ns_rr rr; /* * Print answer records. */ sflag = (pfcode & pflag); if (pfcode && !sflag) return; buf = malloc(buflen); if (buf == NULL) { fprintf(file, ";; memory allocation failure\n"); return; } opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode); rrnum = 0; for (;;) { if (ns_parserr(handle, section, rrnum, &rr)) { if (errno != ENODEV) fprintf(file, ";; ns_parserr: %s\n", strerror(errno)); else if (rrnum > 0 && sflag != 0 && (pfcode & RES_PRF_HEAD1)) putc('\n', file); goto cleanup; } if (rrnum == 0 && sflag != 0 && (pfcode & RES_PRF_HEAD1)) fprintf(file, ";; %s SECTION:\n", p_section(section, opcode)); if (section == ns_s_qd) fprintf(file, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr), p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else { n = ns_sprintrr(handle, &rr, NULL, NULL, buf, buflen); if (n < 0) { if (errno == ENOSPC) { free(buf); buf = NULL; if (buflen < 131072) buf = malloc(buflen += 1024); if (buf == NULL) { fprintf(file, ";; memory allocation failure\n"); return; } continue; } fprintf(file, ";; ns_sprintrr: %s\n", strerror(errno)); goto cleanup; } fputs(buf, file); fputc('\n', file); } rrnum++; } cleanup: free(buf); }