ext/iodine/fio.c
/**
 * Writes the local machine address (qualified host name) to the buffer.
 *
 * Returns the amount of data written (excluding the NUL byte).
 *
 * `limit` is the maximum number of bytes in the buffer, including the NUL byte.
 *
 * If the returned value == limit - 1, the result might have been truncated.
 *
 * If 0 is returned, an erro might have occured (see `errno`) and the contents
 * of `dest` is undefined.
 */
Writes the local machine address (qualified host name) to the buffer.
Returns the amount of data written (excluding the NUL byte).

`limit` is the maximum number of bytes in the buffer, including the NUL byte.

If the returned value == limit - 1, the result might have been truncated.

If 0 is returned, an erro might have occured  and the contents
of `dest` is undefined.
Writes the local machine address ( qualified host name ) to the buffer . Returns the amount of data written ( excluding the NUL byte ) . ` limit ` is the maximum number of bytes in the buffer including the NUL byte . If the returned value == limit - 1 the result might have been truncated . If 0 is returned an erro might have occured and the contents of ` dest ` is undefined .
size_t fio_local_addr(char *dest, size_t limit) {
  if (gethostname(dest, limit))
    return 0;
  struct addrinfo hints, *info;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;     
  hints.ai_socktype = SOCK_STREAM; 
  hints.ai_flags = AI_CANONNAME;   
  if (getaddrinfo(dest, "http", &hints, &info) != 0)
    return 0;
  for (struct addrinfo *pos = info; pos; pos = pos->ai_next) {
    if (pos->ai_canonname) {
      size_t len = strlen(pos->ai_canonname);
      if (len >= limit)
        len = limit - 1;
      memcpy(dest, pos->ai_canonname, len);
      dest[len] = 0;
      freeaddrinfo(info);
      return len;
    }
  }
  freeaddrinfo(info);
  return 0;
}
size_t fio_local_addr ( char * dest , size_t limit ) { if ( gethostname ( dest , limit ) ) return 0 ; struct addrinfo hints , * info ; memset ( & hints , 0 , sizeof hints ) ; hints . ai_family = AF_UNSPEC ; hints . ai_socktype = SOCK_STREAM ; hints . ai_flags = AI_CANONNAME ; if ( getaddrinfo ( dest , " " , & hints , & info ) != 0 ) return 0 ; for ( struct addrinfo * pos = info ; pos ; pos = pos -> ai_next ) { if ( pos -> ai_canonname ) { size_t len = strlen ( pos -> ai_canonname ) ; if ( len >= limit ) len = limit - 1 ; memcpy ( dest , pos -> ai_canonname , len ) ; dest [ len ] = 0 ; freeaddrinfo ( info ) ; return len ; } } freeaddrinfo ( info ) ; return 0 ; }
Writes the local machine address (qualified host name) to the buffer.
Writes the local machine address ( qualified host name ) to the buffer .
// don't care IPv4 or IPv6 // TCP stream sockets // get cannonical name