Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master:
  Fix includes for iOS
  Include syslog.h on Android
  Fix #include path for wintime.h
  build: Fix for MinGW support
  srt_compat.h: Enable localtime_s only if MSC_VER >= 1500
  Clean .pc to provide the dependecies
  configure-data.tcl: Fix crypto backend check condition
  build: support cross-compiling by mingw
  srtcore/api.h: change inet_ntop to getnameinfo
  common/srt_compat.h: add time.h to suppress compilation warnings
  channel.cpp: add mswsock.h for Win32
  Bump up SRT_VERSION to 1.2.2
  Update ttl option description in stransmit.md
  Changed ipttl to ttl to be resolved as IP_TTL or IP_MULTICAST_TTL (Haivision#164)
  • Loading branch information
Adam Yellen committed Jan 9, 2018
2 parents da06e0a + 3f73759 commit df8e553
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 31 deletions.
33 changes: 24 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
include(haiUtil)
include(FindPkgConfig)

set (SRT_VERSION 1.2.0)
set (SRT_VERSION 1.2.2)
set_version_variables(SRT_VERSION ${SRT_VERSION})

if (NOT DEFINED ENABLE_DEBUG)
Expand Down Expand Up @@ -89,7 +89,14 @@ set_if(LINUX ${CMAKE_SYSTEM_NAME} MATCHES "Linux")

# find OpenSSL
if ( USE_GNUTLS )
pkg_check_modules (SSL REQUIRED gnutls nettle)
set (SSL_REQUIRED_MODULES "gnutls nettle")
if (WIN32)
if (MINGW)
set (SSL_REQUIRED_MODULES "${SSL_REQUIRED_MODULES} zlib")
endif()
endif()

pkg_check_modules (SSL REQUIRED ${SSL_REQUIRED_MODULES})

add_definitions(
-DUSE_GNUTLS=1
Expand All @@ -99,6 +106,7 @@ if ( USE_GNUTLS )
${SSL_LIBRARY_DIRS}
)
else()
set (SSL_REQUIRED_MODULES "openssl libcrypto zlib")
find_package(OpenSSL REQUIRED)
set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})
Expand All @@ -108,7 +116,6 @@ else()
-DHAICRYPT_USE_OPENSSL_AES
)
endif()

message (STATUS "SSL libraries: ${SSL_LIBRARIES}")

# Detect if the compiler is GNU compatable for flags
Expand Down Expand Up @@ -211,6 +218,7 @@ if (${ENABLE_PROFILE} AND HAVE_COMPILER_GNU_COMPAT)
endif()


if (NOT MINGW)
# find pthread
find_path(PTHREAD_INCLUDE_DIR pthread.h HINTS C:/pthread-win32/include)
if (PTHREAD_INCLUDE_DIR)
Expand All @@ -226,6 +234,10 @@ else()
message(FATAL_ERROR "Failed to find pthread library. Specify PTHREAD_LIBRARY.")
endif()

else()
find_library(PTHREAD_LIBRARY NAMES pthread pthreadGC2 pthreadGC)
endif() # if (NOT MINGW)

# This is required in some projects that add some other sources
# to the SRT library to be compiled together (aka "virtual library").
if (DEFINED SRT_EXTRA_LIB_INC)
Expand Down Expand Up @@ -357,9 +369,9 @@ target_include_directories(${TARGET_haicrypt}
)

set_target_properties (${TARGET_haicrypt} PROPERTIES VERSION ${SRT_VERSION} SOVERSION ${SRT_VERSION_MAJOR})
target_link_libraries(${TARGET_haicrypt} PRIVATE ${SSL_LIBRARIES})
set (SRT_LIBS_PRIVATE ${SSL_LIBRARIES})
if (WIN32)
target_link_libraries(${TARGET_haicrypt} PRIVATE ${SRT_LIBS_PRIVATE} ${SSL_LIBRARIES})

if ( WIN32 AND NOT CYGWIN )
target_link_libraries(${TARGET_haicrypt} PRIVATE ws2_32.lib)
set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ws2_32.lib)
endif()
Expand All @@ -385,10 +397,8 @@ if (ENABLE_SHARED)
target_compile_definitions(${TARGET_srt} PUBLIC -DUDT_DYNAMIC)
endif()

if ( WIN32 )
if (NOT CYGWIN)
if ( WIN32 AND (NOT MINGW AND NOT CYGWIN) )
target_link_libraries(${TARGET_srt} PUBLIC Ws2_32.lib)
endif()
endif()

install(TARGETS ${TARGET_srt}
Expand Down Expand Up @@ -452,6 +462,9 @@ endif()

if ( ENABLE_CXX11 )

# FIXME: with MINGW, it fails to build stransmit
# https://github.com/Haivision/srt/issues/177
if ( NOT MINGW )
add_executable(stransmit
${CMAKE_SOURCE_DIR}/apps/stransmit.cpp
${CMAKE_SOURCE_DIR}/common/uriparser.cpp
Expand All @@ -468,6 +481,8 @@ if ( ENABLE_CXX11 )
install(TARGETS stransmit RUNTIME DESTINATION bin)
install(PROGRAMS scripts/sfplay DESTINATION bin)

endif() # if ( NOT MINGW )

endif()

if (DEFINED SRT_EXTRA_APPS_INC)
Expand Down
41 changes: 39 additions & 2 deletions apps/stransmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,19 @@ Iface* CreateConsole() { return new typename Console<Iface>::type (); }

// More options can be added in future.
SocketOption udp_options [] {
{ "ipttl", IPPROTO_IP, IP_TTL, SocketOption::INT, SocketOption::PRE },
{ "iptos", IPPROTO_IP, IP_TOS, SocketOption::INT, SocketOption::PRE },
{ "mcttl", IPPROTO_IP, IP_MULTICAST_TTL, SocketOption::INT, SocketOption::PRE },
// IP_TTL and IP_MULTICAST_TTL are handled separately by a common option, "ttl".
{ "mcloop", IPPROTO_IP, IP_MULTICAST_LOOP, SocketOption::INT, SocketOption::PRE }
};


static inline bool IsMulticast(in_addr adr)
{
unsigned char* abytes = (unsigned char*)&adr.s_addr;
unsigned char c = abytes[0];
return c >= 224 && c <= 239;
}

class UdpCommon
{
protected:
Expand All @@ -1294,7 +1301,22 @@ class UdpCommon
}
sadr = CreateAddrInet(host, port);

bool is_multicast = false;

if ( attr.count("multicast") )
{
if (!IsMulticast(sadr.sin_addr))
{
throw std::runtime_error("UdpCommon: requested multicast for a non-multicast-type IP address");
}
is_multicast = true;
}
else if (IsMulticast(sadr.sin_addr))
{
is_multicast = true;
}

if (is_multicast)
{
adapter = attr.count("adapter") ? attr.at("adapter") : string();
sockaddr_in maddr;
Expand Down Expand Up @@ -1343,6 +1365,21 @@ class UdpCommon
attr.erase("adapter");
}

// The "ttl" options is handled separately, it maps to either IP_TTL
// or IP_MULTICAST_TTL, depending on whether the address is sc or mc.
if (attr.count("ttl"))
{
int ttl = stoi(attr.at("ttl"));
int res = setsockopt(m_sock, IPPROTO_IP, IP_TTL, (const char*)&ttl, sizeof ttl);
if (res == -1)
cout << "WARNING: failed to set 'ttl' (IP_TTL) to " << ttl << endl;
res = setsockopt(m_sock, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&ttl, sizeof ttl);
if (res == -1)
cout << "WARNING: failed to set 'ttl' (IP_MULTICAST_TTL) to " << ttl << endl;

attr.erase("ttl");
}

m_options = attr;

for (auto o: udp_options)
Expand Down
7 changes: 7 additions & 0 deletions common/srt_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ written by

#include <assert.h>
#include <sys/time.h>
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
#include <MobileCoreServices/MobileCoreServices.h>
#else
#include <CoreServices/CoreServices.h>
#endif
#include <pthread.h>
#include <mach/mach.h>
#include <mach/clock.h>
Expand Down
7 changes: 7 additions & 0 deletions common/srt_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ written by
#define HAISRT_COMPAT_H__

#include <stddef.h>
#include <time.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -176,10 +177,16 @@ inline struct tm LocalTime(time_t tt)
{
struct tm tm;
#ifdef WIN32
#if defined(_MSC_VER) && (_MSC_VER>=1500)
errno_t rr = localtime_s(&tm, &tt);
if (rr)
return tm;

#else
tm = *localtime(&tt);
#endif // _MSC_VER

#else // WIN32
tm = *localtime_r(&tt, &tm);
#endif

Expand Down
3 changes: 1 addition & 2 deletions common/win/wintime.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <winsock2.h>
#include <windows.h>
#include <time.h>
#include "haicrypt.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -34,7 +33,7 @@ struct timezone

void timeradd(struct timeval *a, struct timeval *b, struct timeval *result);

HAICRYPT_API int gettimeofday(struct timeval* tp, struct timezone* tz);
int gettimeofday(struct timeval* tp, struct timezone* tz);

#ifdef __cplusplus
}
Expand Down
27 changes: 15 additions & 12 deletions configure-data.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,26 @@ proc postprocess {} {
}

if { $::HAVE_DARWIN } {
# ON Darwin there's a problem with linking against the Mac-provided OpenSSL.
# This must use brew-provided OpenSSL.
#
if { !$have_openssl || !$have_gnutls } {

set er [catch {exec brew info openssl} res]
if { $er } {
error "You must have OpenSSL installed from 'brew' tool. The standard Mac version is inappropriate."
}

lappend ::cmakeopt "-DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include"
lappend ::cmakeopt "-DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib/libcrypto.a"
} elseif { $have_gnutls } {
if { $have_gnutls } {
set er [catch {exec brew info gnutls} res]
if { $er } {
error "Cannot find gnutls in brew"
}
} else {
# ON Darwin there's a problem with linking against the Mac-provided OpenSSL.
# This must use brew-provided OpenSSL.
#
if { !$have_openssl } {

set er [catch {exec brew info openssl} res]
if { $er } {
error "You must have OpenSSL installed from 'brew' tool. The standard Mac version is inappropriate."
}

lappend ::cmakeopt "-DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include"
lappend ::cmakeopt "-DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib/libcrypto.a"
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions docs/stransmit.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ specify the local port, e.g.:

udp://:5555

UDP handles two parameters: **iptos** and **ipttl**. See IP protocol
documentation for details.
UDP handles two parameters: **iptos** and **ttl**.
**iptos** will set the value of Type-Of-Service (TOS) field for outgoing packets via IP_TOS socket option.
**ttl** parameter will set time-to-live value for outgoing packets via IP_TTL or IP_MULTICAST_TTL socket options.
See IP protocol documentation for details.

For a single host IP address (unicast):
* **reading**: The *host* part or **adapter** parameter can specify the adapter. The *port* part is mandatory.
Expand Down
4 changes: 2 additions & 2 deletions scripts/haisrt.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Description: SRT library set
Version: @SRT_VERSION@
Libs: -L${libdir} -l@TARGET_srt@ @IFNEEDED_LINK_HAICRYPT@ @IFNEEDED_SRTBASE@ @IFNEEDED_SRT_LDFLAGS@
Libs.private: @SRT_LIBS_PRIVATE@
Cflags: -I${includedir}

Cflags: -I${includedir} -I${includedir}/srt
Requires.private: @SSL_REQUIRED_MODULES@
2 changes: 1 addition & 1 deletion srtcore/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ inline std::string SockaddrToString(const sockaddr* sadr)

std::ostringstream output;
char hostbuf[1024];
if (inet_ntop(sadr->sa_family, addr, hostbuf, 1024))
if (!getnameinfo(sadr, sizeof(*sadr), hostbuf, 1024, NULL, 0, NI_NAMEREQD))
{
output << hostbuf;
}
Expand Down
1 change: 1 addition & 0 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ modified by
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#include <mswsock.h>
#endif

#include <iostream>
Expand Down
4 changes: 4 additions & 0 deletions srtcore/logging_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ written by
#ifdef WIN32
#include "win/syslog_defs.h"
#else
#ifdef ANDROID
#include <syslog.h>
#else
#include <sys/syslog.h>
#endif
#endif

// Syslog is included so that it provides log level names.
// Haivision log standard requires the same names plus extra one:
Expand Down
3 changes: 2 additions & 1 deletion srtcore/platform_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
#include <windows.h>
#include <inttypes.h>
#include <stdint.h>
#include <win/wintime.h>
#include "win/wintime.h"
#if defined(_MSC_VER)
#pragma warning(disable:4251)
#endif
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
Expand Down

0 comments on commit df8e553

Please sign in to comment.