apportate/src/connect.c

27 lines
345 B
C
Raw Normal View History

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