check mapped IPv4

This commit is contained in:
ruti 2023-07-08 20:04:24 +02:00
parent 3be8b82084
commit a35039e6d7
2 changed files with 11 additions and 9 deletions

View File

@ -183,11 +183,15 @@ int desync(int sfd, char *buffer,
int desync_udp(int fd, char *buffer,
ssize_t n, struct sockaddr_in6 *dst)
{
if (params.desync_udp & DESYNC_UDP_FAKE) {
if (setttl(fd, params.ttl, AF_INET) < 0) {
return -1;
char is_mv4 = 1;
if (dst->sin6_family == AF_INET6) {
static char *pat = "\0\0\0\0\0\0\0\0\0\0\xff\xff";
is_mv4 = !memcmp(&dst->sin6_addr, pat, 12);
}
if (setttl(fd, params.ttl, AF_INET6) < 0) {
if (params.desync_udp & DESYNC_UDP_FAKE) {
if (setttl(fd, params.ttl,
is_mv4 ? AF_INET : dst->sin6_family) < 0) {
return -1;
}
if (sendto(fd, fake_udp.data, fake_udp.size,
@ -195,10 +199,8 @@ int desync_udp(int fd, char *buffer,
perror("sendto");
return -1;
}
if (setttl(fd, params.def_ttl, AF_INET) < 0) {
return -1;
}
if (setttl(fd, params.def_ttl, AF_INET6) < 0) {
if (setttl(fd, params.def_ttl,
is_mv4 ? AF_INET : dst->sin6_family) < 0) {
return -1;
}
}

View File

@ -45,7 +45,7 @@ static inline int ip_cmp(
}
static inline void map_fix(struct sockaddr_ina *addr, int f6)
void map_fix(struct sockaddr_ina *addr, char f6)
{
struct {
uint64_t o64;