2018-10-21 09:00:15 -05:00
|
|
|
#ifndef TUNSAFE_IPADDR_H_
|
|
|
|
#define TUNSAFE_IPADDR_H_
|
|
|
|
|
|
|
|
#include "tunsafe_types.h"
|
2018-11-16 08:01:44 -06:00
|
|
|
#include <vector>
|
2018-10-21 09:00:15 -05:00
|
|
|
#if !defined(OS_WIN)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
union IpAddr {
|
|
|
|
sockaddr_in sin;
|
|
|
|
sockaddr_in6 sin6;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WgCidrAddr {
|
|
|
|
uint8 addr[16];
|
|
|
|
uint8 size;
|
|
|
|
uint8 cidr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DnsResolver;
|
|
|
|
|
|
|
|
#define kSizeOfAddress 64
|
|
|
|
const char *print_ip_prefix(char buf[kSizeOfAddress], int family, const void *ip, int prefixlen);
|
|
|
|
char *PrintIpAddr(const IpAddr &addr, char buf[kSizeOfAddress]);
|
|
|
|
char *PrintWgCidrAddr(const WgCidrAddr &addr, char buf[kSizeOfAddress]);
|
|
|
|
bool ParseCidrAddr(const char *s, WgCidrAddr *out);
|
|
|
|
|
2018-11-16 08:01:44 -06:00
|
|
|
bool IsWgCidrAddrSubsetOfAny(const WgCidrAddr &inner, const std::vector<WgCidrAddr> &addr);
|
|
|
|
|
2018-10-21 09:00:15 -05:00
|
|
|
enum {
|
|
|
|
kParseSockaddrDontDoNAT64 = 1,
|
|
|
|
};
|
|
|
|
bool ParseSockaddrInWithPort(const char *s, IpAddr *sin, DnsResolver *resolver, int flags = 0);
|
|
|
|
bool ParseSockaddrInWithoutPort(char *s, IpAddr *sin, DnsResolver *resolver, int flags = 0);
|
|
|
|
|
2018-11-16 07:37:51 -06:00
|
|
|
// Returns nonzero if two endpoints are different.
|
|
|
|
uint32 CompareIpAddr(const IpAddr *a, const IpAddr *b);
|
2018-10-21 09:00:15 -05:00
|
|
|
|
|
|
|
#endif // TUNSAFE_IPADDR_H_
|