summaryrefslogtreecommitdiff
path: root/toxcore/LAN_discovery.c
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-11 11:44:05 +0200
committerCoren[m] <Break@Ocean>2013-09-11 11:44:05 +0200
commit5e076e35d92f8dc6d28060afee5160339cad11a3 (patch)
tree0d08f095c8f270db894ec75e13cbc2ef18f25306 /toxcore/LAN_discovery.c
parent85912418db41d692b78b6bfe7a567ee2ca24e742 (diff)
network.c: logging more details, fixing poll
LAN_discovery.c: IPv6: send both v6 multicast and v4 broadcast if socket allows
Diffstat (limited to 'toxcore/LAN_discovery.c')
-rw-r--r--toxcore/LAN_discovery.c64
1 files changed, 47 insertions, 17 deletions
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 4cbe3177..933c2402 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -81,27 +81,35 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t * d
81#endif 81#endif
82 82
83/* Return the broadcast ip. */ 83/* Return the broadcast ip. */
84static IP broadcast_ip(sa_family_t sa_family) 84static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
85{ 85{
86 IP ip; 86 IP ip;
87 ip_reset(&ip); 87 ip_reset(&ip);
88 88
89#ifdef TOX_ENABLE_IPV6 89#ifdef TOX_ENABLE_IPV6
90 if (sa_family == AF_INET) 90 if (family_socket == AF_INET6) {
91 { 91 if (family_broadcast == AF_INET6) {
92 ip.family = AF_INET; 92 ip.family = AF_INET6;
93 ip.ip4.uint32 = INADDR_BROADCAST; 93 /* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */
94 /* FE80::*: MUST be exact, for that we would need to look over all
95 * interfaces and check in which status they are */
96 ip.ip6.s6_addr[ 0] = 0xFF;
97 ip.ip6.s6_addr[ 1] = 0x02;
98 ip.ip6.s6_addr[15] = 0x01;
99 }
100 else if (family_broadcast == AF_INET) {
101 ip.family = AF_INET6;
102 ip.ip6.s6_addr32[0] = 0;
103 ip.ip6.s6_addr32[1] = 0;
104 ip.ip6.s6_addr32[2] = htonl(0xFFFF);
105 ip.ip6.s6_addr32[3] = INADDR_BROADCAST;
106 }
94 } 107 }
95 108 else if (family_socket == AF_INET) {
96 if (sa_family == AF_INET6) 109 if (family_broadcast == AF_INET) {
97 { 110 ip.family = AF_INET;
98 ip.family = AF_INET6; 111 ip.ip4.uint32 = INADDR_BROADCAST;
99 /* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */ 112 }
100 /* FE80::*: MUST be exact, for that we would need to look over all
101 * interfaces and check in which status they are */
102 ip.ip6.s6_addr[ 0] = 0xFF;
103 ip.ip6.s6_addr[ 1] = 0x02;
104 ip.ip6.s6_addr[15] = 0x01;
105 } 113 }
106#else 114#else
107 ip.uint32 = INADDR_BROADCAST; 115 ip.uint32 = INADDR_BROADCAST;
@@ -175,13 +183,35 @@ int send_LANdiscovery(uint16_t port, Net_Crypto *c)
175 uint8_t data[crypto_box_PUBLICKEYBYTES + 1]; 183 uint8_t data[crypto_box_PUBLICKEYBYTES + 1];
176 data[0] = NET_PACKET_LAN_DISCOVERY; 184 data[0] = NET_PACKET_LAN_DISCOVERY;
177 memcpy(data + 1, c->self_public_key, crypto_box_PUBLICKEYBYTES); 185 memcpy(data + 1, c->self_public_key, crypto_box_PUBLICKEYBYTES);
186
178#ifdef __linux 187#ifdef __linux
179 send_broadcasts(c->lossless_udp->net, port, data, 1 + crypto_box_PUBLICKEYBYTES); 188 send_broadcasts(c->lossless_udp->net, port, data, 1 + crypto_box_PUBLICKEYBYTES);
180#endif 189#endif
190
191 int res = -1;
181 IP_Port ip_port; 192 IP_Port ip_port;
182 ip_port.ip = broadcast_ip(c->lossless_udp->net->family);
183 ip_port.port = port; 193 ip_port.port = port;
184 return sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES); 194
195#ifdef TOX_ENABLE_IPV6
196 if (c->lossless_udp->net->family == AF_INET6) {
197 ip_port.ip = broadcast_ip(c->lossless_udp->net->family, AF_INET6);
198 if (ip_isset(&ip_port.ip))
199 if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES) > 0)
200 res = 1;
201 }
202
203 ip_port.ip = broadcast_ip(c->lossless_udp->net->family, AF_INET);
204 if (ip_isset(&ip_port.ip))
205 if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
206 res = 1;
207#else
208 ip_port.ip = broadcast_ip(c->lossless_udp->net->family, AF_INET);
209 if (ip_isset(&ip_port.ip))
210 if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
211 res = 1;
212#endif
213
214 return res;
185} 215}
186 216
187 217