/*++ /* NAME /* dns_rr 3 /* SUMMARY /* resource record memory and list management /* SYNOPSIS /* #include <dns.h> /* /* DNS_RR *dns_rr_create(qname, rname, type, class, ttl, preference, /* weight, port, data, data_len) /* const char *qname; /* const char *rname; /* unsigned short type; /* unsigned short class; /* unsigned int ttl; /* unsigned preference; /* unsigned weight; /* unsigned port; /* const char *data; /* size_t data_len; /* /* void dns_rr_free(list) /* DNS_RR *list; /* /* DNS_RR *dns_rr_copy(record) /* DNS_RR *record; /* /* DNS_RR *dns_rr_append(list, record) /* DNS_RR *list; /* DNS_RR *record; /* /* DNS_RR *dns_rr_sort(list, compar) /* DNS_RR *list /* int (*compar)(DNS_RR *, DNS_RR *); /* /* int dns_rr_compare_pref_ipv6(DNS_RR *a, DNS_RR *b) /* DNS_RR *list /* DNS_RR *list /* /* int dns_rr_compare_pref_ipv4(DNS_RR *a, DNS_RR *b) /* DNS_RR *list /* DNS_RR *list /* /* int dns_rr_compare_pref_any(DNS_RR *a, DNS_RR *b) /* DNS_RR *list /* DNS_RR *list /* /* DNS_RR *dns_rr_shuffle(list) /* DNS_RR *list; /* /* DNS_RR *dns_rr_remove(list, record) /* DNS_RR *list; /* DNS_RR *record; /* /* DNS_RR *dns_rr_detach(list, record) /* DNS_RR *list; /* DNS_RR *record; /* /* DNS_RR *dns_srv_rr_sort(list) /* DNS_RR *list; /* /* int var_dns_rr_list_limit; /* AUXILIARY FUNCTIONS /* DNS_RR *dns_rr_create_nopref(qname, rname, type, class, ttl, /* data, data_len) /* const char *qname; /* const char *rname; /* unsigned short type; /* unsigned short class; /* unsigned int ttl; /* const char *data; /* size_t data_len; /* /* DNS_RR *dns_rr_create_noport(qname, rname, type, class, ttl, /* preference, data, data_len) /* const char *qname; /* const char *rname; /* unsigned short type; /* unsigned short class; /* unsigned int ttl; /* unsigned preference; /* const char *data; /* size_t data_len; /* DESCRIPTION /* The routines in this module maintain memory for DNS resource record /* information, and maintain lists of DNS resource records. /* /* dns_rr_create() creates and initializes one resource record. /* The \fIqname\fR field specifies the query name. /* The \fIrname\fR field specifies the reply name. /* \fIpreference\fR is used for MX and SRV records; \fIweight\fR /* and \fIport\fR are used for SRV records; \fIdata\fR is a null /* pointer or specifies optional resource-specific data; /* \fIdata_len\fR is the amount of resource-specific data. /* /* dns_rr_create_nopref() and dns_rr_create_noport() are convenience /* wrappers around dns_rr_create() that take fewer arguments. /* /* dns_rr_free() releases the resource used by of zero or more /* resource records. /* /* dns_rr_copy() makes a copy of a resource record. /* /* dns_rr_append() appends an input resource record list to /* an output list. Null arguments are explicitly allowed. /* When the result would be longer than var_dns_rr_list_limit /* (default: 100), dns_rr_append() logs a warning, flags the /* output list as truncated, and discards the excess elements. /* Once an output list is flagged as truncated (test with /* DNS_RR_IS_TRUNCATED()), the caller is expected to stop /* trying to append records to that list. Note: the 'truncated' /* flag is transitive, i.e. when appending a input list that /* was flagged as truncated to an output list, the output list /* will also be flagged as truncated. /* /* dns_rr_sort() sorts a list of resource records into ascending /* order according to a user-specified criterion. The result is the /* sorted list. /* /* dns_rr_compare_pref_XXX() are dns_rr_sort() helpers to sort /* records by their MX preference and by their address family. /* /* dns_rr_shuffle() randomly permutes a list of resource records. /* /* dns_rr_remove() disconnects the specified record from the /* specified list and destroys it. /* The updated list is the result value. /* The record MUST be a list member. /* /* dns_rr_detach() disconnects the specified record from the /* specified list. The updated list is the result value. /* The record MUST be a list member. /* /* dns_srv_rr_sort() sorts a list of SRV records according to /* their priority and weight as described in RFC 2782. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA /* /* SRV Support by /* Tomas Korbar /* Red Hat, Inc.
/*--*/
/* weight_order - sort equal-priority records by weight */
staticvoid weight_order(DNS_RR **array, int count)
{ int unordered_weights; int i;
/* *Computethesumofrecordweights.Ifweightsarenotsuppliedthen *thisfunctionwouldbeanoop.Infactthiswouldbeanoopwhenall *weightshavethesamevalue,whetherthatweightiszeroornot.There *isnoneedtogivespecialtreatmenttozeroweights.
*/ for (unordered_weights = 0, i = 0; i < count; i++)
unordered_weights += array[i]->weight; if (unordered_weights == 0) return;
/* *TherecordorderingcodebelowdiffersfromRFC2782whentheinput *containsamixofzeroandnon-zeroweights:thecodebelowdoesnot *givespecialtreatmenttozeroweights.Instead,ittreatsazero *weightjustlikeanyothersmallweight.Fewerspecialcasesmakefor *codethatissimplerandmorerobust.
*/ for (i = 0; i < count - 1; i++) { int running_sum; int threshold; int k;
DNS_RR *temp;
DNS_RR *dns_srv_rr_sort(DNS_RR *list)
{ int (*saved_user) (DNS_RR *, DNS_RR *);
DNS_RR **rr_array;
DNS_RR *rr; int len; int i; int r; int cur_pref; int left_bound; /* inclusive */ int right_bound; /* non-inclusive */
/* *Avoidmymalloc()panic,orrr_array[0]fence-posterror.
*/ if (list == 0) return (list);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.