Index: INSTALL.Fedora
===================================================================
--- INSTALL.Fedora	(revision 861)
+++ INSTALL.Fedora	(revision 1561)
@@ -4,5 +4,5 @@
 
 Dependencies on Fedora 13 (from minimal system):
-# yum install cmake make gcc gcc-c++ flex bison lksctp-tools-devel gnutls-devel libgcrypt-devel libidn-devel
+# yum install cmake make gcc gcc-c++ flex bison lksctp-tools-devel gnutls-devel libgcrypt-devel libidn2-devel
 
 In addition, if you have not already retrieved the latest source:
Index: INSTALL.FreeBSD
===================================================================
--- INSTALL.FreeBSD	(revision 921)
+++ INSTALL.FreeBSD	(revision 1561)
@@ -35,5 +35,5 @@
 4) Install 'flex' and 'bison', same way.
 
-5) Install 'gnutls' and 'libidn', same way also.
+5) Install 'gnutls' and 'libidn2', same way also.
 
 6) Retrieve freeDiameter source code:
Index: INSTALL.OSX
===================================================================
--- INSTALL.OSX	(revision 1288)
+++ INSTALL.OSX	(revision 1561)
@@ -40,8 +40,8 @@
 
 2) Install dependencies:
-    $ brew install mercurial cmake gnutls libgcrypt postgres mysql libidn
+    $ brew install mercurial cmake gnutls libgcrypt postgres mysql libidn2
 
    Notes:
-    * GNU IDN (libidn) is optional, see below
+    * GNU IDN (libidn2) is optional, see below
     * When libusrsctp package is available, you can use it as well.
         However, it requires some rework on the source code as libusrsctp is not fully
Index: INSTALL.OpenSUSE
===================================================================
--- INSTALL.OpenSUSE	(revision 858)
+++ INSTALL.OpenSUSE	(revision 1561)
@@ -4,5 +4,5 @@
 
 Dependencies on OpenSUSE 11.3 (from minimal server system installation):
-# zypper install cmake make gcc gcc-c++ flex bison lksctp-tools-devel libgnutls-devel libgcrypt-devel libidn-devel
+# zypper install cmake make gcc gcc-c++ flex bison lksctp-tools-devel libgnutls-devel libgcrypt-devel libidn2-devel
 # zypper install mercurial
 
Index: INSTALL.Ubuntu
===================================================================
--- INSTALL.Ubuntu	(revision 1351)
+++ INSTALL.Ubuntu	(revision 1561)
@@ -18,7 +18,7 @@
 
 The following packages are required to compile freeDiameter from source:
- cmake make gcc g++ flex bison libsctp1 libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev
+ cmake make gcc g++ flex bison libsctp1 libsctp-dev libgnutls-dev libgcrypt-dev libidn2-dev
  
-(note that libidn and libsctp can be avoided by defining DISABLE_SCTP and DIAMID_IDNA_REJECT)
+(note that libidn2 and libsctp can be avoided by defining DISABLE_SCTP and DIAMID_IDNA_REJECT)
  
 Additionnaly, these ones may be useful:
@@ -45,5 +45,5 @@
 
 # Install the dependencies for building the source:
-sudo apt-get -y install mercurial cmake make gcc g++ bison flex libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev ssl-cert debhelper fakeroot \
+sudo apt-get -y install mercurial cmake make gcc g++ bison flex libsctp-dev libgnutls-dev libgcrypt-dev libidn2-dev ssl-cert debhelper fakeroot \
    libpq-dev libmysqlclient-dev libxml2-dev swig python-dev
    
@@ -85,5 +85,5 @@
 
 1) Install all packages dependencies
-# sudo apt-get install mercurial cmake make gcc g++ bison flex libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev
+# sudo apt-get install mercurial cmake make gcc g++ bison flex libsctp-dev libgnutls-dev libgcrypt-dev libidn2-dev
 
 2) (OPTION) If you will compile modules that require postgresql, also install:
Index: INSTALL.pkgsrc
===================================================================
--- INSTALL.pkgsrc	(revision 1334)
+++ INSTALL.pkgsrc	(revision 1561)
@@ -9,5 +9,5 @@
 If you want to build and install freeDiameter from the repository,
 you'll need to install:
-	pkg_add bison pkg-config libidn gnutls libgcrypt mercurial
+	pkg_add bison pkg-config libidn2 gnutls libgcrypt mercurial
 and follow the usual installation note.
 
Index: ake/Modules/FindIDNA.cmake
===================================================================
--- cmake/Modules/FindIDNA.cmake	(revision 707)
+++ 	(revision )
@@ -1,40 +1,0 @@
-# - Try to find GNU IDN library and headers
-# Once done, this will define
-#
-#  IDNA_FOUND - system has IDNA
-#  IDNA_INCLUDE_DIR - the IDNA include directories (<idna.h>)
-#  IDNA_LIBRARIES - link these to use IDNA (idna_to_ascii_8z)
-
-if (IDNA_INCLUDE_DIR AND IDNA_LIBRARIES)
-  set(IDNA_FIND_QUIETLY TRUE)
-endif (IDNA_INCLUDE_DIR AND IDNA_LIBRARIES)
-
-# Include dir
-find_path(IDNA_INCLUDE_DIR
-  NAMES idna.h
-)
-
-# Library
-find_library(IDNA_LIBRARY
-  NAMES idn
-)
-
-
-# handle the QUIETLY and REQUIRED arguments and set IDNA_FOUND to TRUE if
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(IDNA DEFAULT_MSG IDNA_LIBRARY IDNA_INCLUDE_DIR)
-
-# If we successfully found the idn library then add the library to the
-# IDNA_LIBRARIES cmake variable otherwise set IDNA_LIBRARIES to nothing.
-IF(IDNA_FOUND)
-   SET( IDNA_LIBRARIES ${IDNA_LIBRARY} )
-ELSE(IDNA_FOUND)
-   SET( IDNA_LIBRARIES )
-ENDIF(IDNA_FOUND)
-
-
-# Lastly make it so that the IDNA_LIBRARY and IDNA_INCLUDE_DIR variables
-# only show up under the advanced options in the gui cmake applications.
-MARK_AS_ADVANCED( IDNA_LIBRARY IDNA_INCLUDE_DIR )
-
Index: contrib/RPM/freeDiameter.spec
===================================================================
--- contrib/RPM/freeDiameter.spec	(revision 1224)
+++ contrib/RPM/freeDiameter.spec	(revision 1561)
@@ -11,5 +11,5 @@
 
 BuildRequires: cmake make gcc gcc-c++ flex bison lksctp-tools-devel 
-BuildRequires: gnutls-devel libgcrypt-devel libidn-devel
+BuildRequires: gnutls-devel libgcrypt-devel libidn2-devel
 BuildRequires: mercurial	
 Requires: lksctp-tools	
Index: contrib/debian/control
===================================================================
--- contrib/debian/control	(revision 1310)
+++ contrib/debian/control	(revision 1561)
@@ -5,5 +5,5 @@
 Build-Depends: debhelper ( >= 7.3.9),
  cmake, make, gcc, g++, bison, flex,
- libsctp-dev, libgnutls-dev | gnutls-dev, libidn11-dev,
+ libsctp-dev, libgnutls-dev | gnutls-dev, libidn2-dev,
  libpq-dev, libmysqlclient-dev, libxml2-dev, swig, python-dev,
  libgcrypt11-dev | libgcrypt20-dev
Index: contrib/nightly_tests/prereqs.fedora
===================================================================
--- contrib/nightly_tests/prereqs.fedora	(revision 1053)
+++ contrib/nightly_tests/prereqs.fedora	(revision 1561)
@@ -4,5 +4,5 @@
 postgresql-server postgresql-devel
 mysql-server mysql-devel
-libxml2 libxml2-devel libidn-devel
+libxml2 libxml2-devel libidn2-devel
 swig python-devel
 
Index: include/freeDiameter/CMakeLists.txt
===================================================================
--- include/freeDiameter/CMakeLists.txt	(revision 1406)
+++ include/freeDiameter/CMakeLists.txt	(revision 1561)
@@ -2,4 +2,6 @@
 
 Project("freeDiameter includes directory" C)
+
+INCLUDE(FindPkgConfig)
 
 ########################
@@ -136,24 +138,13 @@
 SET(SCTP_LIBRARIES ${SCTP_LIBRARIES} PARENT_SCOPE)
 
-# IDNA process: we use libidn from GNU (unless the function & header files are included in libc)
+# IDNA process: we use GNU libidn2
 IF(NOT DIAMID_IDNA_IGNORE AND NOT DIAMID_IDNA_REJECT)
-	FIND_PACKAGE(IDNA)
-   	SET(CHECK_IDNA_SOURCE_CODE "
-		#include <idna.h>
-		int main() {
-		   return idna_to_ascii_8z(NULL, NULL, 0);
-		}
-		")
-	SET(CMAKE_REQUIRED_INCLUDES ${IDNA_INCLUDE_DIR})
-	SET(CMAKE_REQUIRED_LIBRARIES ${IDNA_LIBRARIES})
-	CHECK_C_SOURCE_COMPILES("${CHECK_IDNA_SOURCE_CODE}" HAS_IDNA_SUPPORT)
-	IF(NOT HAS_IDNA_SUPPORT)
-		MESSAGE(SEND_ERROR "Unable to find idna.h header or idna_to_ascii_8z function, please install libidn-dev or equivalent, or set DIAMID_IDNA_IGNORE or DIAMID_IDNA_REJECT")
-	ENDIF(NOT HAS_IDNA_SUPPORT)
+	PKG_CHECK_MODULES(IDNA libidn2)
+	IF(NOT IDNA_FOUND)
+		MESSAGE(SEND_ERROR "Unable to find libidn2, please install libidn2-dev or equivalent, or set DIAMID_IDNA_IGNORE or DIAMID_IDNA_REJECT")
+	ENDIF()
 ELSE (NOT DIAMID_IDNA_IGNORE  AND NOT DIAMID_IDNA_REJECT)
 	MESSAGE(STATUS "Non-default Internationalized Domain Names (IDN) behavior selected (no stringprep).")
 ENDIF(NOT DIAMID_IDNA_IGNORE  AND NOT DIAMID_IDNA_REJECT)
-SET(IDNA_INCLUDE_DIR ${IDNA_INCLUDE_DIR} PARENT_SCOPE)
-SET(IDNA_LIBRARIES ${IDNA_LIBRARIES} PARENT_SCOPE)
 
 
@@ -221,7 +212,7 @@
 
 # LFDPROTO_LIBS = libraries required by the libfdproto.
-SET(LFDPROTO_LIBS ${CLOCK_GETTIME_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${IDNA_LIBRARIES} PARENT_SCOPE)
+SET(LFDPROTO_LIBS ${CLOCK_GETTIME_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${IDNA_LINK_LIBRARIES} PARENT_SCOPE)
 # And includes paths
-SET(LFDPROTO_INCLUDES ${IDNA_INCLUDE_DIR} PARENT_SCOPE)
+SET(LFDPROTO_INCLUDES ${IDNA_INCLUDE_DIRS} PARENT_SCOPE)
 # Dependencies: the libraries required by any code linking to libfdproto.
 SET(LFDPROTO_LINK_INTERFACES ${CMAKE_THREAD_LIBS_INIT} PARENT_SCOPE)
Index: libfdproto/CMakeLists.txt
===================================================================
--- libfdproto/CMakeLists.txt	(revision 1560)
+++ libfdproto/CMakeLists.txt	(revision 1561)
@@ -28,9 +28,9 @@
 SET(LFDPROTO_SRC ${LFDPROTO_SRC} PARENT_SCOPE)
 
-# Include path
-INCLUDE_DIRECTORIES(${LFDPROTO_INCLUDES})
-
 # Build as a shared library
 ADD_LIBRARY(libfdproto SHARED ${LFDPROTO_SRC})
+
+# Include path
+TARGET_INCLUDE_DIRECTORIES(libfdproto PRIVATE /a/b/c ${LFDPROTO_INCLUDES})
 
 ADD_DEPENDENCIES(libfdproto version_information)
Index: libfdproto/ostr.c
===================================================================
--- libfdproto/ostr.c	(revision 1127)
+++ libfdproto/ostr.c	(revision 1561)
@@ -37,6 +37,6 @@
 
 #if (!defined(DIAMID_IDNA_IGNORE) && !defined(DIAMID_IDNA_REJECT))
-/* Process IDNA with stringprep -- See RFC5890 -- and libidn documentation... */
-#include <idna.h> /* idna_to_ascii_8z() */
+/* Process IDNA with stringprep -- See RFC5890 -- and libidn2 documentation... */
+#include <idn2.h> /* idn2_to_ascii_8z() */
 #endif /* !defined(DIAMID_IDNA_IGNORE) && !defined(DIAMID_IDNA_REJECT) */
 
@@ -227,6 +227,6 @@
 		}
 		
-		ret = idna_to_ascii_8z ( *id, &processed, IDNA_USE_STD3_ASCII_RULES );
-		if (ret == IDNA_SUCCESS) {
+		ret = idn2_to_ascii_8z ( *id, &processed, IDNA_USE_STD3_ASCII_RULES );
+		if (ret == IDN2_OK) {
 			TRACE_DEBUG(INFO, "The string '%s' is not a valid DiameterIdentity, it was changed to '%s'", *id, processed);
 			if (memory == 0)
@@ -236,5 +236,5 @@
 			/* Done! */
 		} else {
-			TRACE_DEBUG(INFO, "The string '%s' is not a valid DiameterIdentity and cannot be sanitanized: %s", *id, idna_strerror (ret));
+			TRACE_DEBUG(INFO, "The string '%s' is not a valid DiameterIdentity and cannot be sanitized: %s", *id, idn2_strerror (ret));
 			return EINVAL;
 		}
