VirtualBox

Changeset 33957 in vbox


Ignore:
Timestamp:
Nov 11, 2010 9:13:09 AM (14 years ago)
Author:
vboxsync
Message:

NAT/libalias: cosmetic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/libalias/alias_dns.c

    r33953 r33957  
    5252AssertCompileSize(union dnsmsg_header, 12);
    5353
    54 struct dnsmsg_answer
    55 {
    56     uint16_t name;
     54struct dns_meta_data
     55{
    5756    uint16_t type;
    5857    uint16_t class;
     58};
     59
     60struct dnsmsg_answer
     61{
     62    uint16_t name;
     63    struct dns_meta_data meta;
    5964    uint16_t ttl[2];
    6065    uint16_t rdata_len;
     
    7479        return -1;
    7580
    76     fprintf(stderr, "NAT:%s: ah(dport: %hd, sport: %hd) oaddr:%R[IP4] aaddr:%R[IP4]\n",
     81    Log(("NAT:%s: ah(dport: %hd, sport: %hd) oaddr:%R[IP4] aaddr:%R[IP4]\n",
    7782        __FUNCTION__, ntohs(*ah->dport), ntohs(*ah->sport),
    78         &ah->oaddr, &ah->aaddr);
     83        &ah->oaddr, &ah->aaddr));
    7984
    8085    if (   (ntohs(*ah->dport) == DNS_CONTROL_PORT_NUMBER
     
    8691}
    8792
    88 static void doanswer(struct libalias *la, union dnsmsg_header *hdr, uint16_t qtype, uint16_t qclass, char *qname, struct ip *pip, struct hostent *h)
     93static void doanswer(struct libalias *la, union dnsmsg_header *hdr, struct dns_meta_data *pReqMeta, char *qname, struct ip *pip, struct hostent *h)
    8994{
    9095    int i;
     
    106111        uint16_t packet_len = 0;
    107112        uint16_t addr_off = (uint16_t)~0;
     113        struct dns_meta_data *meta;
    108114
    109115#if 0
     
    115121                   + sizeof(union dnsmsg_header)
    116122                   + strlen(qname)
    117                    + 2 * sizeof(uint16_t); /* ip + udp + header + query */
     123                   + sizeof(struct dns_meta_data); /* ip + udp + header + query */
    118124        query = (char *)&hdr[1];
    119125
    120126        strcpy(query, qname);
    121127        query += strlen(qname) + 1;
    122 
    123         *(uint16_t *)query = qtype;
    124         ((uint16_t *)query)[1] = qclass;
    125         answers = (char *)&((uint16_t *)query)[2];
     128        /* class & type informations lay right after symbolic inforamtion. */
     129        meta = (struct dns_meta_data *)query;
     130        meta->type = pReqMeta->type;
     131        meta->class = pReqMeta->class;
     132
     133        /* answers zone lays after query in response packet */
     134        answers = (char *)&meta[1];
    126135
    127136        off = (char *)&hdr[1] - (char *)hdr;
     
    134143            struct dnsmsg_answer *ans = (struct dnsmsg_answer *)answers;
    135144            ans->name = htons(off);
    136             ans->type = htons(5); /* CNAME */
    137             ans->class = htons(1);
     145            ans->meta.type = htons(5); /* CNAME */
     146            ans->meta.class = htons(1);
    138147            *(uint32_t *)ans->ttl = htonl(3600); /* 1h */
    139148            c = (addr_off == (uint16_t)~0 ? h->h_name : *cstr);
     
    157166
    158167            ans->name = htons(off);
    159             ans->type = htons(1);
    160             ans->class = htons(1);
     168            ans->meta.type = htons(1);
     169            ans->meta.class = htons(1);
    161170            *(uint32_t *)ans->ttl = htonl(3600); /* 1h */
    162171            ans->rdata_len = htons(4); /* IPv4 */
     
    187196    char cname[255];
    188197    int cname_len = 0;
     198    struct dns_meta_data *meta;
    189199
    190200    struct udphdr *udp = NULL;
     
    201211    if ((ntohs(hdr->X.qdcount) != 1))
    202212    {
    203         LogRel(("NAT:alias_dns: multiple quieries isn't supported\n"));
     213        static bool fMultiWarn;
     214        if (!fMultiWarn)
     215        {
     216            LogRel(("NAT:alias_dns: multiple quieries isn't supported\n"));
     217            fMultiWarn = true;
     218        }
    204219        return 1;
    205220    }
     
    207222    for (i = 0; i < ntohs(hdr->X.qdcount); ++i)
    208223    {
    209         qw_qtype = (uint16_t *)(qw_qname + strlen(qw_qname) + 1);
    210         qw_qclass = &qw_qtype[1];
    211         fprintf(stderr, "qname:%s qtype:%hd qclass:%hd\n",
    212             qw_qname, ntohs(*qw_qtype), ntohs(*qw_qclass));
     224        meta = (struct dns_meta_data *)(qw_qname + strlen(qw_qname) + 1);
     225        Log(("qname:%s qtype:%hd qclass:%hd\n",
     226            qw_qname, ntohs(meta->type), ntohs(meta->class)));
    213227
    214228        QStr2CStr(qw_qname, cname, sizeof(cname));
     
    227241        h = gethostbyname(cname);
    228242        fprintf(stderr, "cname:%s\n", cname);
    229         doanswer(la, hdr, *qw_qtype, *qw_qclass, qw_qname, pip, h);
     243        doanswer(la, hdr, meta, qw_qname, pip, h);
    230244    }
    231245
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette