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

45
src/libnet/ip_hostname.c Normal file
View File

@ -0,0 +1,45 @@
//
// IP gethostname
//
#include "netlib.h"
const char *ip_host2name( char *buf, int max, const struct sockaddr_storage *sa )
{
const char *s = NULL;
switch (sa->ss_family)
{
case AF_INET:
s = inet_ntop(sa->ss_family,
&((struct sockaddr_in *)sa)->sin_addr,
buf, max);
break;
case AF_INET6:
s = inet_ntop(sa->ss_family,
&((struct sockaddr_in6 *)sa)->sin6_addr,
buf, max);
break;
}
if ( s )
return s;
return strerror(errno);
}
int ip_name2host( const char *buf, struct sockaddr_storage *sa )
{
// from string
switch (sa->ss_family)
{
case AF_INET:
return inet_pton(sa->ss_family, buf,
&((struct sockaddr_in *)sa)->sin_addr );
break;
case AF_INET6:
return inet_pton(sa->ss_family, buf,
&((struct sockaddr_in6 *)sa)->sin6_addr );
break;
}
return EAFNOSUPPORT;
}