Changeset 98abd40 in mainline for uspace/app/nterm/conn.c


Ignore:
Timestamp:
2013-07-06T21:57:22Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c8bb1633, cdc8a391
Parents:
b8e72fd1 (diff), 507c6f3 (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:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nterm/conn.c

    rb8e72fd1 r98abd40  
    7575int conn_open(const char *addr_s, const char *port_s)
    7676{
    77         struct sockaddr_in addr;
    78         dnsr_hostinfo_t *hinfo = NULL;
    79         int rc;
    80         char *endptr;
    81 
    82         addr.sin_family = AF_INET;
    83 
    84         rc = inet_pton(addr.sin_family, addr_s, (uint8_t *)&addr.sin_addr);
     77        int conn_fd = -1;
     78       
     79        /* Interpret as address */
     80        inet_addr_t addr_addr;
     81        int rc = inet_addr_parse(addr_s, &addr_addr);
     82       
    8583        if (rc != EOK) {
    86                 /* Try interpreting as a host name */
     84                /* Interpret as a host name */
     85                dnsr_hostinfo_t *hinfo = NULL;
    8786                rc = dnsr_name2host(addr_s, &hinfo);
     87               
    8888                if (rc != EOK) {
    8989                        printf("Error resolving host '%s'.\n", addr_s);
    9090                        goto error;
    9191                }
    92 
    93                 addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
     92               
     93                addr_addr = hinfo->addr;
    9494        }
    95 
    96         addr.sin_port = htons(strtol(port_s, &endptr, 10));
     95       
     96        struct sockaddr_in addr;
     97        struct sockaddr_in6 addr6;
     98        uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
     99       
     100        char *endptr;
     101        uint16_t port = strtol(port_s, &endptr, 10);
    97102        if (*endptr != '\0') {
    98103                printf("Invalid port number %s\n", port_s);
    99104                goto error;
    100105        }
    101 
     106       
     107        printf("Connecting to host %s port %u\n", addr_s, port);
     108       
    102109        conn_fd = socket(PF_INET, SOCK_STREAM, 0);
    103110        if (conn_fd < 0)
    104111                goto error;
    105 
    106         printf("Connecting to host %s port %u\n", addr_s, ntohs(addr.sin_port));
    107 
    108         rc = connect(conn_fd, (struct sockaddr *)&addr, sizeof(addr));
     112       
     113        switch (af) {
     114        case AF_INET:
     115                addr.sin_port = htons(port);
     116                rc = connect(conn_fd, (struct sockaddr *) &addr, sizeof(addr));
     117                break;
     118        case AF_INET6:
     119                addr6.sin6_port = htons(port);
     120                rc = connect(conn_fd, (struct sockaddr *) &addr6, sizeof(addr6));
     121                break;
     122        default:
     123                printf("Unknown address family.\n");
     124                goto error;
     125        }
     126       
    109127        if (rc != EOK)
    110128                goto error;
    111 
     129       
    112130        rcv_fid = fibril_create(rcv_fibril, NULL);
    113131        if (rcv_fid == 0)
    114132                goto error;
    115 
     133       
    116134        fibril_add_ready(rcv_fid);
    117 
     135       
    118136        return EOK;
    119 
     137       
    120138error:
    121139        if (conn_fd >= 0) {
     
    123141                conn_fd = -1;
    124142        }
    125 
     143       
    126144        return EIO;
    127145}
     
    129147int conn_send(void *data, size_t size)
    130148{
    131         int rc;
    132 
    133         rc = send(conn_fd, data, size, 0);
     149        int rc = send(conn_fd, data, size, 0);
    134150        if (rc != EOK)
    135151                return EIO;
    136 
     152       
    137153        return EOK;
    138154}
Note: See TracChangeset for help on using the changeset viewer.