Initial commit of files
This commit is contained in:
45
src/libnet/ip_hostname.c
Normal file
45
src/libnet/ip_hostname.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user