Maybe I am missing something....but why doesn't this work?

Roland Dirlewanger rd at zildjian.chorus.fr
Thu May 30 18:26:20 AEST 1991


In article <1991May29.145535.23801 at bradley.bradley.edu>
brad at bradley.bradley.edu (Bradley E. Smith) writes:

%% I am not sure why but the following program has problems.....
%% 
%% HARDWARE USED:
%% 
%% SUN 470 SunOS 4.1.1		- NO
%% SUN SLC SunOS 4.1.1		- NO
%% IBM RT BSD OS			- YES
%% AT&T 3B2 WIN TCP 3.2		- YES
%% AT&T 386 WIN TCP 3.0		- YES
%% 
%% What happens:  As the program is listed below (make sure you change
%% the host name if you are going to try it), 'bind(2)' fails on the
%% suns with EADDRNOTAVAIL.  The other machines work just fine.
%% 
%% If I change/remove the x(), and the '{' '}' so that the whole
%% program is in 1 function (ie I just delete a few lines everything
%% is in main()).  It works just fine.
%% 
%% [Source program deleted]

Implementations based on the BSD TCP/IP distribution (such as SunOS)
check that the last eight bytes (the sin_zero field) of a sockaddr_in
are set to 0. If not, they complain.

What happens, is that your "struct sockaddr_in backupserver" is
allocated in the stack, thus initialized to random data. In main(),
it happens to be initialized to 0, in x() it's not.

To fix your problem, you may either:

      - declare "struct sockaddr_in backupserver" to be a static
	variable (thus garantied to be zeroed):

	x () {
		...
		static struct sockaddr_in backupserver;
		...
	}

      - insert somewhere before the bind() the following line:

	bzero (backupserver.sin_zero, sizeof backupserver.sin_zero);

Hope this helped.

--
Roland Dirlewanger				E-mail:	rd at chorus.fr
Chorus systemes					Phone:	+33 1 30 64 82 85
6, Avenue Gustave Eiffel			Fax:	+33 1 30 57 00 66
F-78182 St Quentin en Yvelines Cedex



More information about the Comp.unix.wizards mailing list