Changeset 08a6382 in mainline for uspace/srv/net/dnsres/transport.c


Ignore:
Timestamp:
2012-08-12T20:17:31Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e5e73af
Parents:
f85ed4b
Message:

Fixes to get DNS query acceptable by looking at analyzer output. Fix assertion failure in UDP.

File:
1 edited

Legend:

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

    rf85ed4b r08a6382  
    3535
    3636#include <errno.h>
     37#include <net/in.h>
     38#include <net/inet.h>
     39#include <net/socket.h>
     40#include <stdlib.h>
    3741
    3842#include "dns_msg.h"
     
    4044#include "transport.h"
    4145
     46#include <stdio.h>
    4247int dns_request(dns_message_t *req, dns_message_t **rresp)
    4348{
     
    4651        void *req_data;
    4752        size_t req_size;
     53        struct sockaddr_in addr;
     54        int fd;
     55
     56        addr.sin_family = AF_INET;
     57        addr.sin_port = htons(53);
     58        addr.sin_addr.s_addr = htonl((192 << 24) | (168 << 16) | (0 << 8) | 1);
     59
     60        req_data = NULL;
     61        fd = -1;
    4862
    4963        rc = dns_message_encode(req, &req_data, &req_size);
    5064        if (rc != EOK)
    51                 return rc;
     65                goto error;
     66
     67        fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
     68        if (fd < 0) {
     69                rc = EIO;
     70                goto error;
     71        }
     72
     73        printf("fd=%d req_data=%p, req_size=%zu\n", fd, req_data, req_size);
     74        rc = sendto(fd, req_data, req_size, 0, (struct sockaddr *)&addr,
     75            sizeof(addr));
     76        if (rc != EOK)
     77                goto error;
    5278
    5379        resp = NULL;
    5480        *rresp = resp;
    5581        return EOK;
     82
     83error:
     84        if (req_data != NULL)
     85                free(req_data);
     86        if (fd >= 0)
     87                closesocket(fd);
     88        return rc;
    5689}
    5790
Note: See TracChangeset for help on using the changeset viewer.