LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Error message of dn_expand (https://www.linuxquestions.org/questions/programming-9/error-message-of-dn_expand-799683/)

btp10 04-02-2010 07:07 PM

Error message of dn_expand
 
Hi,
Can anyone tell me what "Message too long" error returned by the function dn_expand means?

The function call I used is as follows:

dn_expand(poutput, poutput + output_space_used, *out_rr, output_qname, 255);

I assumed that the error was due to the difference between the 1st argument and 2nd argument, However, changing the difference to the accepted dns message size (512 bytes) or even to no difference at all did nothing to remove the error.

Further, I am trying to check the output after having first compressed a domain name using dn_comp into *out_rr. This function call is in order to check whether the compression is happening correctly.

Any ideas on what I might be doing wrong ?

Sergei Steshenko 04-03-2010 12:14 PM

Quote:

Originally Posted by btp10 (Post 3922327)
Hi,
Can anyone tell me what "Message too long" error returned by the function dn_expand means?

The function call I used is as follows:

dn_expand(poutput, poutput + output_space_used, *out_rr, output_qname, 255);

I assumed that the error was due to the difference between the 1st argument and 2nd argument, However, changing the difference to the accepted dns message size (512 bytes) or even to no difference at all did nothing to remove the error.

Further, I am trying to check the output after having first compressed a domain name using dn_comp into *out_rr. This function call is in order to check whether the compression is happening correctly.

Any ideas on what I might be doing wrong ?

And why haven't you looked yet into the function source ?

btp10 04-04-2010 07:57 AM

Quote:

Originally Posted by Sergei Steshenko (Post 3923029)
And why haven't you looked yet into the function source ?

I have looked into the function source and I could not figure out anything from that as there are too many flags that I do not understand. Moreover, the source was pretty difficult to find so that when I did find the code I wasn't sure whether it was for the actual function that I am using or the source code for some other version of the function.

PS: I don't know whether you realize it or not but your response is ---- 1. Rude, 2. Not helpful at all. Thanks a lot anyways.

Sergei Steshenko 04-04-2010 09:23 AM

Quote:

Originally Posted by btp10 (Post 3923724)
I have looked into the function source and I could not figure out anything from that as there are too many flags that I do not understand. Moreover, the source was pretty difficult to find so that when I did find the code I wasn't sure whether it was for the actual function that I am using or the source code for some other version of the function.

PS: I don't know whether you realize it or not but your response is ---- 1. Rude, 2. Not helpful at all. Thanks a lot anyways.

So, now copy the source into your program, changing the function name, and adding 'printf' statements, so you'll be able to trace which statements are executed and why you are getting the error message.

The above is trivial.

The source apparently is in 'glibc' - at least, this is where I find it.


The sources:

Code:

int
dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
          char *dst, int dstsiz)
{
        int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);

        if (n > 0 && dst[0] == '.')
                dst[0] = '\0';
        return (n);
}


Code:

int
ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
                  char *dst, size_t dstsiz)
{
        u_char tmp[NS_MAXCDNAME];
        int n;

        if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
                return (-1);
        if (ns_name_ntop(tmp, dst, dstsiz) == -1)
                return (-1);
        return (n);
}

Code:

int
ns_name_ntop(const u_char *src, char *dst, size_t dstsiz)
{
        const u_char *cp;
        char *dn, *eom;
        u_char c;
        u_int n;
        int l;

        cp = src;
        dn = dst;
        eom = dst + dstsiz;

        while ((n = *cp++) != 0) {
                if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
                        /* Some kind of compression pointer. */
                        __set_errno (EMSGSIZE);
                        return (-1);
                }
                if (dn != dst) {
                        if (dn >= eom) {
                                __set_errno (EMSGSIZE);
                                return (-1);
                        }
                        *dn++ = '.';
                }
                if ((l = labellen(cp - 1)) < 0) {
                        __set_errno (EMSGSIZE);
                        return(-1);
                }
                if (dn + l >= eom) {
                        __set_errno (EMSGSIZE);
                        return (-1);
                }
                if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) {
                        int m;

                        if (n != DNS_LABELTYPE_BITSTRING) {
                                /* XXX: labellen should reject this case */
                                __set_errno (EINVAL);
                                return(-1);
                        }
                        if ((m = decode_bitstring(&cp, dn, eom)) < 0)
                        {
                                __set_errno (EMSGSIZE);
                                return(-1);
                        }
                        dn += m;
                        continue;
                }
                for ((void)NULL; l > 0; l--) {
                        c = *cp++;
                        if (special(c)) {
                                if (dn + 1 >= eom) {
                                        __set_errno (EMSGSIZE);
                                        return (-1);
                                }
                                *dn++ = '\\';
                                *dn++ = (char)c;
                        } else if (!printable(c)) {
                                if (dn + 3 >= eom) {
                                        __set_errno (EMSGSIZE);
                                        return (-1);
                                }
                                *dn++ = '\\';
                                *dn++ = digits[c / 100];
                                *dn++ = digits[(c % 100) / 10];
                                *dn++ = digits[c % 10];
                        } else {
                                if (dn >= eom) {
                                        __set_errno (EMSGSIZE);
                                        return (-1);
                                }
                                *dn++ = (char)c;
                        }
                }
        }
        if (dn == dst) {
                if (dn >= eom) {
                        __set_errno (EMSGSIZE);
                        return (-1);
                }
                *dn++ = '.';
        }
        if (dn >= eom) {
                __set_errno (EMSGSIZE);
                return (-1);
        }
        *dn++ = '\0';
        return (dn - dst);
}


Code:

int
ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
              u_char *dst, size_t dstsiz)
{
        const u_char *srcp, *dstlim;
        u_char *dstp;
        int n, len, checked, l;

        len = -1;
        checked = 0;
        dstp = dst;
        srcp = src;
        dstlim = dst + dstsiz;
        if (srcp < msg || srcp >= eom) {
                __set_errno (EMSGSIZE);
                return (-1);
        }
        /* Fetch next label in domain name. */
        while ((n = *srcp++) != 0) {
                /* Check for indirection. */
                switch (n & NS_CMPRSFLGS) {
                case 0:
                case NS_TYPE_ELT:
                        /* Limit checks. */
                        if ((l = labellen(srcp - 1)) < 0) {
                                __set_errno (EMSGSIZE);
                                return(-1);
                        }
                        if (dstp + l + 1 >= dstlim || srcp + l >= eom) {
                                __set_errno (EMSGSIZE);
                                return (-1);
                        }
                        checked += l + 1;
                        *dstp++ = n;
                        memcpy(dstp, srcp, l);
                        dstp += l;
                        srcp += l;
                        break;

                case NS_CMPRSFLGS:
                        if (srcp >= eom) {
                                __set_errno (EMSGSIZE);
                                return (-1);
                        }
                        if (len < 0)
                                len = srcp - src + 1;
                        srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
                        if (srcp < msg || srcp >= eom) {  /*%< Out of range. */
                                __set_errno (EMSGSIZE);
                                return (-1);
                        }
                        checked += 2;
                        /*
                        * Check for loops in the compressed name;
                        * if we've looked at the whole message,
                        * there must be a loop.
                        */
                        if (checked >= eom - msg) {
                                __set_errno (EMSGSIZE);
                                return (-1);
                        }
                        break;

                default:
                        __set_errno (EMSGSIZE);
                        return (-1);                        /*%< flag error */
                }
        }
        *dstp = '\0';
        if (len < 0)
                len = srcp - src;
        return (len);
}

The code snippets above have a lot of

Code:

__set_errno (EMSGSIZE)
and putting a unique print statement just before each of them is trivial.

About my response - do you realize you are plain lazy and want others to do your job ?

btp10 04-04-2010 05:05 PM

Quote:

About my response - do you realize you are plain lazy and want others to do your job ?
1. By not asking for help again after replying to you, I think it was very clear that the thread was "CLOSED" at least for "you".

2. I have completed my work - ALL ON MY OWN. :) :) :)

3. When I posted the thread, all I wanted to know was whether anyone had any idea about dn_expand(). I wasn't expecting anyone to do my work for me. If you have such trouble replying, just don't bother to.


All times are GMT -5. The time now is 03:34 AM.