librnr/sock.c
char *SocketThisHostName()
{
  char             sHostName[HOST_NAME_MAX];
  char             sAddr[INET6_ADDRSTRLEN];
  struct hostent  *pHostEntry;
  char            *p;

  // get the host name of this processor
  if( gethostname(sHostName, sizeof(sHostName)) == -1 )
  {
    LOGSYSERROR("gethostname(...)");
    return new_strdup(SockStrUnknownHost);
  }
  sHostName[sizeof(sHostName)-1] = 0;

  // get this host entry info
  if( (pHostEntry = gethostbyname(sHostName)) == NULL )
  {
    LOGERROR("gethostbyname(%s): %s", sHostName, hstrerror(h_errno));
    return new_strdup(sHostName);
  }

  // dotted address to string
  if( pHostEntry->h_addr_list  && pHostEntry->h_addr_list[0] )
  {
    if( inet_ntop(pHostEntry->h_addrtype, pHostEntry->h_addr_list[0],
                  sAddr, (socklen_t)sizeof(sAddr)) == NULL )
    {
      LOGSYSERROR("inet_ntop(%d, ...)", pHostEntry->h_addrtype);
      strcpy(sAddr, "ADDR???");
    }
  }
  else
  {
    strcpy(sAddr, "ADDR???");
  }
  sAddr[sizeof(sAddr)-1] = 0;

  p = NEWSTR(strlen(sHostName)+strlen(sAddr)+2);
  sprintf(p, "%s(%s)", sHostName, sAddr);

  return p;
}
/*!
 * \brief Get the host string name of this network node (computer).
 *
 * \return Returns pointer to allocated name string.
 */
\brief Get the host string name of this network node (computer).
\return Returns pointer to allocated name string.
\ brief Get the host string name of this network node ( computer ) . \ return Returns pointer to allocated name string .
char *SocketThisHostName()
{
  char             sHostName[HOST_NAME_MAX];
  char             sAddr[INET6_ADDRSTRLEN];
  struct hostent  *pHostEntry;
  char            *p;
  if( gethostname(sHostName, sizeof(sHostName)) == -1 )
  {
    LOGSYSERROR("gethostname(...)");
    return new_strdup(SockStrUnknownHost);
  }
  sHostName[sizeof(sHostName)-1] = 0;
  if( (pHostEntry = gethostbyname(sHostName)) == NULL )
  {
    LOGERROR("gethostbyname(%s): %s", sHostName, hstrerror(h_errno));
    return new_strdup(sHostName);
  }
  if( pHostEntry->h_addr_list  && pHostEntry->h_addr_list[0] )
  {
    if( inet_ntop(pHostEntry->h_addrtype, pHostEntry->h_addr_list[0],
                  sAddr, (socklen_t)sizeof(sAddr)) == NULL )
    {
      LOGSYSERROR("inet_ntop(%d, ...)", pHostEntry->h_addrtype);
      strcpy(sAddr, "ADDR???");
    }
  }
  else
  {
    strcpy(sAddr, "ADDR???");
  }
  sAddr[sizeof(sAddr)-1] = 0;
  p = NEWSTR(strlen(sHostName)+strlen(sAddr)+2);
  sprintf(p, "%s(%s)", sHostName, sAddr);
  return p;
}
char * SocketThisHostName ( ) { char sHostName [ HOST_NAME_MAX ] ; char sAddr [ INET6_ADDRSTRLEN ] ; struct hostent * pHostEntry ; char * p ; if ( gethostname ( sHostName , sizeof ( sHostName ) ) == -1 ) { LOGSYSERROR ( " " ) ; return new_strdup ( SockStrUnknownHost ) ; } sHostName [ sizeof ( sHostName ) - 1 ] = 0 ; if ( ( pHostEntry = gethostbyname ( sHostName ) ) == NULL ) { LOGERROR ( " " , sHostName , hstrerror ( h_errno ) ) ; return new_strdup ( sHostName ) ; } if ( pHostEntry -> h_addr_list && pHostEntry -> h_addr_list [ 0 ] ) { if ( inet_ntop ( pHostEntry -> h_addrtype , pHostEntry -> h_addr_list [ 0 ] , sAddr , ( socklen_t ) sizeof ( sAddr ) ) == NULL ) { LOGSYSERROR ( " " , pHostEntry -> h_addrtype ) ; strcpy ( sAddr , " " ) ; } } else { strcpy ( sAddr , " " ) ; } sAddr [ sizeof ( sAddr ) - 1 ] = 0 ; p = NEWSTR ( strlen ( sHostName ) + strlen ( sAddr ) + 2 ) ; sprintf ( p , " " , sHostName , sAddr ) ; return p ; }
\brief Get the host string name of this network node (computer).
\ brief Get the host string name of this network node ( computer ) .
// get the host name of this processor // get this host entry info // dotted address to string