acl/lib_acl/include/net/acl_sane_inet.h

100 lines
3.4 KiB
C
Raw Normal View History

#ifndef ACL_SANE_INET_INCLUDE_H
2014-11-19 00:25:21 +08:00
#define ACL_SANE_INET_INCLUDE_H
#ifdef __cplusplus
extern "C" {
#endif
2017-06-02 14:47:24 +08:00
#include "../stdlib/acl_define.h"
2014-11-19 00:25:21 +08:00
#ifdef ACL_UNIX
#include <netinet/in.h>
2018-09-12 17:43:46 +08:00
#include <sys/un.h>
2014-11-19 00:25:21 +08:00
#endif
2018-09-12 17:43:46 +08:00
typedef union {
struct sockaddr_storage ss;
#ifdef AF_INET6
struct sockaddr_in6 in6;
#endif
struct sockaddr_in in;
#ifdef ACL_UNIX
struct sockaddr_un un;
#endif
struct sockaddr sa;
} ACL_SOCKADDR;
/**
* socket IPV4 IPV6 UNIX
2018-09-12 17:43:46 +08:00
* @param sa {const struct sockaddr*}
* @param buf {char*}
* @param size {size_t} buf
* @return {size_t} sockaddr IPV4
* struct sockaddr_in IPV6 struct sockaddr_in6
* 0
2018-09-12 17:43:46 +08:00
*/
ACL_API size_t acl_inet_ntop(const struct sockaddr *sa, char *buf, size_t size);
/**
* socket IPV4 IPV6 UNIX
* @param af {int} AF_INETIPV4 AF_INET6IPV6
* @param src {const char*} ipip#port ipv4:port
* @param dst {struct sockaddr*}
* @return {size_t} IPV4 IPV6 IPV4
* struct sockaddr_in IPV6 struct sockaddr_in6
* 0
2018-09-12 17:43:46 +08:00
*/
ACL_API size_t acl_inet_pton(int af, const char *src, struct sockaddr *dst);
/**
* socket IPV4 IPV6 UNIX
* IPV4 IPV6
* @param src {const char*} ipip#port ipv4:port
* @param dst {struct sockaddr*}
* @return {size_t} IPV4 IPV6 IPV4
* struct sockaddr_in IPV6 struct sockaddr_in6
* 0
2018-09-12 17:43:46 +08:00
*/
ACL_API size_t acl_sane_pton(const char *src, struct sockaddr *dst);
2014-11-19 00:25:21 +08:00
/**
* IP地址转换成字符串格式
* @param src {const unsigned char*} struct in_addr in.s_addr
* @param dst {char *}
* @param size {size_t} dst
2014-11-19 00:25:21 +08:00
* @return {const char*} NULL: error; !NULL: ok
*/
ACL_API const char *acl_inet_ntop4(const unsigned char *src, char *dst, size_t size);
/**
* IP地址转换成字符串格式
2014-11-19 00:25:21 +08:00
* @param in {struct in_addr}
* @param dst {char *}
* @param size {size_t} dst
2014-11-19 00:25:21 +08:00
* @return {const char*} NULL: error; !NULL: ok
*/
ACL_API const char *acl_inet_ntoa(struct in_addr in, char *dst, size_t size);
/**
* ip
2014-11-19 00:25:21 +08:00
* @param ip {const char *ip}
* @return {int} != 0: ; == 0:
2014-11-19 00:25:21 +08:00
*/
ACL_API int acl_is_ip(const char *ip);
2017-04-07 20:13:08 +08:00
ACL_API int acl_is_ipv4(const char *ip);
ACL_API int acl_is_ipv6(const char *ip);
2014-11-19 00:25:21 +08:00
/**
* ip xxx.xxx.xxx.xxx:port
* @param addr {const char*} IP:PORT
* @return {int} 1: , 0:
2014-11-19 00:25:21 +08:00
*/
ACL_API int acl_ipv4_addr_valid(const char *addr);
#ifdef __cplusplus
}
#endif
#endif