]> git.meshlink.io Git - catta/blobdiff - src/socket.c
socket.c needs closesocket from internal.h
[catta] / src / socket.c
index a6dd588c7052416f06d391b910c6c454f48a2b66..01eeaebabfd9a3ac92cf26166756a0159edeee3b 100644 (file)
@@ -50,6 +50,7 @@
 #include "fdutil.h"
 #include "socket.h"
 #include "addr-util.h"
+#include "internal.h"
 
 /* this is a portability hack */
 #ifndef IPV6_ADD_MEMBERSHIP
@@ -364,7 +365,7 @@ int catta_open_socket_ipv4(int no_reuse) {
 
 fail:
     if (fd >= 0)
-        close(fd);
+        closesocket(fd);
 
     return -1;
 }
@@ -434,7 +435,7 @@ int catta_open_socket_ipv6(int no_reuse) {
 
 fail:
     if (fd >= 0)
-        close(fd);
+        closesocket(fd);
 
     return -1;
 }
@@ -469,7 +470,7 @@ static int sendmsg_loop(int fd, struct msghdr *msg, int flags) {
 
 int catta_send_dns_packet_ipv4(
         int fd,
-        CattaIfIndex interface,
+        CattaIfIndex iface,
         CattaDnsPacket *p,
         const CattaIPv4Address *src_address,
         const CattaIPv4Address *dst_address,
@@ -510,7 +511,7 @@ int catta_send_dns_packet_ipv4(
     msg.msg_controllen = 0;
 
 #ifdef IP_PKTINFO
-    if (interface > 0 || src_address) {
+    if (iface > 0 || src_address) {
         struct in_pktinfo *pkti;
 
         memset(cmsg_data, 0, sizeof(cmsg_data));
@@ -524,11 +525,13 @@ int catta_send_dns_packet_ipv4(
 
         pkti = (struct in_pktinfo*) CMSG_DATA(cmsg);
 
-        if (interface > 0)
-            pkti->ipi_ifindex = interface;
+        if (iface > 0)
+            pkti->ipi_ifindex = iface;
 
+#ifdef HAVE_IPI_SPEC_DST
         if (src_address)
             pkti->ipi_spec_dst.s_addr = src_address->address;
+#endif
     }
 #elif defined(IP_MULTICAST_IF)
     if (src_address) {
@@ -563,7 +566,7 @@ int catta_send_dns_packet_ipv4(
 
 int catta_send_dns_packet_ipv6(
         int fd,
-        CattaIfIndex interface,
+        CattaIfIndex iface,
         CattaDnsPacket *p,
         const CattaIPv6Address *src_address,
         const CattaIPv6Address *dst_address,
@@ -596,7 +599,7 @@ int catta_send_dns_packet_ipv6(
     msg.msg_iovlen = 1;
     msg.msg_flags = 0;
 
-    if (interface > 0 || src_address) {
+    if (iface > 0 || src_address) {
         struct in6_pktinfo *pkti;
 
         memset(cmsg_data, 0, sizeof(cmsg_data));
@@ -610,8 +613,8 @@ int catta_send_dns_packet_ipv6(
 
         pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg);
 
-        if (interface > 0)
-            pkti->ipi6_ifindex = interface;
+        if (iface > 0)
+            pkti->ipi6_ifindex = iface;
 
         if (src_address)
             memcpy(&pkti->ipi6_addr, src_address->address, sizeof(src_address->address));
@@ -942,7 +945,7 @@ int catta_open_unicast_socket_ipv4(void) {
 
 fail:
     if (fd >= 0)
-        close(fd);
+        closesocket(fd);
 
     return -1;
 }
@@ -987,7 +990,7 @@ int catta_open_unicast_socket_ipv6(void) {
 
 fail:
     if (fd >= 0)
-        close(fd);
+        closesocket(fd);
 
     return -1;
 }