STCP/client.c
int
parse_address(char *address, struct sockaddr_in *sin)
{
    char *address_copy = NULL;
    char *pc;
    unsigned h_port;
    int rc = -1;
    struct hostent *he;

    if (NULL == (address_copy = strdup(address)))
        goto cleanup;

    memset(sin, 0, sizeof(*sin));
    sin->sin_family = AF_INET;

    if (NULL == (pc = strchr(address_copy, ':')))
    {
        sin->sin_port = 0;
    }
    else
    {
        if (1 != sscanf(pc + 1, "%u", &h_port))
        {
            errno = EINVAL;
            goto cleanup;
        }

        sin->sin_port = htons(h_port);
        *pc = '\0';
    }

    if ((in_addr_t) - 1 == (sin->sin_addr.s_addr = inet_addr(address_copy)))
    {
        if (NULL == (he = gethostbyname(address_copy)) ||
            he->h_addrtype != AF_INET || he->h_length != 4)
        {
            errno = EADDRNOTAVAIL;
            goto cleanup;
        }

        memcpy((char *) &sin->sin_addr, he->h_addr, sizeof(sin->sin_addr));
    }

    rc = 0;

cleanup:
    if (address_copy)
        free(address_copy);

    return rc;
}
/**********************************************************************/
/* parse_address
 *
 * Get the address and write it in the appropiate format to "sin"
 */
parse_address
Get the address and write it in the appropiate format to "sin"
parse_address Get the address and write it in the appropiate format to " sin "
int
parse_address(char *address, struct sockaddr_in *sin)
{
    char *address_copy = NULL;
    char *pc;
    unsigned h_port;
    int rc = -1;
    struct hostent *he;
    if (NULL == (address_copy = strdup(address)))
        goto cleanup;
    memset(sin, 0, sizeof(*sin));
    sin->sin_family = AF_INET;
    if (NULL == (pc = strchr(address_copy, ':')))
    {
        sin->sin_port = 0;
    }
    else
    {
        if (1 != sscanf(pc + 1, "%u", &h_port))
        {
            errno = EINVAL;
            goto cleanup;
        }
        sin->sin_port = htons(h_port);
        *pc = '\0';
    }
    if ((in_addr_t) - 1 == (sin->sin_addr.s_addr = inet_addr(address_copy)))
    {
        if (NULL == (he = gethostbyname(address_copy)) ||
            he->h_addrtype != AF_INET || he->h_length != 4)
        {
            errno = EADDRNOTAVAIL;
            goto cleanup;
        }
        memcpy((char *) &sin->sin_addr, he->h_addr, sizeof(sin->sin_addr));
    }
    rc = 0;
cleanup:
    if (address_copy)
        free(address_copy);
    return rc;
}
int parse_address ( char * address , struct sockaddr_in * sin ) { char * address_copy = NULL ; char * pc ; unsigned h_port ; int rc = -1 ; struct hostent * he ; if ( NULL == ( address_copy = strdup ( address ) ) ) goto cleanup ; memset ( sin , 0 , sizeof ( * sin ) ) ; sin -> sin_family = AF_INET ; if ( NULL == ( pc = strchr ( address_copy , ' ' ) ) ) { sin -> sin_port = 0 ; } else { if ( 1 != sscanf ( pc + 1 , " " , & h_port ) ) { errno = EINVAL ; goto cleanup ; } sin -> sin_port = htons ( h_port ) ; * pc = ' \0 ' ; } if ( ( in_addr_t ) - 1 == ( sin -> sin_addr . s_addr = inet_addr ( address_copy ) ) ) { if ( NULL == ( he = gethostbyname ( address_copy ) ) || he -> h_addrtype != AF_INET || he -> h_length != 4 ) { errno = EADDRNOTAVAIL ; goto cleanup ; } memcpy ( ( char * ) & sin -> sin_addr , he -> h_addr , sizeof ( sin -> sin_addr ) ) ; } rc = 0 ; cleanup : if ( address_copy ) free ( address_copy ) ; return rc ; }
parse_address
 Get the address and write it in the appropiate format to "sin"
parse_address Get the address and write it in the appropiate format to " sin "