Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4059010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:09:09+00:00 2026-05-20T15:09:09+00:00

The code below is suppose to print out the TXT Resource Records i have

  • 0

The code below is suppose to print out the TXT Resource Records i have in my zone file.
When i execute the code only with BLOCK 1 (BLOCK 2 not present) i get the name, Type, Class,TTL and Data Length for each of the 3 TXT RRs i have.
But when i execute the code only with BLOCK 2, i only get the answer for the first TXT RR and then an error message: ns_parserr: Message to long.
Can somebody plese help me with this problem.
Thanks in advance.

    int rrnum;  /* resource record number */
    ns_rr rr;   /* expanded resource record */
    for(rrnum = 0; rrnum < ns_msg_count(handle, ns_s_an); rrnum++)
    {
    //from section ns_s_an(ANSWER) take out answer number rrnum and put it in rr        
    if (ns_parserr(&handle, ns_s_an, rrnum, &rr)) {
        fprintf(stderr, "ns_parserr: %s\n", strerror(errno));
    }
    if (ns_rr_type(rr)==ns_t_txt){  
        //BLOCK 1
                    char *cp;
        cp=(char *)ns_rr_name(rr);
        printf("CP->%s\n",(char *)cp);
        int i1=ns_rr_type(rr);
        printf("Type->%d\n", i1);
        int i2=ns_rr_class(rr);
        printf("Class->%d\n", i2);      
        int i3=ns_rr_ttl(rr);
        printf("TTL->%d\n", i3);
        int i4=ns_rr_rdlen(rr);
        printf("Data Length->%d\n\n", i4);

                    //BLOCK 2
        u_char const *rdata=ns_rr_rdata(rr);
        printf("Data->%s\n",(u_char *)rdata);
        char *rdatatemp;
        rdatatemp=(char *)rdata;
        int len=strlen(rdata);
        printf("%d\n",len);
        rdatatemp[strlen(rdata)-2]='\0';
        printf("Data->%s\n",(u_char *)rdatatemp);   
    }
}

This is the result i get with the two blocks on:
vanco@vanco-laptop:~/Desktop$ gcc d2ip.c /usr/lib/libresolv.a
vanco@vanco-laptop:~/Desktop$ ./a.out http://www.example.com
CP->http://www.example.com
Type->16
Class->1
TTL->10800
Data Length->41

Data->(ver=dgw1 pre=8 id=0 name=www.example.com�

43
Data->(ver=dgw1 pre=8 id=0 name=www.example.com
ns_parserr: Message too long

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:09:10+00:00Added an answer on May 20, 2026 at 3:09 pm

    You’re modifying the memory pointed to by the u_char const * returned by ns_rr_rdata(rr); via circumventing the const using a cast

    u_char const *rdata=ns_rr_rdata(rr);
    ...
    char *rdatatemp;
    rdatatemp=(char *)rdata;
    ...
    rdatatemp[strlen(rdata)-2]='\0';
    

    You need to allocate a new char array and copy from rdata

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a particular scenario below. The code below should print 'say()' function of
The code below reads from a file 'helpFile.txt' and checks for an index represented
I suppose button should has Close title in the code below, but it has
Ok another question in VHDL. Below is my code. Suppose that I want my
I have the code below that is supposed to draw lines from the top
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
Code below is working well as long as I have class ClassSameAssembly in same
Update: I have tried Sheldon's code below but I have struck a couple of
I am having trouble figuring out what the code segment below is doing. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.