Giter VIP home page Giter VIP logo

Comments (8)

yan-kuan avatar yan-kuan commented on August 25, 2024

Just like this one, how can we construct the member bitmap. Now. I only know that I can figure it out in Paser, but can I build the prototype in variable length?

 *     WKS RDATA format:
 *
 *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 *     |                    ADDRESS                    |
 *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 *     |       PROTOCOL        |                       |
 *     +--+--+--+--+--+--+--+--+                       |
 *     |                                               |
 *     /                   <BIT MAP>                   /
 *     /                                               /
 *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 * 
 * where:
 * 
 * ADDRESS         An 32 bit Internet address
 * 
 * PROTOCOL        An 8 bit IP protocol number
 * 
 * <BIT MAP>       A variable length bit map.  The bit map must be a
 *                 multiple of 8 bits long.

from ddns.

yan-kuan avatar yan-kuan commented on August 25, 2024

More one question, rfc1305 has defined the limit of name, so I define the fixed limit for it. But the real system do the same one? So I can't save some space of that?

/**
 * 3.3.11. Name Server (NS) RR
 * 
 * An NS RR marks the beginning of a DNS zone and supplies the domain name of a name server for that zone. It is typically seen in two places - at the top of a zone, just after the SOA; and at the start of a subzone, where an NS (and often a paired A) are all that is required to perform delegation. See RFC 1035 ยง3.3.11 for a more detailed description of the NS RR.
 * 
 *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 *     /                   NSDNAME                     /
 *     /                                               /
 *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 * 
 * where: 
 * 
 * NSDNAME         A <domain-name> which specifies a host which should be
 *                 authoritative
 */
 typedef char NN_t[NAME_LIMIT];

from ddns.

gapry avatar gapry commented on August 25, 2024

For syntax, you can reference the 6.9 Bit-fields, The C programming Language, 2nd.

For the background knowledge, you can watch the video tap 8-2 Domain Name System (DNS), Part 1 and 8-3 Domain Name System (DNS), Part 2 in the following list.
Video Lecture, Computer Networks, University of Washington

The implementation maybe like this:
http://www.binarytides.com/dns-query-code-in-c-with-linux-sockets/

Also, you can find a lot of helpful resources in the CMU Lecture, http://www.cs.cmu.edu/~prs/15-441-F16/syllabus.html

from ddns.

yan-kuan avatar yan-kuan commented on August 25, 2024

@gapry , What a useful suggest !

Thanks a lot. I would take the way on DNS Query Code in C with linux sockets. I have constructed the protocol in include/protocol directory.

I also have an novel idea to deal with variable-length array.

from ddns.

gapry avatar gapry commented on August 25, 2024

@yenwu For the variable-length array, it may be like this

Case 1: 1st dimension fixed, 2nd dimension unfixed

void print(int*(*a)[2],int sz2) 
{
      for (int i=0;i<2;i++) {
          for (int j=0;j<sz2;j++) printf("%d ",(*a)[i][j]);
          printf("\n");
      }
}
int main(void)
{
      int a[2][3]={1,2,3,4,5,6},b[1][3]={1,2,3};
      int c[2][2]={1,2,3,4};
      int *aa[2]={a[0],a[1]},*bb[1]={b[0]};
      int *cc[2]={c[0],c[1]};
      
      print(&aa,3); // ok
      print(&bb,3); // no
      print(&cc,2); // ok
      return 0;
}

Case 2: 1st dimension unfixed, 2nd dimension fixed

void print(int (*a)[3],int sz1)
{
    for (int i=0;i<sz1;i++) {
        for (int j=0;j<3;j++) printf("%d ",a[i][j]);
        printf("\n");
    }
}
int main(void)
{
    int a[2][3]={1,2,3,4,5,6},b[1][3]={1,2,3};
    int c[2][2]={1,2,3,4};
    print(a,2);// ok
    print(b,1); // ok
    print(c,2); // no
    return 0;
}

Case 3: Both dimensions unfixed
Method A: Extra Space

void print(int** a,int sz1,int sz2)
{
    for (int i=0;i<sz1;i++) {
        for (int j=0;j<sz2;j++) printf("%d ",a[i][j]);
        printf("\n");
    }
}

int main(void)
{
    int a[2][3]={1,2,3,4,5,6},b[1][3]={1,2,3};
    int c[2][2]={1,2,3,4};
    int *aa[2]={a[0],a[1]},*bb[1]={b[0]};
    int *cc[2]={c[0],c[1]};
    print(aa,2,3);// ok
    print(bb,1,3);// ok
    print(cc,2,2);// ok
    return 0;
}

Method B: Generic pointer

void print(void* a,int sz1,int sz2)
{
    for (int i=0;i<sz1;i++) {
        for (int j=0;j<sz2;j++) {
            int* aij=(int*)((char*)a+i*sz2*sizeof(int)+j*sizeof(int)); // int* aij=(int*)a+i*sz2+j;
            printf("%d ",*aij);
        }
        printf("\n");
    }
}
int main(void)
{
    int a[2][3]={1,2,3,4,5,6},b[1][3]={1,2,3};
    int c[2][2]={1,2,3,4};
    print(a,2,3); // ok; or, print(&a,2,3);
    print(b,1,3);// ok
    print(c,2,2);// ok
    return 0;
}

from ddns.

gapry avatar gapry commented on August 25, 2024

@yenwu The following figure is the key idea.

c_array

from ddns.

yan-kuan avatar yan-kuan commented on August 25, 2024

@gapry , Such a warmhearted guy!
I have already read it. If the way I used fail, I would take yours.

I would use the gcc extension zero-length array to represent variable array. That's used to locate the address of the head of variable array.

typedef struct _test {
    int     num;
    int**   arr;
    char    data[0];
}test;

test* t = (test *) malloc(sizeof(test) + 10);

t->data[0] = 'h';
t->data[1] = 'e';
 ...

printf("check the data[0] = %c", t->data[0]);

Ref: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

from ddns.

gapry avatar gapry commented on August 25, 2024

@yenwu Thank for your sharing and invitation

from ddns.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.