summaryrefslogtreecommitdiff
path: root/pjlib/include/pj
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-11-18 14:53:47 +0000
committerBenny Prijono <bennylp@teluu.com>2007-11-18 14:53:47 +0000
commitfe61446fbe7fecfa0946812215e42396da6e0b9b (patch)
treec7e35c1578c50d7c8f97f4b27ff64787cd33932a /pjlib/include/pj
parent54f99f73d8f744c4558645906c99cbab480f5b8c (diff)
Ticket #415: implement IPv6 support in PJLIB
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1585 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include/pj')
-rw-r--r--pjlib/include/pj/addr_resolv.h31
-rw-r--r--pjlib/include/pj/compat/os_auto.h.in3
-rw-r--r--pjlib/include/pj/compat/socket.h39
-rw-r--r--pjlib/include/pj/config.h11
-rw-r--r--pjlib/include/pj/errno.h5
-rw-r--r--pjlib/include/pj/sock.h85
6 files changed, 158 insertions, 16 deletions
diff --git a/pjlib/include/pj/addr_resolv.h b/pjlib/include/pj/addr_resolv.h
index 39645cb6..e69abcf8 100644
--- a/pjlib/include/pj/addr_resolv.h
+++ b/pjlib/include/pj/addr_resolv.h
@@ -73,6 +73,16 @@ typedef struct pj_hostent
/** Shortcut to h_addr_list[0] */
#define h_addr h_addr_list[0]
+/**
+ * This structure describes address information pj_getaddrinfo().
+ */
+typedef struct pj_addrinfo
+{
+ char ai_canonname[PJ_MAX_HOSTNAME]; /**< Canonical name for host*/
+ pj_sockaddr ai_addr; /**< Binary address. */
+} pj_addrinfo;
+
+
/**
* This function fills the structure of type pj_hostent for a given host name.
*
@@ -95,6 +105,27 @@ PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr);
+/**
+ * This function translates the name of a service location (for example,
+ * a host name) and returns a set of addresses and associated information
+ * to be used in creating a socket with which to address the specified
+ * service.
+ *
+ * @param name Descriptive name or an address string, such as host
+ * name.
+ * @param af The desired address family to query.
+ * @param count On input, it specifies the number of elements in
+ * \a ai array. On output, this will be set with the
+ * number of address informations found for the
+ * specified name.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_getaddrinfo(const pj_str_t *nodename, int af,
+ unsigned *count, pj_addrinfo ai[]);
+
+
+
/** @} */
PJ_END_DECL
diff --git a/pjlib/include/pj/compat/os_auto.h.in b/pjlib/include/pj/compat/os_auto.h.in
index 58bf8690..336be7d5 100644
--- a/pjlib/include/pj/compat/os_auto.h.in
+++ b/pjlib/include/pj/compat/os_auto.h.in
@@ -72,6 +72,9 @@
#undef PJ_HAS_WINSOCK2_H
#undef PJ_SOCK_HAS_INET_ATON
+#undef PJ_SOCK_HAS_INET_PTON
+#undef PJ_SOCK_HAS_INET_NTOP
+#undef PJ_SOCK_HAS_GETADDRINFO
/* Set 1 if native sockaddr_in has sin_len member.
* Default: 0
diff --git a/pjlib/include/pj/compat/socket.h b/pjlib/include/pj/compat/socket.h
index 7cc0d654..f44a623c 100644
--- a/pjlib/include/pj/compat/socket.h
+++ b/pjlib/include/pj/compat/socket.h
@@ -32,6 +32,45 @@
# include <winsock.h>
#endif
+/*
+ * IPv6 for Visual Studio's
+ *
+ * = Visual Studio 6 =
+ *
+ * Visual Studio 6 does not ship with IPv6 support, so you MUST
+ * download and install IPv6 Tehnology Preview (IPv6Kit) from:
+ * http://msdn.microsoft.com/downloads/sdks/platform/tpipv6/ReadMe.asp
+ * Then put IPv6Kit\inc in your Visual Studio include path.
+ *
+ * In addition, by default IPv6Kit does not want to install on
+ * Windows 2000 SP4. Please see:
+ * http://msdn.microsoft.com/downloads/sdks/platform/tpipv6/faq.asp
+ * on how to install IPv6Kit on Win2K SP4.
+ *
+ *
+ * = Visual Studio 2003, 2005 (including Express) =
+ *
+ * These VS uses Microsoft Platform SDK for Windows Server 2003 SP1, and
+ * it has built-in IPv6 support.
+ */
+#if defined(_MSC_VER) && defined(PJ_HAS_IPV6) && PJ_HAS_IPV6!=0
+# ifndef s_addr
+# define s_addr S_un.S_addr
+# endif
+
+# include <ws2tcpip.h>
+
+# ifndef IPPROTO_IPV6
+ /* Need to download and install IPv6Kit for this platform.
+ * Please see the comments above about Visual Studio 6.
+ */
+# include <tpipv6.h>
+# endif
+
+# undef s_addr
+#endif /* _MSC_VER */
+
+
#if defined(PJ_HAS_SYS_TYPES_H) && PJ_HAS_SYS_TYPES_H != 0
# include <sys/types.h>
#endif
diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h
index 2f05c0f7..b1287101 100644
--- a/pjlib/include/pj/config.h
+++ b/pjlib/include/pj/config.h
@@ -449,6 +449,17 @@
#endif
/**
+ * \def PJ_HAS_IPV6
+ * Support IPv6 in the library. If this support is disabled, some IPv6
+ * related functions will return PJ_EIPV6NOTSUP.
+ *
+ * Default: 0 (disabled, for now)
+ */
+#ifndef PJ_HAS_IPV6
+# define PJ_HAS_IPV6 0
+#endif
+
+ /**
* Maximum hostname length.
* Libraries sometimes needs to make copy of an address to stack buffer;
* the value here affects the stack usage.
diff --git a/pjlib/include/pj/errno.h b/pjlib/include/pj/errno.h
index 10b15fe5..507bd7b8 100644
--- a/pjlib/include/pj/errno.h
+++ b/pjlib/include/pj/errno.h
@@ -309,6 +309,11 @@ PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code,
* Ignored
*/
#define PJ_EIGNORED (PJ_ERRNO_START_STATUS + 20)/* 70020 */
+/**
+ * @hideinitializer
+ * IPv6 is not supported
+ */
+#define PJ_EIPV6NOTSUP (PJ_ERRNO_START_STATUS + 21)/* 70021 */
/** @} */ /* pj_errnum */
diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h
index 12b771c9..d90c91e8 100644
--- a/pjlib/include/pj/sock.h
+++ b/pjlib/include/pj/sock.h
@@ -60,6 +60,9 @@ PJ_BEGIN_DECL
* THE LIBRARY WILL DO TRANSLATION TO THE NATIVE VALUE.
*/
+/** Address family is unspecified. @see pj_AF_UNSPEC() */
+extern const pj_uint16_t PJ_AF_UNSPEC;
+
/** Unix domain socket. @see pj_AF_UNIX() */
extern const pj_uint16_t PJ_AF_UNIX;
@@ -84,6 +87,8 @@ extern const pj_uint16_t PJ_AF_IRDA;
* global variables from a DLL.
*/
+/** Get #PJ_AF_UNSPEC value */
+PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void);
/** Get #PJ_AF_UNIX value. */
PJ_DECL(pj_uint16_t) pj_AF_UNIX(void);
/** Get #PJ_AF_INET value. */
@@ -313,6 +318,17 @@ typedef struct pj_in_addr
/**
+ * Maximum length of text representation of an IPv4 address.
+ */
+#define PJ_INET_ADDRSTRLEN 16
+
+/**
+ * Maximum length of text representation of an IPv6 address.
+ */
+#define PJ_INET6_ADDRSTRLEN 46
+
+
+/**
* This structure describes Internet socket address.
* If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added
* to this struct. As far the application is concerned, the value of
@@ -333,27 +349,26 @@ struct pj_sockaddr_in
char sin_zero[8]; /**< Padding. */
};
+
#undef s6_addr
/**
* This structure describes IPv6 address.
*/
-typedef struct pj_in6_addr
+typedef union pj_in6_addr
{
- /** Union of address formats. */
- union {
- pj_uint8_t u6_addr8[16]; /**< u6_addr8 */
- pj_uint16_t u6_addr16[8]; /**< u6_addr16 */
- pj_uint32_t u6_addr32[4]; /**< u6_addr32 */
- } in6_u;
-/** Shortcut to access in6_u.u6_addr8. */
-#define s6_addr in6_u.u6_addr8
-/** Shortcut to access in6_u.u6_addr16. */
-#define s6_addr16 in6_u.u6_addr16
-/** Shortcut to access in6_u.u6_addr32. */
-#define s6_addr32 in6_u.u6_addr32
+ /* This is the main entry */
+ pj_uint8_t s6_addr[16]; /**< 8-bit array */
+
+ /* While these are used for proper alignment */
+ pj_uint32_t u6_addr32[4];
+#if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0
+ pj_int64_t u6_addr64[2];
+#endif
+
} pj_in6_addr;
+
/** Initializer value for pj_in6_addr. */
#define PJ_IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
@@ -371,15 +386,15 @@ typedef struct pj_in6_addr
typedef struct pj_sockaddr_in6
{
#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
- pj_uint8_t sin_zero_len; /**< Just ignore this. */
- pj_uint8_t sin_family; /**< Address family. */
+ pj_uint8_t sin6_zero_len; /**< Just ignore this. */
+ pj_uint8_t sin6_family; /**< Address family. */
#else
pj_uint16_t sin6_family; /**< Address family */
#endif
pj_uint16_t sin6_port; /**< Transport layer port number. */
pj_uint32_t sin6_flowinfo; /**< IPv6 flow information */
pj_in6_addr sin6_addr; /**< IPv6 address. */
- pj_uint32_t sin6_scope_id; /**< IPv6 scope-id */
+ pj_uint32_t sin6_scope_id; /**< Set of interfaces for a scope */
} pj_sockaddr_in6;
@@ -474,6 +489,44 @@ PJ_DECL(char*) pj_inet_ntoa(pj_in_addr inaddr);
PJ_DECL(int) pj_inet_aton(const pj_str_t *cp, struct pj_in_addr *inp);
/**
+ * This function converts an address in its standard text presentation form
+ * into its numeric binary form. It supports both IPv4 and IPv6 address
+ * conversion.
+ *
+ * @param af Specify the family of the address. The PJ_AF_INET and
+ * PJ_AF_INET6 address families shall be supported.
+ * @param src Points to the string being passed in.
+ * @param dst Points to a buffer into which the function stores the
+ * numeric address; this shall be large enough to hold the
+ * numeric address (32 bits for PJ_AF_INET, 128 bits for
+ * PJ_AF_INET6).
+ *
+ * @return PJ_SUCCESS if conversion was successful.
+ */
+PJ_DECL(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst);
+
+/**
+ * This function converts a numeric address into a text string suitable
+ * for presentation. It supports both IPv4 and IPv6 address
+ * conversion.
+ *
+ * @param af Specify the family of the address. This can be PJ_AF_INET
+ * or PJ_AF_INET6.
+ * @param src Points to a buffer holding an IPv4 address if the af argument
+ * is PJ_AF_INET, or an IPv6 address if the af argument is
+ * PJ_AF_INET6; the address must be in network byte order.
+ * @param dst Points to a buffer where the function stores the resulting
+ * text string; it shall not be NULL.
+ * @param size Specifies the size of this buffer, which shall be large
+ * enough to hold the text string (PJ_INET_ADDRSTRLEN characters
+ * for IPv4, PJ_INET6_ADDRSTRLEN characters for IPv6).
+ *
+ * @return PJ_SUCCESS if conversion was successful..
+ */
+PJ_DECL(pj_status_t) pj_inet_ntop(int af, const void *src,
+ char *dst, int size);
+
+/**
* Convert address string with numbers and dots to binary IP address.
*
* @param cp The IP address in numbers and dots notation.