[Spread-users] bzero and bind() on FreeBSD

Joshua Goodall joshua at roughtrade.net
Sat Apr 6 09:21:50 EST 2002


This was interesting: whilst working on the updated FreeBSD port
for 3.16.2, I ran into some trouble when testing Spread_Segment
with the extra interface stanza (e.g.

Spread_Segment 10.1.2.255 {
        host1   10.1.2.1 {
                D 10.1.2.1
                C 127.0.0.1
        }
        host2   10.1.2.2 {
                D 10.1.2.2
                C 127.0.0.1
        }
}

... the OS refused to allow a UDP bind to 10.1.2.1!

Much head-scratching ensued. The problem eventually revealed itself
as a lack of bzero'ing the struct sockaddr_in, to which the syscall
was very sensitive (in particular, the sin_zero part).

The following patches fixed the problem. I have not tested them
on any other platform, but they fixed this oddity, and they're going
into the FreeBSD port of 3.16.2.

Joshua

--- data_link.c.orig	Sat Apr  6 22:45:23 2002
+++ data_link.c	Sat Apr  6 22:48:01 2002
@@ -93,6 +93,7 @@
 	{
         	soc_addr.sin_family    	= AF_INET;
         	soc_addr.sin_port	= htons(port);
+		bzero(&soc_addr.sin_zero, sizeof(soc_addr.sin_zero));
                 if (interface_address == 0)
                         soc_addr.sin_addr.s_addr= INADDR_ANY;
                 else 
--- session.c.orig	Sat Apr  6 22:47:26 2002
+++ session.c	Sat Apr  6 22:47:42 2002
@@ -347,6 +347,7 @@
 
 	/* Initiation of the INET socket */
 
+	bzero(&inet_addr.sin_zero, sizeof(inet_addr.sin_zero));
 	inet_addr.sin_family	= AF_INET;
 	inet_addr.sin_port	= htons(port);
         Accept_inet_mbox_num = 0;





More information about the Spread-users mailing list