#include "headers.h" int dial(const char *fqdn, const char *proto, struct tls **tlsres) { int sd; struct addrinfo *ainfo; struct tls_config *tlshints; if( !(sd = socket(AF_INET, SOCK_STREAM, 0))) { return(0); } if(getaddrinfo(fqdn, proto, 0, &ainfo)) { return(0); } if(connect(sd, ainfo->ai_addr, ainfo->ai_addrlen)) { return(0); } if(tlsres != 0) { close(sd); if( 0 == (*tlsres = tls_client())) { goto err_ssl; } if( 0 == (tlshints = tls_config_new())) { goto err_ssl; } if(tls_configure(*tlsres, tlshints)) { goto err_ssl; } if( (tls_connect(*tlsres, fqdn, proto))) { goto err_ssl; } } return(sd); err_ssl: return(0); }