Back to index

php5  5.3.10
Functions
inet.h File Reference
#include <Ws2tcpip.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PHPAPI int inet_pton (int af, const char *src, void *dst)
PHPAPI const char * inet_ntop (int af, const void *src, char *dst, size_t size)
PHPAPI int inet_aton (const char *cp, struct in_addr *inp)

Function Documentation

PHPAPI int inet_aton ( const char *  cp,
struct in_addr *  inp 
)

Definition at line 175 of file flock_compat.c.

{
    int dots = 0;
    register unsigned long acc = 0, addr = 0;

    do {
        register char cc = *cp;

        switch (cc) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            acc = acc * 10 + (cc - '0');
            break;

        case '.':
            if (++dots > 3) {
                return 0;
            }
            /* Fall through */

        case '\0':
            if (acc > 255) {
                return 0;
            }
            addr = addr << 8 | acc;
            acc = 0;
            break;

        default:
            return 0;
        }
    } while (*cp++) ;

    /* Normalize the address */
    if (dots < 3) {
        addr <<= 8 * (3 - dots) ;
    }

    /* Store it if requested */
    if (ap) {
        ap->s_addr = htonl(addr);
    }

    return 1;    
}

Here is the caller graph for this function:

PHPAPI const char* inet_ntop ( int  af,
const void *  src,
char *  dst,
size_t  size 
)

Definition at line 46 of file inet.c.

{
       int address_length;
       DWORD string_length = size;
       struct sockaddr_storage sa;
       struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
       struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;

       memset (&sa, 0, sizeof (sa));
       switch (af) {
              case AF_INET:
                     address_length = sizeof (struct sockaddr_in);
                     sin->sin_family = af;
                     memcpy (&sin->sin_addr, src, sizeof (struct in_addr));
                     break;

              case AF_INET6:
                     address_length = sizeof (struct sockaddr_in6);
                     sin6->sin6_family = af;
                     memcpy (&sin6->sin6_addr, src, sizeof (struct in6_addr));
                     break;

              default:
                     return NULL;
       }

       if (WSAAddressToString ((LPSOCKADDR) &sa, address_length, NULL, dst, &string_length) == 0) {
              return dst;
       }

       return NULL;
}

Here is the caller graph for this function:

PHPAPI int inet_pton ( int  af,
const char *  src,
void *  dst 
)

Definition at line 10 of file inet.c.

{
       int address_length;
       struct sockaddr_storage sa;
       struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
       struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;

       switch (af) {
              case AF_INET:
                     address_length = sizeof (struct sockaddr_in);
                     break;

              case AF_INET6:
                     address_length = sizeof (struct sockaddr_in6);
                     break;

              default:
                     return -1;
       }

       if (WSAStringToAddress ((LPTSTR) src, af, NULL, (LPSOCKADDR) &sa, &address_length) == 0) {
              switch (af) {
                     case AF_INET:
                            memcpy (dst, &sin->sin_addr, sizeof (struct in_addr));
                            break;

                     case AF_INET6:
                            memcpy (dst, &sin6->sin6_addr, sizeof (struct in6_addr));
                            break;
              }
              return 1;
       }

       return 0;
}

Here is the caller graph for this function: