linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Woods <Kazrak+kernel@cesmail.net>
To: Edward Parrilla <eparrilla@comcast.net>
Cc: linux prg <linux-c-programming@vger.kernel.org>
Subject: Re: passing host name from a structure.
Date: Wed, 06 Oct 2004 23:03:35 -0600	[thread overview]
Message-ID: <6.1.1.1.0.20041006171515.04d4c6b8@no.incoming.mail> (raw)
In-Reply-To: <1097099245.4086.421.camel@localhost.localdomain>

At 10/6/2004 04:47 PM -0500, Edward Parrilla wrote:
>#define bcopy(a,b,c) strncpy(b,a,c)
>
>    struct sockaddr_in  sa;  /* socket addr. structure           */
>    struct hostent * hp;     /* host entry                       */
>    char *hostname;
>
>hostname=argv[3];
>
>hp=gethostbyname(hostname);  <-- get this error " warning: assignment 
>makes pointer from integer without a cast"

This error looks really peculiar.  IIUC, it's complaining that 
gethostbyname() returns an int (or other ordinal value) which must be 
converted to a pointer for assignment to "hp".  However, on my system "man 
gethostbyname" says "struct hostent *gethostbyname(const char *name);" 
which says it should be returning a pointer (even one of the same type as 
you declared "hp").  Have you declared a prototype for gethostbyname()?  If 
not, then the compiler assumes the function returns an int.  The same man 
page indicates you should include this line in your source:  "#include 
<netdb.h>".  Just to be sure, check "man gethostbyname" on your system and 
see what include files it recommends and what type gethostbyname() 
returns.  If you've confirmed that's not the problem, then you might dig 
into the include file(s), find the prototype being used for gethostbyname() 
and see that it's correct; but that's very unlikely to be the 
problem.  (Someone else would have seen it a long time ago.)

>bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length);  <-- 
>getting  dereferencing pointer to incomplete type

The problem is the precedence of "(char *)hp->h_addr".  The cast "()" and 
indirection "->" operators have equal precedence level and so left-to-right 
order determines precedence, which means you told the compile to access the 
h_addr struct field of what you just told it is a char.  I think you mean 
"(char *)(hp->h_addr)".  Note also that some groups of operators at the 
same precedence level operate left to right [e.g., arithmetic: (a + b - c)] 
and others operate right to left [e.g., assignments: (a *= b +=2)].

--
Jeff Woods <kazrak+kernel@cesmail.net> 



  parent reply	other threads:[~2004-10-07  5:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-06 10:44 C language(asm construct) Ankit Jain
2004-10-06 21:47 ` passing host name from a structure Edward Parrilla
2004-10-06 22:44   ` Alphex Kaanoken
2004-10-07  2:02     ` Edward Parrilla
2004-10-07  5:03   ` Jeff Woods [this message]
2004-10-07  6:23     ` Edward Parrilla
2004-10-07  6:34     ` mapping client to port Edward Parrilla
2004-10-08 15:02 ` C language(asm construct) Suciu Flavius

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6.1.1.1.0.20041006171515.04d4c6b8@no.incoming.mail \
    --to=kazrak+kernel@cesmail.net \
    --cc=eparrilla@comcast.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).