43 lines
1007 B
C
43 lines
1007 B
C
#include "headers.h"
|
|
|
|
int dial(const char *fqdn, const char *proto)
|
|
{
|
|
int sd;
|
|
struct addrinfo hints;
|
|
struct addrinfo *ainfo;
|
|
|
|
if( !(sd = socket(AF_INET, SOCK_STREAM, 0)))
|
|
{
|
|
return(0);
|
|
}
|
|
|
|
/* using hints at all right now seems to break our connectivity... */
|
|
/* POSIX demands that all fields of a hints struct are initialized */
|
|
memset(&hints, 0, sizeof(struct addrinfo));
|
|
/* only return IPv6/4 addresses if the system can handle them */
|
|
hints.ai_flags = AI_ADDRCONFIG;
|
|
/* we want both IPv4 and IPv6 to be configured */
|
|
hints.ai_family = AF_UNSPEC;
|
|
/* connecting via TCP stream */
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
/* using the default protocol for TCP over inet */
|
|
/* seems to break fetch on BSD? */
|
|
/* hints.ai_protocol = IPPROTO_TCP; */
|
|
|
|
|
|
if(getaddrinfo(fqdn, proto, NULL, &ainfo))
|
|
{
|
|
return(0);
|
|
}
|
|
|
|
|
|
|
|
if(connect(sd, ainfo->ai_addr, sizeof(struct sockaddr)))
|
|
{
|
|
return(0);
|
|
}
|
|
|
|
|
|
return(sd);
|
|
}
|