Subject: Re: garbage at sockaddr_in.sin_zero
To: Shin'ichiro TAYA <taya@sm.sony.co.jp>
From: None <jchacon@genuity.net>
List: current-users
Date: 10/22/2000 01:11:19
Your "in" var is an automatic variable. You can't depend on it being
zero'd out. So, garbage in, garbage out as far as the bind call goes.

bzero it first before setting values.

James

>
>Following program failes because there are garbages in in.sin_zero.
>Should I clear in.sin_zero? Is it documented somewhere?
>Or is it a bug of library or kernel?
>
>-taya
>
>#include	<stdio.h>
>#include	<sys/types.h>
>#include	<sys/socket.h>
>#include	<netinet/in.h>
>
>main()
>{
>	int	s;
>	struct sockaddr_in	in;
>
>	if((s = socket(PF_INET, SOCK_STREAM, 0)) < 0){
>		perror("socket");
>		exit(1);
>	}
>
>	in.sin_len = sizeof(in);
>	in.sin_family = AF_INET;
>	in.sin_port = 0;
>	in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
>
>	if(bind(s, (struct sockaddr *)&in, sizeof(in))){
>		perror("bind");
>		exit(1);
>	}
>}
>
>
>
>