#include #include #include #include #include /* changed from 873 to 8733, so it can run as user, the actual port does not * matter */ #define RSYNC_PORT (8733) int main() { int so1, so2; int32_t optval; /* The following code is rewritten from a strace of rsync --daemon. */ so1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); optval = 1; setsockopt(so1, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(optval)); struct sockaddr_in sa1 = {.sin_family = AF_INET, .sin_port = htons(RSYNC_PORT), .sin_addr = inet_addr("0.0.0.0")}; bind(so1, (struct sockaddr *)&sa1, sizeof(sa1)); so2 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); optval = 1; setsockopt(so2, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(optval)); optval = 1; setsockopt(so2, SOL_IPV6, IPV6_V6ONLY, (void *)&optval, sizeof(optval)); struct sockaddr_in6 sa2 = {.sin6_family = AF_INET6, .sin6_port = htons(RSYNC_PORT), .sin6_flowinfo = htonl(0), .sin6_scope_id = 0}; inet_pton(AF_INET6, "::", &sa2.sin6_addr); bind(so2, (struct sockaddr *)&sa2, sizeof(sa2)); /* WARN_ON() is thrown here: */ listen(so1, 5); /* listen(so2, 5); */ }