[package] add smap, a SIP device discovery program, patch from Daniel Dickinson
[openwrt/svn-archive/archive.git] / net / smap / patches / 00-fix-broadcast.patch
1 diff -Naur smap.orig/icmpping.c smap/icmpping.c
2 --- smap.orig/icmpping.c 2007-10-07 06:15:11.000000000 -0400
3 +++ smap/icmpping.c 2009-06-13 11:57:28.000000000 -0400
4 @@ -182,6 +182,7 @@
5 struct sockaddr_in sin;
6 #define ICMP_PKT_LEN (sizeof(struct icmp) + ICMP_PAYLOAD_LEN)
7 char icmpbuf[ICMP_PKT_LEN];
8 + socklen_t socklen;
9
10 /* prepare ICMP packet */
11 memset(&icmpbuf, 'A', ICMP_PKT_LEN);
12 @@ -207,6 +208,8 @@
13 if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) != 0)
14 perror("setsockopt");
15 #endif
16 + if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)) != 0)
17 + perror("setsockopt");
18 icmp->icmp_cksum = icmp_in_cksum((unsigned short *) &icmpbuf, ICMP_PKT_LEN);
19
20 /* send data */
21 diff -Naur smap.orig/smap.c smap/smap.c
22 --- smap.orig/smap.c 2007-11-03 14:14:52.000000000 -0400
23 +++ smap/smap.c 2009-06-13 10:49:15.000000000 -0400
24 @@ -244,11 +244,11 @@
25 break;
26 case 't': /* TCP transport */
27 /* UDP is default so TCP would override it */
28 - config.flags ^= FLAG_UDP_TRANSPORT;
29 + config.flags &= ~FLAG_UDP_TRANSPORT;
30 config.flags |= FLAG_TCP_TRANSPORT;
31 break;
32 case 'u': /* UDP transport */
33 - config.flags ^= FLAG_TCP_TRANSPORT;
34 + config.flags &= ~FLAG_TCP_TRANSPORT;
35 config.flags |= FLAG_UDP_TRANSPORT;
36 break;
37 case 'r': /* ratelimit messages/sec */
38 diff -Naur smap.orig/transport_udp.c smap/transport_udp.c
39 --- smap.orig/transport_udp.c 2008-08-20 09:02:57.000000000 -0400
40 +++ smap/transport_udp.c 2009-06-13 11:56:15.000000000 -0400
41 @@ -52,6 +52,7 @@
42 extern int udp_sendsock;
43 extern struct sockaddr_in udp_sendsock_sockaddr;
44 int sockaddrlen;
45 + int one;
46
47 /* is 5060 (DEFAULT_SIP_PORT) available?
48 * if yes, we'll use it since some clients send responses to
49 @@ -116,6 +117,13 @@
50 error(ERR_DEBUG, "bind() successful");
51 }
52 }
53 + one = 1;
54 + if (setsockopt(udp_sendsock, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)) != 0) {
55 + perror("setsockopt");
56 + error(ERR_ERROR, "unable to set socket to broadcast");
57 + return 0;
58 + }
59 +
60 if (getsockname(udp_sendsock, (struct sockaddr *) &udp_sendsock_sockaddr,
61 (socklen_t *) &sockaddrlen) != 0)
62 if (DEBUG) perror("getsocknameudp_sendsock");