Changeset f3386d7 in mainline for uspace/srv/net/dnsrsrv/transport.c


Ignore:
Timestamp:
2013-07-15T20:44:54Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f8d3df3
Parents:
273c976 (diff), a940f1d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

mainline changes

File:
1 edited

Legend:

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

    r273c976 rf3386d7  
    5252
    5353/** Request timeout (microseconds) */
    54 #define REQ_TIMEOUT (5*1000*1000)
     54#define REQ_TIMEOUT (5 * 1000 * 1000)
    5555
    5656/** Maximum number of retries */
    5757#define REQ_RETRY_MAX 3
     58
     59inet_addr_t dns_server_addr;
    5860
    5961typedef struct {
     
    7274static fid_t recv_fid;
    7375static int transport_fd = -1;
    74 inet_addr_t dns_server_addr;
    7576
    7677/** Outstanding requests */
     
    182183int dns_request(dns_message_t *req, dns_message_t **rresp)
    183184{
    184         int rc;
     185        trans_req_t *treq = NULL;
     186       
    185187        void *req_data;
    186188        size_t req_size;
     189        int rc = dns_message_encode(req, &req_data, &req_size);
     190        if (rc != EOK)
     191                goto error;
     192       
    187193        struct sockaddr_in addr;
    188         trans_req_t *treq;
    189         int ntry;
    190 
    191         req_data = NULL;
    192         treq = NULL;
    193 
    194         addr.sin_family = AF_INET;
    195         addr.sin_port = htons(DNS_SERVER_PORT);
    196         addr.sin_addr.s_addr = host2uint32_t_be(dns_server_addr.ipv4);
    197 
    198         rc = dns_message_encode(req, &req_data, &req_size);
    199         if (rc != EOK)
    200                 goto error;
    201 
    202         ntry = 0;
    203 
     194        struct sockaddr_in6 addr6;
     195        uint16_t af =
     196            inet_addr_sockaddr_in(&dns_server_addr, &addr, &addr6);
     197       
     198        struct sockaddr *address;
     199        socklen_t addrlen;
     200       
     201        switch (af) {
     202        case AF_INET:
     203                addr.sin_port = htons(DNS_SERVER_PORT);
     204                address = (struct sockaddr *) &addr;
     205                addrlen = sizeof(addr);
     206                break;
     207        case AF_INET6:
     208                addr6.sin6_port = htons(DNS_SERVER_PORT);
     209                address = (struct sockaddr *) &addr6;
     210                addrlen = sizeof(addr6);
     211                break;
     212        default:
     213                rc = EAFNOSUPPORT;
     214                goto error;
     215        }
     216       
     217        size_t ntry = 0;
     218       
    204219        while (ntry < REQ_RETRY_MAX) {
    205220                rc = sendto(transport_fd, req_data, req_size, 0,
    206                     (struct sockaddr *)&addr, sizeof(addr));
     221                    (struct sockaddr *) address, addrlen);
    207222                if (rc != EOK)
    208223                        goto error;
    209 
     224               
    210225                treq = treq_create(req);
    211226                if (treq == NULL) {
     
    213228                        goto error;
    214229                }
    215 
    216 
     230               
    217231                fibril_mutex_lock(&treq->done_lock);
    218232                while (treq->done != true) {
     
    224238                        }
    225239                }
    226 
     240               
    227241                fibril_mutex_unlock(&treq->done_lock);
    228 
     242               
    229243                if (rc != ETIMEOUT)
    230244                        break;
    231245        }
    232 
     246       
    233247        if (ntry >= REQ_RETRY_MAX) {
    234248                rc = EIO;
    235249                goto error;
    236250        }
    237 
     251       
    238252        if (treq->status != EOK) {
    239253                rc = treq->status;
    240254                goto error;
    241255        }
    242 
     256       
    243257        *rresp = treq->resp;
    244258        treq_destroy(treq);
    245259        free(req_data);
    246260        return EOK;
     261       
    247262error:
    248263        if (treq != NULL)
    249264                treq_destroy(treq);
     265       
    250266        free(req_data);
    251267        return rc;
Note: See TracChangeset for help on using the changeset viewer.