X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsocket.c;h=31adcf81a99e5080ccd7ea7af3e80be8c0bee1f4;hb=08ac450b42b7533e97c02c02bbbef8946b9582fb;hp=dc989d8ac466f1647a5aa278b5ee980b667aae77;hpb=4ac8d5e93bf09c86e8352cdc2099b35ec89ba3a9;p=catta diff --git a/src/socket.c b/src/socket.c index dc989d8..31adcf8 100644 --- a/src/socket.c +++ b/src/socket.c @@ -21,6 +21,8 @@ #include #endif +#define __APPLE_USE_RFC_2292 + #include #include #include @@ -105,7 +107,7 @@ static void ipv6_address_to_sockaddr(struct sockaddr_in6 *ret_sa, const CattaIPv memcpy(&ret_sa->sin6_addr, a, sizeof(CattaIPv6Address)); } -int catta_mdns_mcast_join_ipv4(int fd, const CattaIPv4Address *a, int idx, int join) { +int catta_mdns_mcast_join_ipv4(int fd, const CattaIPv4Address *a, CattaIfIndex idx, int join) { #ifdef HAVE_STRUCT_IP_MREQN struct ip_mreqn mreq; #else @@ -141,7 +143,7 @@ int catta_mdns_mcast_join_ipv4(int fd, const CattaIPv4Address *a, int idx, int j return 0; } -int catta_mdns_mcast_join_ipv6(int fd, const CattaIPv6Address *a, int idx, int join) { +int catta_mdns_mcast_join_ipv6(int fd, const CattaIPv6Address *a, CattaIfIndex idx, int join) { struct ipv6_mreq mreq6; struct sockaddr_in6 sa6; @@ -464,9 +466,12 @@ static int sendmsg_loop(int fd, struct msghdr *msg, int flags) { if (errno != EAGAIN && errno != EWOULDBLOCK) { char where[64]; - struct sockaddr_in *sin = msg->msg_name; + struct sockaddr *sa = msg->msg_name; - inet_ntop(sin->sin_family, &sin->sin_addr, where, sizeof(where)); + if(sa->sa_family == AF_INET) + inet_ntop(sa->sa_family, &((struct sockaddr_in *)sa)->sin_addr, where, sizeof(where)); + else + inet_ntop(sa->sa_family, &((struct sockaddr_in6 *)sa)->sin6_addr, where, sizeof(where)); catta_log_debug("sendmsg() to %s failed: %s", where, errnostrsocket()); return -1; } @@ -541,6 +546,9 @@ int catta_send_dns_packet_ipv4( #ifdef HAVE_IPI_SPEC_DST if (src_address) pkti->ipi_spec_dst.s_addr = src_address->address; +#else + if (src_address) + pkti->ipi_addr.s_addr = src_address->address; #endif } #elif defined(IP_MULTICAST_IF) @@ -609,6 +617,11 @@ int catta_send_dns_packet_ipv6( msg.msg_iovlen = 1; msg.msg_flags = 0; +// TODO: don't ask me why, but Win8.1 64bit WSASendMsg() fails with an InvalidArgument error 10022 when IPv6 source address is specified ( everHannes / hannes.ahrens@everbase.net ) +#ifdef _WIN32 + msg.msg_control = NULL; + msg.msg_controllen = 0; +#else if (iface > 0 || src_address) { struct in6_pktinfo *pkti; @@ -632,6 +645,7 @@ int catta_send_dns_packet_ipv6( msg.msg_control = NULL; msg.msg_controllen = 0; } +#endif return sendmsg_loop(fd, &msg, 0); }