Skip to content

Commit

Permalink
DNS-SD: Move headers to .c files
Browse files Browse the repository at this point in the history
Including a lot of headers in a header should be avoided as much as
possible; instead the headers should be included in the source files
directly.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Apr 13, 2021
1 parent 4fb59f0 commit e6b3a17
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
16 changes: 16 additions & 0 deletions dns_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
#include "iio-lock.h"
#include "iio-private.h"

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <errno.h>
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#endif

#ifdef _WIN32
#define close(s) closesocket(s)
#endif

/* Some functions for handling common linked list operations */
static void dnssd_remove_node(struct dns_sd_discovery_data **ddata, int n)
{
Expand Down
25 changes: 4 additions & 21 deletions dns_sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,17 @@
#ifndef __IIO_DNS_SD_H
#define __IIO_DNS_SD_H

#include "iio-config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <stdint.h>

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#define close(s) closesocket(s)
/* winsock2.h defines ERROR, we don't want that */
#undef ERROR
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN (MAX_COMPUTERNAME_LENGTH+1)
#endif /* MAXHOSTNAMELEN */
#else /* !_WIN32 */
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <net/if.h>
#include <sys/mman.h>
#else
#include <sys/param.h>
#include <sys/socket.h>
#include <poll.h>
#include <netdb.h>
#include <unistd.h>
#endif /* _WIN32 */
#endif

#define DNS_SD_ADDRESS_STR_MAX (40) /* IPv6 Max = 4*8 + 7 + 1 for NUL */

Expand All @@ -47,6 +29,7 @@
#define ENOMEDIUM ENOENT
#endif

struct addrinfo;
struct AvahiSimplePoll;
struct AvahiAddress;

Expand Down
2 changes: 2 additions & 0 deletions dns_sd_avahi.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "iio-private.h"
#include "iio-lock.h"

#include <errno.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

Expand Down
6 changes: 4 additions & 2 deletions dns_sd_bonjour.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* Robin Getz <[email protected]>
*/

#include <CFNetwork/CFNetwork.h>

#include "debug.h"
#include "dns_sd.h"
#include "iio-lock.h"
#include "iio-private.h"

#include <arpa/inet.h>
#include <netinet/in.h>
#include <CFNetwork/CFNetwork.h>

/*
Implementation for DNS SD discovery for macOS using CFNetServices.
*/
Expand Down
19 changes: 19 additions & 0 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
#include "iio-lock.h"
#include "iiod-client.h"

#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <unistd.h>
#endif

#define _STRINGIFY(x) #x
#define STRINGIFY(x) _STRINGIFY(x)

Expand Down

0 comments on commit e6b3a17

Please sign in to comment.