Exemple #1
0
/* Copy an RDATA, using compression pointers where RFC1035 permits.
 */
static int
rdcpy(ns_newmsg *handle, ns_type type, const u_char *rdata, size_t rdlen) {
    ns_msg *msg = &handle->msg;
    u_char *p = (u_char *) (unsigned long) msg->_msg_ptr;
    u_char *t = p + NS_INT16SZ;
    u_char *s = t;
    int n;

    switch (type) {
    case ns_t_soa:
        /* MNAME. */
        n = ns_name_pack(rdata, t, msg->_eom - t,
                         handle->dnptrs, handle->lastdnptr);
        if (n < 0)
            return (-1);
        t += n;
        if (ns_name_skip(&rdata, msg->_eom) < 0)
            return (-1);

        /* ANAME. */
        n = ns_name_pack(rdata, t, msg->_eom - t,
                         handle->dnptrs, handle->lastdnptr);
        if (n < 0)
            return (-1);
        t += n;
        if (ns_name_skip(&rdata, msg->_eom) < 0)
            return (-1);

        /* Serial, Refresh, Retry, Expiry, and Minimum. */
        if ((msg->_eom - t) < (NS_INT32SZ * 5)) {
            errno = EMSGSIZE;
            return (-1);
        }
        memcpy(t, rdata, NS_INT32SZ * 5);
        t += (NS_INT32SZ * 5);
        break;
    case ns_t_ptr:
    case ns_t_cname:
    case ns_t_ns:
        /* PTRDNAME, CNAME, or NSDNAME. */
        n = ns_name_pack(rdata, t, msg->_eom - t,
                         handle->dnptrs, handle->lastdnptr);
        if (n < 0)
            return (-1);
        t += n;
        break;
    default:
        memcpy(t, rdata, rdlen);
        t += rdlen;
    }
    NS_PUT16(t - s, p);
    msg->_msg_ptr = t;
    return (0);
}
Exemple #2
0
int dn_skipname(unsigned char *ptr, unsigned char *eom) {
    unsigned char *saveptr = ptr;

    if (ns_name_skip(&ptr, eom) == -1)
         return (-1);
    return (ptr - saveptr);
}
Exemple #3
0
/*
* Skip over a compressed domain name. Return the size or -1.
*/
int dn_skipname(const u_char *ptr, const u_char *eom) {
   const u_char *saveptr = ptr;

   if (ns_name_skip(&ptr, eom) == -1)
      return (-1);
   return (ptr - saveptr);
}
Exemple #4
0
int main() {
  uint8_t A[10];
  uint8_t *eom = &A[10];
  ns_name_skip(A,eom);
}