Changeset f85ed4b in mainline


Ignore:
Timestamp:
2012-08-12T17:51:26Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
08a6382
Parents:
adae30d
Message:

Fixes: initialize off, increment lsize.

Location:
uspace/srv/net/dnsres
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsres/dns_msg.c

    radae30d rf85ed4b  
    4545#define NAME  "dnsres"
    4646
     47#include <stdio.h>
    4748static int dns_name_encode(char *name, uint8_t *buf, size_t buf_size,
    4849    size_t *act_size)
     
    5556        pi = 0;
    5657        di = 1;
    57 
     58        off = 0;
     59
     60        printf("dns_name_encode(name='%s', buf=%p, buf_size=%zu, act_size=%p\n",
     61            name, buf, buf_size, act_size);
    5862        lsize = 0;
    5963        while (true) {
     64                printf("off=%zu\n", off);
    6065                c = str_decode(name, &off, STR_NO_LIMIT);
     66                printf("c=%d\n", (int)c);
    6167                if (c > 127) {
    6268                        /* Non-ASCII character */
     69                        printf("non-ascii character\n");
    6370                        return EINVAL;
    6471                }
     
    6673                if (c == '.' || c == '\0') {
    6774                        /* Empty string, starting with period or two consecutive periods. */
    68                         if (lsize == 0)
     75                        if (lsize == 0) {
     76                                printf("empty token\n");
    6977                                return EINVAL;
     78                        }
    7079
    7180                        if (lsize > DNS_LABEL_MAX_SIZE) {
    7281                                /* Label too long */
     82                                printf("label too long\n");
    7383                                return EINVAL;
    7484                        }
     
    8393                        ++di;
    8494                } else {
     95                        ++lsize;
    8596                        if (buf != NULL && di < buf_size)
    8697                                buf[di++] = c;
     
    116127
    117128        *act_size = name_size + sizeof(uint16_t) + sizeof(uint16_t);
     129        if (buf == NULL)
     130                return EOK;
     131
    118132        di = name_size;
    119133
  • uspace/srv/net/dnsres/dns_type.h

    radae30d rf85ed4b  
    6969/** Unencoded DNS message question section */
    7070typedef struct {
    71         link_t *msg;
     71        link_t msg;
    7272        /** Domain name in text format (dot notation) */
    7373        char *qname;
  • uspace/srv/net/dnsres/dnsres.c

    radae30d rf85ed4b  
    3939#include "dns_msg.h"
    4040#include "dns_std.h"
     41#include "query.h"
    4142
    4243#define NAME  "dnsres"
     
    4445int main(int argc, char *argv[])
    4546{
     47        dns_host_info_t hinfo;
     48        int rc;
     49
    4650        printf("%s: DNS Resolution Service\n", NAME);
     51        rc = dns_name2host("helenos.org", &hinfo);
     52        printf("dns_name2host() -> rc = %d\n", rc);
     53
    4754        return 0;
    4855}
  • uspace/srv/net/dnsres/query.c

    radae30d rf85ed4b  
    3939#include "dns_type.h"
    4040#include "query.h"
     41#include "transport.h"
    4142
    4243static uint16_t msg_id;
    4344
    44 int dns_name2host(char *name, dns_host_info_t *info)
     45int dns_name2host(const char *name, dns_host_info_t *info)
    4546{
    4647        dns_message_t msg;
     48        dns_message_t *amsg;
    4749        dns_question_t question;
     50        int rc;
    4851
    49         question.qname = name;
     52        question.qname = (char *)name;
    5053        question.qtype = DTYPE_A;
    5154        question.qclass = DC_IN;
    5255
    5356        list_initialize(&msg.question);
    54         list_append(question.msg, &msg.question);
     57        list_append(&question.msg, &msg.question);
    5558
    5659        msg.id = msg_id++;
     
    6265        msg.ra = false;
    6366
     67        rc = dns_request(&msg, &amsg);
     68        if (rc != EOK)
     69                return rc;
     70
    6471        return EOK;
    6572}
  • uspace/srv/net/dnsres/query.h

    radae30d rf85ed4b  
    3939#include "dns_type.h"
    4040
    41 extern int dns_name2host(char *, dns_host_info_t *);
     41extern int dns_name2host(const char *, dns_host_info_t *);
    4242
    4343#endif
Note: See TracChangeset for help on using the changeset viewer.