本文整理汇总了C++中dn_expand函数的典型用法代码示例。如果您正苦于以下问题:C++ dn_expand函数的具体用法?C++ dn_expand怎么用?C++ dn_expand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dn_expand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dns_ptr_parser
/** parses a PTR record into a ptr_rdata structure */
struct ptr_rdata* dns_ptr_parser( unsigned char* msg, unsigned char* end,
unsigned char* rdata)
{
struct ptr_rdata* pname;
int len;
char name[MAX_DNS_NAME];
pname=0;
if (dn_expand(msg, end, rdata, name, MAX_DNS_NAME-1)==-1)
goto error;
len=strlen(name);
if (len>255)
goto error;
/* alloc sizeof struct + space for the null terminated name */
pname=local_malloc(sizeof(struct ptr_rdata)-1+len+1);
if(pname==0){
LM_ERR("out of memory\n");
goto error;
}
pname->ptrdname_len=len;
memcpy(pname->ptrdname, name, pname->ptrdname_len);
pname->ptrdname[pname->ptrdname_len]=0;
return pname;
error:
if (pname) local_free(pname);
return 0;
}
示例2: parse_answer
static int parse_answer(querybuf_t *ans, int len, struct in_addr *addr)
{
char buf[MAXPACKET];
HEADER *ahp;
u_char *cp, *eoa;
int type, n;
ahp = &ans->hdr;
eoa = ans->buf + len;
cp = ans->buf + sizeof(HEADER);
while (ahp->qdcount > 0) {
ahp->qdcount--;
cp += dn_skipname(cp, eoa) + QFIXEDSZ;
}
while (ahp->ancount > 0 && cp < eoa) {
ahp->ancount--;
if ((n = dn_expand(ans->buf, eoa, cp, buf, sizeof(buf))) < 0)
break;
cp += n;
type = _getshort(cp);
cp += 8;
n = _getshort(cp);
cp += 2;
if (type == T_CNAME) {
cp += n;
continue;
}
memcpy(addr, cp, n);
return 0;
}
h_errno = TRY_AGAIN;
return -1;
}
示例3: dn_expand_wrapper
// ccured wrappers
int dn_expand_wrapper(const u_char *msg, const u_char *eomorig,
const u_char *comp_dn, char *exp_dn, int length) {
__write_at_least(exp_dn, length);
__verify_nul(comp_dn);
return ( dn_expand(__ptrof(msg), __ptrof(eomorig), __ptrof(comp_dn),
__ptrof(exp_dn), length) );
}
示例4: ns_parserr
int
ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
int b;
int tmp;
/* Make section right. */
tmp = section;
if (tmp < 0 || section >= ns_s_max)
RETERR(ENODEV);
if (section != handle->_sect)
setsection(handle, section);
/* Make rrnum right. */
if (rrnum == -1)
rrnum = handle->_rrnum;
if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
RETERR(ENODEV);
if (rrnum < handle->_rrnum)
setsection(handle, section);
if (rrnum > handle->_rrnum) {
b = ns_skiprr(handle->_msg_ptr, handle->_eom, section,
rrnum - handle->_rrnum);
if (b < 0)
return (-1);
handle->_msg_ptr += b;
handle->_rrnum = rrnum;
}
/* Do the parse. */
b = dn_expand(handle->_msg, handle->_eom,
handle->_msg_ptr, rr->name, NS_MAXDNAME);
if (b < 0)
return (-1);
handle->_msg_ptr += b;
if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom)
RETERR(EMSGSIZE);
NS_GET16(rr->type, handle->_msg_ptr);
NS_GET16(rr->rr_class, handle->_msg_ptr);
if (section == ns_s_qd) {
rr->ttl = 0;
rr->rdlength = 0;
rr->rdata = NULL;
} else {
if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom)
RETERR(EMSGSIZE);
NS_GET32(rr->ttl, handle->_msg_ptr);
NS_GET16(rr->rdlength, handle->_msg_ptr);
if (handle->_msg_ptr + rr->rdlength > handle->_eom)
RETERR(EMSGSIZE);
rr->rdata = handle->_msg_ptr;
handle->_msg_ptr += rr->rdlength;
}
if (++handle->_rrnum > handle->_counts[(int)section])
setsection(handle, (ns_sect)((int)section + 1));
/* All done. */
return (0);
}
示例5: GetDN
static bool GetDN(const unsigned char * reply, const unsigned char * replyEnd, unsigned char * & cp, char * buff)
{
int len = dn_expand(reply, replyEnd, cp, buff, MAXDNAME);
if (len < 0)
return false;
cp += len;
return true;
}
示例6: rrextract
static int
rrextract(u_char *msg, int msglen, u_char *rrp, u_char *dname, int namelen)
{
/* cp is used to read data from rrp[] (the Resource Record)
* cp1 is used to write data into data[]
* However, we sometimes abuse cp1 and use it for reading too. :-/
*/
u_char *eom, *cp, *cp1, *rdatap;
u_int class, type, dlen;
int n;
long origTTL;
u_char data[MAXDATA*2+SPACE_FOR_VARS];
data [(MAXDATA*2)-1+SPACE_FOR_VARS] = EOS;
cp = rrp;
eom = msg + msglen;
GETSHORT(dlen, cp);
BOUNDS_CHECK(cp, dlen);
/* Begin case T_SIG: */
/* Just read one variable --- the original reads several. */
BOUNDS_CHECK(cp, SPACE_FOR_VARS);
cp1 = cp;
GETLONG(origTTL, cp1);
/* Skip checks on times which are present in the original. */
/* Copy over initial fields, which we read above. */
cp1 = (u_char *)data;
BOUNDS_CHECK(cp, SPACE_FOR_VARS);
memcpy(cp1, cp, SPACE_FOR_VARS);
cp += SPACE_FOR_VARS;
cp1 += SPACE_FOR_VARS;
/* Expand the domain name, set cp1 past the end of the uncompressed
* domain name.
*/
n = dn_expand(msg, eom, cp, (char *)cp1, (sizeof data));
if (n < 0) {
return (-1);
}
cp += n;
cp1 += strlen((char*)cp1)+1;
/* Figure out the length of the "signature" to copy over and copy it. */
n = dlen - (SPACE_FOR_VARS + n);
if (n > (sizeof data) - (cp1 - (u_char *)data)) {
return (-1); /* out of room! */
}
/* OK */
r_memcpy(cp1, cp, n);
return 0;
}
示例7:
static char *get_name(unsigned char *msg, unsigned char *msg_end, unsigned char **msg_ptr)
{
int res;
static char buffer[MAX_STRING_LEN];
if (-1 == (res = dn_expand(msg, msg_end, *msg_ptr, buffer, sizeof(buffer))))
return NULL;
*msg_ptr += res;
return buffer;
}
示例8: dn_expand
bool
dnsparse::qparse (const u_char **cpp, question *qp)
{
const u_char *cp = *cpp;
int n = dn_expand (buf, eom, cp, qp->q_name, sizeof (qp->q_name));
if (n < 0 || n >= MAXDNAME || cp + n + 4 > eom)
return false;
cp += n;
GETSHORT (qp->q_type, cp);
GETSHORT (qp->q_class, cp);
*cpp = cp;
return true;
}
示例9: p_cdnname
const u_char *
p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
char name[MAXDNAME];
int n;
if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
return (NULL);
if (name[0] == '\0')
putc('.', file);
else
fputs(name, file);
return (cp + n);
}
示例10: krb5int_dns_nextans
/*
* krb5int_dns_nextans() - get next answer record
*
* Sets pp to NULL if no more records.
*/
int
krb5int_dns_nextans(struct krb5int_dns_state *ds,
const unsigned char **pp, int *lenp)
{
int len;
unsigned char *p;
unsigned short ntype, nclass, rdlen;
#if !HAVE_DN_SKIPNAME
char host[MAXDNAME];
#endif
*pp = NULL;
*lenp = 0;
p = ds->ptr;
while (ds->nanswers--) {
#if HAVE_DN_SKIPNAME
len = dn_skipname(p, (unsigned char *)ds->ansp + ds->anslen);
#else
len = dn_expand(ds->ansp, (unsigned char *)ds->ansp + ds->anslen,
p, host, sizeof(host));
#endif
if (len < 0 || !INCR_OK(ds->ansp, ds->anslen, p, len))
return -1;
p += len;
SAFE_GETUINT16(ds->ansp, ds->anslen, p, 2, ntype, out);
/* Also skip 4 bytes of TTL */
SAFE_GETUINT16(ds->ansp, ds->anslen, p, 6, nclass, out);
SAFE_GETUINT16(ds->ansp, ds->anslen, p, 2, rdlen, out);
if (!INCR_OK(ds->ansp, ds->anslen, p, rdlen))
return -1;
/* Solaris Kerberos - resync */
#if 0
if (rdlen > INT_MAX)
return -1;
#endif
if (nclass == ds->nclass && ntype == ds->ntype) {
*pp = p;
*lenp = rdlen;
ds->ptr = p + rdlen;
return 0;
}
p += rdlen;
}
return 0;
out:
return -1;
}
示例11: krb5int_dns_expand
/*
* krb5int_dns_expand - wrapper for dn_expand()
*/
int
krb5int_dns_expand(struct krb5int_dns_state *ds, const unsigned char *p,
char *buf, int len)
{
#if HAVE_NS_NAME_UNCOMPRESS
return ns_name_uncompress(ds->ansp,
(unsigned char *)ds->ansp + ds->anslen,
p, buf, (size_t)len);
#else
return dn_expand(ds->ansp,
(unsigned char *)ds->ansp + ds->anslen,
p, buf, len);
#endif
}
示例12: p_cdname
char *
p_cdname(char *cp, char *msg, FILE *file)
{
char name[MAXDNAME];
int n;
if ((n = dn_expand(msg, msg + 512, cp, name, sizeof(name))) < 0)
return (NULL);
if (name[0] == '\0') {
name[0] = '.';
name[1] = '\0';
}
fputs(name, file);
return (cp + n);
}
示例13: p_fqnname
const u_char *
p_fqnname (const u_char *cp, const u_char *msg, int msglen, char *name,
int namelen)
{
int n, newlen;
if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
return (NULL);
newlen = strlen(name);
if (newlen == 0 || name[newlen - 1] != '.') {
if (newlen + 1 >= namelen) /* Lack space for final dot */
return (NULL);
else
strcpy(name + newlen, ".");
}
return (cp + n);
}
示例14: fqdn_to_env
static void fqdn_to_env(const char *name, const uint8_t *fqdn, size_t len)
{
size_t buf_len = strlen(name);
size_t buf_size = len + buf_len + 2;
const uint8_t *fqdn_end = fqdn + len;
char *buf = realloc(NULL, len + buf_len + 2);
memcpy(buf, name, buf_len);
buf[buf_len++] = '=';
int l = 1;
while (l > 0 && fqdn < fqdn_end) {
l = dn_expand(fqdn, fqdn_end, fqdn, &buf[buf_len], buf_size - buf_len);
fqdn += l;
buf_len += strlen(&buf[buf_len]);
buf[buf_len++] = ' ';
}
buf[buf_len - 1] = '\0';
putenv(buf);
}
示例15: getMailserver
char* getMailserver(const char* domain) {
int len;
char answer[NS_PACKETSZ];
char *mailserver = malloc(NS_PACKETSZ);
ns_msg msg;
ns_rr rr;
if(res_init() == -1) {
return NULL;
}
len = res_query(domain,C_ANY,T_MX,answer,NS_PACKETSZ);
if(len == -1) {
return NULL;
}
/* return first MX record */
ns_initparse(answer,len,&msg);
ns_parserr(&msg,ns_s_an,0,&rr);
dn_expand(ns_msg_base(msg),ns_msg_base(msg)+ns_msg_size(msg),ns_rr_rdata(rr)+NS_INT16SZ,mailserver,NS_PACKETSZ);
return mailserver;
}