Subject: Re: garbage at sockaddr_in.sin_zero
To: None <current-users@netbsd.org>
From: Geoff Wing <mason@primenet.com.au>
List: current-users
Date: 10/22/2000 04:57:51
Shin'ichiro TAYA <taya@sm.sony.co.jp> typed:
:Following program failes because there are garbages in in.sin_zero.
:Should I clear in.sin_zero? Is it documented somewhere?
Just remember to clear the struct (see memset() below) before using
it (or manually set all the members). I thought it was mentioned
in some manual page but can't find it at the moment.
:Or is it a bug of library or kernel?
It's existed on NetBSD this way for a few years - don't know about
other OS's.
Regards,
Geoff
:#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);
: }
memset(&in, 0, sizeof(in));
: 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);
: }
:}