Skip to content

Commit

Permalink
Fix analogdevicesinc#307 by accepting avahi null names, and install a…
Browse files Browse the repository at this point in the history
…vahi service file

This will make sure things like this are functional:

./tests/iio_attr -u ip: -d
IIO context has 5 devices:
	iio:device0: adm1177, found 0 device attributes
	iio:device1: ad9361-phy, found 18 device attributes
	iio:device2: xadc, found 1 device attributes
	iio:device3: cf-ad9361-dds-core-lpc, found 0 device attributes
	iio:device4: cf-ad9361-lpc, found 0 device attributes

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Jan 13, 2020
1 parent 3d582f2 commit 673f922
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

if(WITH_NETWORK_BACKEND)
message(STATUS "Building with Network back end support")
if (WIN32)
set(LIBS_TO_LINK ${LIBS_TO_LINK} wsock32 ws2_32)
endif()
Expand All @@ -244,14 +245,20 @@ if(WITH_NETWORK_BACKEND)
find_library(AVAHI_CLIENT_LIBRARIES avahi-client)
find_library(AVAHI_COMMON_LIBRARIES avahi-common)
if(AVAHI_CLIENT_LIBRARIES AND AVAHI_COMMON_LIBRARIES)
message(STATUS "Building with Avahi, a zero-configuration networking (zeroconf) implementation")
set(HAVE_AVAHI ON)
set(AVAHI_LIBRARIES ${AVAHI_CLIENT_LIBRARIES} ${AVAHI_COMMON_LIBRARIES})
set(LIBS_TO_LINK ${LIBS_TO_LINK} ${AVAHI_LIBRARIES})
set(AVAHI_SERVICE_INSTALL_DIR /etc/avahi/services/ CACHE PATH "default install path for Avahi service files")
else()
message(STATUS "Building without Avahi (zeroconf) support")
endif()

set(NEED_THREADS 1)
set(IIOD_CLIENT 1)
set(NEED_LIBXML2 1)
else()
message(STATUS "Building without network support")
endif()

# Since libxml2-2.9.2, libxml2 provides its own LibXml2-config.cmake, with all
Expand Down Expand Up @@ -300,6 +307,9 @@ endif()

if (IIOD_CLIENT)
set(LIBIIO_CFILES ${LIBIIO_CFILES} iiod-client.c)
if (HAVE_AVAHI)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/iio.service DESTINATION ${AVAHI_SERVICE_INSTALL_DIR})
endif()
endif()

configure_file(libiio.iss.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libiio.iss @ONLY)
Expand Down
34 changes: 34 additions & 0 deletions iio.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

<!--
This file is part of avahi.

avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

avahi is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
-->

<!-- See avahi.service(5) for more information about this configuration file -->

<service-group>

<name replace-wildcards="yes">%h</name>

<service>
<type>_iio._tcp</type>
<port>30431</port>
</service>

</service-group>
2 changes: 1 addition & 1 deletion network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ struct iio_context * network_create_context(const char *host)
hints.ai_socktype = SOCK_STREAM;

#ifdef HAVE_AVAHI
if (!host) {
if (!host || !host[0]) {
char addr_str[AVAHI_ADDRESS_STR_MAX];
char port_str[6];
AvahiAddress address;
Expand Down

0 comments on commit 673f922

Please sign in to comment.