Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!motcsd!mcdcup!mcdchg!tellab5!mtcchi!levy From: levy@mtcchi.uucp (2656-Daniel R. Levy(0000000)0000) Newsgroups: comp.protocols.tcp-ip Subject: Re: Comer/Shein whois server example won't work on Sparcstation Message-ID: <1990Dec21.184019.22326@mtcchi.uucp> Date: 21 Dec 90 18:40:19 GMT References: <1990Dec20.044937.21094@mtcchi.uucp> Distribution: na Organization: Memorex Telex Corporation NSBG/STP Lines: 47 I wrote >I tried to run the whois server example by Barry Shein in Douglas Comer's >_Internetworking_With_TCP/IP_ on a Sparcstation running SunOS 4.0.3... bind() >fails with EADDRNOTAVAIL even though the program was run with uid=euid=0. >(Killing inetd, guessing that it might somehow be interfering, did not help. >It did run fine on two SVR2 machines, an Amdahl and a 3B2. I do not have any >other 4BSD machines for testing.) Below is a listing of the program (with some >debug print statements thrown in) and then the output I get when running it on >the Sparcstation. Can anyone please assist... thanks much in advance. >main(argc,argv) >char **argv; >{ ... > struct sockaddr_in sa; > struct hostent *hp; > int s; ... > sa.sin_port = sp->s_port; > bcopy((char *)hp->h_addr,(char *)&sa.sin_addr,hp->h_length); > sa.sin_family = hp->h_addrtype; > > if ((s = socket(hp->h_addrtype,SOCK_STREAM,0)) < 0) { > perror("socket"); > exit(1); > } > > if (bind(s,&sa,sizeof sa) < 0) { > perror("bind"); > exit(1); > } ... >} A public thanks to Stuart Levy at the University of Minnesota, who pointed out the problem: a struct sockaddr_in has a char sin_zero[8] member which is supposed to be zeroed; but if a struct sockaddr_in variable is declared auto, this member is, of course, not guaranteed to be zeroed. Either declaring sa to be static or bzero()ing it fixes the problem. As an experienced C programmer, I feel kind of sheepish about not catching this sooner, though I could possibly be excused in that I was not yet familiar with the structures involved.... -- * Daniel R. Levy * uunet!tellab5!mtcchi!levy * | * These views are live; they are not Memorex' * --+-- Praise the Lord, Praise the Lord, let the earth hear His voice; | Praise the Lord, Praise the Lord, let the people rejoice. [F. Crosby] |