Skip to content

Commit b1099c9

Browse files
committed
Use FQDN_LEN instead of MAXHOSTNAMELEN for DNS names
As defined in nbase.h (or in some system header file on Linux), MAXHOSTNAMELEN is 64. This is the maximum length of a hostname, but not of a DNS name, which may be longer. RFC 1035 spells out that DNS names are formed of labels, each of which must be 63 bytes or less, and that labels are combined to form a DNS name (a.k.a. FQDN) which may not exceed 255 bytes. So add and use that, which fixed a long name issue for me. Signed-off-by: Robin Getz <[email protected]>
1 parent 47381e2 commit b1099c9

File tree

6 files changed

+6
-11
lines changed

6 files changed

+6
-11
lines changed

dns_sd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int dnssd_fill_context_info(struct iio_context_info *info,
8181
char *hostname, char *addr_str, uint16_t port)
8282
{
8383
struct iio_context *ctx;
84-
char uri[sizeof("ip:") + MAXHOSTNAMELEN + sizeof (":65535") + 1];
84+
char uri[sizeof("ip:") + FQDN_LEN + sizeof (":65535") + 1];
8585
char description[255], *p;
8686
const char *hw_model, *serial;
8787
unsigned int i;

dns_sd.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515

1616
#ifdef _WIN32
1717
#include <winsock2.h>
18-
#ifndef MAXHOSTNAMELEN
19-
#define MAXHOSTNAMELEN (MAX_COMPUTERNAME_LENGTH+1)
20-
#endif /* MAXHOSTNAMELEN */
2118
#else
2219
#include <sys/param.h>
2320
#endif
2421

2522
#define DNS_SD_ADDRESS_STR_MAX (40) /* IPv6 Max = 4*8 + 7 + 1 for NUL */
23+
#define FQDN_LEN (255) /* RFC 1035 */
2624

2725
/* MacOS doesn't include ENOMEDIUM (No medium found) like Linux does */
2826
#ifndef ENOMEDIUM

dns_sd_bonjour.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ static void __cfnet_browser_cb(CFNetServiceBrowserRef browser,
3030
struct dns_sd_discovery_data *dd = info;
3131
char address_v4[DNS_SD_ADDRESS_STR_MAX+1] = "";
3232
char address_v6[DNS_SD_ADDRESS_STR_MAX+1] = "";
33-
char hostname[MAXHOSTNAMELEN];
34-
char name[MAXHOSTNAMELEN];
33+
char hostname[FQDN_LEN];
34+
char name[FQDN_LEN];
3535
bool have_v4 = false;
3636
bool have_v6 = false;
3737
struct sockaddr_in *sa;

network-windows.c

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include <errno.h>
1212
#include <ws2tcpip.h>
1313
#define close(s) closesocket(s)
14-
#ifndef MAXHOSTNAMELEN
15-
#define MAXHOSTNAMELEN (MAX_COMPUTERNAME_LENGTH+1)
16-
#endif /* MAXHOSTNAMELEN */
1714

1815
int set_blocking_mode(int s, bool blocking)
1916
{

network.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ struct iio_context * network_create_context(const char *host)
12181218

12191219
uri_len = strlen(description);
12201220
if (host && host[0])
1221-
uri_len = strnlen(host, MAXHOSTNAMELEN);
1221+
uri_len = strnlen(host, FQDN_LEN);
12221222
uri_len += sizeof ("ip:");
12231223

12241224
uri = malloc(uri_len);

utilities.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ char * iio_getenv (char * envvar)
321321
if (!hostname)
322322
return NULL;
323323

324-
tmp = MAXHOSTNAMELEN + sizeof("serial:") + sizeof(":65535") - 2;
324+
tmp = FQDN_LEN + sizeof("serial:") + sizeof(":65535") - 2;
325325
len = strnlen(hostname, tmp);
326326

327327
/* Should be smaller than max length */

0 commit comments

Comments
 (0)