Initial commit of files

This commit is contained in:
2021-01-22 10:16:20 -05:00
parent 32d165ec8f
commit ed92211680
534 changed files with 68563 additions and 19 deletions

51
src/libnet/udp_client.c Normal file
View File

@ -0,0 +1,51 @@
//
// UDP Client Connect
//
#include "netlib.h"
int udp_client( const char *host, const char *service )
{
int sock; /* tcp socket */
struct addrinfo hints, *res, *ressave;
/* default IPv6 localhost */
if ( !host || !strlen(host) )
host = "ip6-localhost";
/* get address information */
bzero(&hints, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
if ( getaddrinfo(host, service, &hints, &res) )
{
log_error("getaddrinfo");
return -1;
}
ressave = res;
while (res)
{
sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sock < 0)
continue; // ignore
// connected (allows send()/write() to be used)
if ( connect(sock, res->ai_addr, res->ai_addrlen) == 0 )
break; // success
// next
close(sock);
res = res->ai_next;
}
if ( !res )
{
log_error("udp_client");
return -1;
}
freeaddrinfo(ressave);
return sock;
}