acl/lib_acl/include/net/acl_sane_inet.h

104 lines
3.2 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;
/**
* <EFBFBD><EFBFBD> socket <EFBFBD><EFBFBD>ַתΪ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ͬʱ֧<EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD> UNIX <EFBFBD><EFBFBD><EFBFBD>׽ӿ<EFBFBD>
2018-09-12 17:43:46 +08:00
* @param sa {const struct sockaddr*}
* @param buf {char*} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} buf <EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С
* @return {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> sockaddr <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ʵ<EFBFBD>ʳ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ӧ struct sockaddr_in <EFBFBD>Ľ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ struct sockaddr_in6
* <EFBFBD>Ľ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ 0 <EFBFBD><EFBFBD>ʾת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-09-12 17:43:46 +08:00
*/
ACL_API size_t acl_inet_ntop(const struct sockaddr *sa, char *buf, size_t size);
/**
* <EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ĵ<EFBFBD>ַתΪ socket <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD> UNIX <EFBFBD><EFBFBD><EFBFBD>׽ӿ<EFBFBD>
* @param af {int} <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>AF_INET<EFBFBD><EFBFBD>IPV4<EFBFBD><EFBFBD><EFBFBD><EFBFBD> AF_INET6<EFBFBD><EFBFBD>IPV6<EFBFBD><EFBFBD>
* @param src {const char*} <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ ip<EFBFBD><EFBFBD>ip#port <EFBFBD><EFBFBD> ipv4:port
* @param dst {struct sockaddr*} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {size_t} <EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ IPV4 <EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ӧ struct sockaddr_in <EFBFBD>Ľ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ struct sockaddr_in6
* <EFBFBD>Ľ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ 0 <EFBFBD><EFBFBD>ʾת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-09-12 17:43:46 +08:00
*/
ACL_API size_t acl_inet_pton(int af, const char *src, struct sockaddr *dst);
/**
* <EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ĵ<EFBFBD>ַתΪ socket <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD> UNIX <EFBFBD><EFBFBD><EFBFBD>׽ӿڣ<EFBFBD>
* <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>̽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV6
* @param src {const char*} <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ ip<EFBFBD><EFBFBD>ip#port <EFBFBD><EFBFBD> ipv4:port
* @param dst {struct sockaddr*} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {size_t} <EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ IPV4 <EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV4 <EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ӧ struct sockaddr_in <EFBFBD>Ľ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPV6 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ struct sockaddr_in6
* <EFBFBD>Ľ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ 0 <EFBFBD><EFBFBD>ʾת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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
/**
* <EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD>ַת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
* @param src {const unsigned char*} struct in_addr in.s_addr <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ʾ
* @param dst {char *} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} dst <EFBFBD>Ŀռ<EFBFBD><EFBFBD><EFBFBD>С
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);
/**
* <EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD>ַת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
2014-11-19 00:25:21 +08:00
* @param in {struct in_addr}
* @param dst {char *} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} dst <EFBFBD>Ŀռ<EFBFBD><EFBFBD><EFBFBD>С
2014-11-19 00:25:21 +08:00
* @return {const char*} NULL: error; !NULL: ok
*/
2020-10-18 18:23:24 +08:00
ACL_API const char *acl_inet_ntoa(const struct in_addr in, char *dst, size_t size);
#ifdef AF_INET6
ACL_API const char *acl_inet6_ntoa(const struct in6_addr in6, char *buf, size_t size);
#endif
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD>жϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD> ip <EFBFBD><EFBFBD>ַ
2014-11-19 00:25:21 +08:00
* @param ip {const char *ip}
* @return {int} != 0: <EFBFBD><EFBFBD>; == 0: <EFBFBD><EFBFBD>
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
/**
* <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ip <EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xxx.xxx.xxx.xxx:port <EFBFBD><EFBFBD>ʽ
* @param addr {const char*} IP:PORT <EFBFBD><EFBFBD>ַ
* @return {int} 1: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
ACL_API int acl_ipv4_addr_valid(const char *addr);
#ifdef __cplusplus
}
#endif
#endif