Really odd pointer behavior

From: Mr. X (greenbaboon1_at_cox.net)
Date: 07/30/04


Date: Thu, 29 Jul 2004 18:44:55 -0700

Hello all,

Please advise...

Consider the following...

void init_sockaddr (struct sockaddr_in *name, const char *hostname,int port)
{
  struct hostent *hostinfo;
  name->sin_family = AF_INET;
  name->sin_port = htons (port);
  hostinfo = gethostbyname (hostname);

#if ONEWAY
  name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
#endif

#if ANOTHERWAY
    bcopy(hostinfo->h_addr, (char*)&(name->sin_addr), hostinfo->h_length);
#endif
}

As I understand, there will be problems with the first way.
Because once the CPU leaves the function, hostinfo might be lost.
For now, it works, but I imagine it might one day fail.

My bigger concern is why it even compiles?
What is the "*" to the left of the "(" in that line?
What is it doing?
Admittedly, it was a mistake that worked, but I am more interested
in



Relevant Pages

  • Re: Really odd pointer behavior
    ... > #if ONEWAY ... > #if ANOTHERWAY ... > Because once the CPU leaves the function, hostinfo might be lost. ... It's indirecting through the pointer. ...
    (comp.lang.c)
  • Re: Really odd pointer behavior
    ... > #if ANOTHERWAY ... > Because once the CPU leaves the function, hostinfo might be lost. ...
    (comp.lang.c)