apportate/src/connect.c

27 lines
345 B
C
Raw Normal View History

2022-11-24 08:18:05 +00:00
#include "headers.h"
2022-12-13 17:12:07 +00:00
2023-02-19 20:44:19 +00:00
int dial(const char *fqdn, const char *proto)
2022-12-13 17:12:07 +00:00
{
int sd;
struct addrinfo *ainfo;
2022-11-24 08:18:05 +00:00
2023-02-19 20:44:19 +00:00
if( !(sd = socket(AF_INET, SOCK_STREAM, 0)))
2022-12-13 21:21:35 +00:00
{
return(0);
}
2022-11-24 08:18:05 +00:00
2023-02-19 20:44:19 +00:00
if(getaddrinfo(fqdn, proto, 0, &ainfo))
2022-12-13 21:21:35 +00:00
{
return(0);
}
2022-11-24 08:18:05 +00:00
2022-12-13 21:21:35 +00:00
if(connect(sd, ainfo->ai_addr, ainfo->ai_addrlen))
{
return(0);
}
2022-11-24 08:18:05 +00:00
2022-12-13 21:21:35 +00:00
return(sd);
}