The following commit has been merged in the master branch: commit f6411418e54f257f0c7d4819f4f77a3fd6d633c1 Author: Stefan Sperling stsp@stsp.in-berlin.de Date: Thu Aug 31 00:41:04 2006 +0200
Use seperate send and recieve sockets.
diff --git a/posix.c b/posix.c index cc99f14..7f1bb16 100644 --- a/posix.c +++ b/posix.c @@ -396,11 +396,16 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); }
- batman_if->udp_recv_sock = socket(PF_INET, SOCK_DGRAM, 0); + batman_if->udp_send_sock = socket(PF_INET, SOCK_DGRAM, 0); + if (batman_if->udp_send_sock < 0) { + fprintf(stderr, "Cannot create send socket: %s", strerror(errno)); + exit(EXIT_FAILURE); + }
+ batman_if->udp_recv_sock = socket(PF_INET, SOCK_DGRAM, 0); if (batman_if->udp_recv_sock < 0) { - fprintf(stderr, "Cannot create socket: %s", strerror(errno)); + fprintf(stderr, "Cannot create recieve socket: %s", strerror(errno)); close_all_sockets(); exit(EXIT_FAILURE); } @@ -430,22 +435,27 @@ int main(int argc, char *argv[]) batman_if->broad.sin_port = htons(PORT); batman_if->broad.sin_addr.s_addr = ((struct sockaddr_in *)&int_req.ifr_broadaddr)->sin_addr.s_addr;
- if (setsockopt(batman_if->udp_recv_sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (int)) < 0) + if (setsockopt(batman_if->udp_send_sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (int)) < 0) { fprintf(stderr, "Cannot enable broadcasts: %s\n", strerror(errno)); close_all_sockets(); exit(EXIT_FAILURE); }
- if (bind(batman_if->udp_recv_sock, (struct sockaddr *)&batman_if->broad, sizeof (struct sockaddr_in)) < 0) + if (bind(batman_if->udp_send_sock, (struct sockaddr *)&batman_if->addr, sizeof (struct sockaddr_in)) < 0) { - fprintf(stderr, "Cannot bind socket: %s\n", strerror(errno)); + fprintf(stderr, "Cannot bind send socket: %s\n", strerror(errno)); close_all_sockets(); exit(EXIT_FAILURE); }
- batman_if->udp_send_sock = batman_if->udp_recv_sock; - + if (bind(batman_if->udp_recv_sock, (struct sockaddr *)&batman_if->broad, sizeof (struct sockaddr_in)) < 0) + { + fprintf(stderr, "Cannot bind receive socket: %s\n", strerror(errno)); + close_all_sockets(); + exit(EXIT_FAILURE); + } + addr_to_string(batman_if->addr.sin_addr.s_addr, str1, sizeof (str1)); addr_to_string(batman_if->broad.sin_addr.s_addr, str2, sizeof (str2));