| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

get_sock_addr

#include "sflsock.h"
int
get_sock_addr (
    sock_t handle,                      /*  Socket to get address for        */
    struct sockaddr_in *sin,            /*  Block for formatted address      */
    char *name,                         /*  Buffer for host name, or NULL    */
    int namesize                        /*  Size of host name buffer         */
)

Synopsis

Builds an address block (struct sockaddr_in) for the local end of the specified connected socket. Returns 0 if okay, SOCKET_ERROR if there was an error. If the name argument is not null, looks-up the host name and returns it. The name is truncated to namesize characters, including a trailing null character.

Source Code - (sflsock.c)

{
#if (defined (DOES_SOCKETS))
    int
        rc;                             /*  Return code from call            */
    struct hostent
        *phe;                           /*  Host information entry           */
    argsize_t
        sin_length;                     /*  Length of address                */

    ASSERT (sin);

    /*  Get address for local connected socket                               */
    sin_length = sizeof (struct sockaddr_in);

    rc = getsockname ((SOCKET) handle, (struct sockaddr *) sin, &sin_length);

    /*  Translate into host name string, only if wanted                      */
    if (name != NULL && rc == 0)
      {
        phe = gethostbyaddr ((char *) &sin-> sin_addr,
                             sizeof (sin-> sin_addr), AF_INET);
        if (phe)
          {
            strncpy (name, phe-> h_name, namesize);
            name [namesize - 1] = '\0';
          }
      }
#   if (defined (__WINDOWS__))
    return (win_error (rc));
#   else
    return (rc);
#   endif
#else
    return ((int) SOCKET_ERROR);        /*  Sockets not supported            */
#endif
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation