From owner-freebsd-chat Fri Nov 2 10:56:15 2001 Delivered-To: freebsd-chat@freebsd.org Received: from mail11.speakeasy.net (mail11.speakeasy.net [216.254.0.211]) by hub.freebsd.org (Postfix) with ESMTP id 8145037B401 for ; Fri, 2 Nov 2001 10:56:12 -0800 (PST) Received: (qmail 29580 invoked from network); 2 Nov 2001 18:56:11 -0000 Received: from unknown (HELO laptop.baldwin.cx) ([64.81.54.73]) (envelope-sender ) by mail11.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 2 Nov 2001 18:56:11 -0000 Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20011102161519.40762.qmail@web11504.mail.yahoo.com> Date: Fri, 02 Nov 2001 10:56:11 -0800 (PST) From: John Baldwin To: Fabio Miranda Subject: RE: struct hostent Cc: freebsd-chat@FreeBSD.org Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On 02-Nov-01 Fabio Miranda wrote: > Hi, i am coding a small c program in order to learn > network programming: > main(int argc, char *argv[]){ > struct hostent *host; > .... > if((host=gethostbyname(argv[1])=NULL)){ > perror("gethostbyname"); > exit(-1);} This should be: if ((host = gethostbyname(argv[1])) == NULL) { Note the "==" check for NULL. You are assigning NULL to host effectively, causing your core dump. I would also persoally recommand a slightly different style, but that is a matter of personal opinion I suppose. > /* now, i want to print out all the hostent struct > information */ > printf("struct hostent{\n"); > printf("char *h_name: %s", host->h_name); > printf("char **h_aliases:%s\n", host->h_length); > printf("int h_addrtype: %d\n", host->h_addrtype); > printf("int h_length: %d\n", host->h_length); > printf("char **h_addr_list: %d\n", > host->h_addr_list); > } > } > This program core dumped, it may crash because i am > trying to print an char array (h_addr_list, right?), I > want to know how can i print all the information store > in a struct hostent?, especiality the ip address. > > thanks > > > __________________________________________________ > Do You Yahoo!? > Find a job, post your resume. > http://careers.yahoo.com > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-chat" in the body of the message -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message