summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f3816cb)
raw | patch | inline | side by side (parent: f3816cb)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Thu, 25 Sep 2008 20:10:17 +0000 (20:10 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Thu, 25 Sep 2008 20:10:17 +0000 (20:10 +0000) |
contain colons, simply checking for a colon and using everything after it does
destroy correctly formatted IPv6-addresses.
This patch checks for dots '.' in the address. If the address contains at least
one dot, it is considered to be a hostname or an IPv4-address and a simple
search for a colon is done.
If no dot is found, the code will check for an opening square bracket '[' at
the beginning of the address. If one if found, the format
[address]:port
is assumed.
If neither applies, the default port will be used.
-- Florian Forster
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1523 a5681a0c-68f1-0310-ab6d-d61299d08faa
destroy correctly formatted IPv6-addresses.
This patch checks for dots '.' in the address. If the address contains at least
one dot, it is considered to be a hostname or an IPv4-address and a simple
search for a colon is done.
If no dot is found, the code will check for an opening square bracket '[' at
the beginning of the address. If one if found, the format
[address]:port
is assumed.
If neither applies, the default port will be used.
-- Florian Forster
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1523 a5681a0c-68f1-0310-ab6d-d61299d08faa
doc/rrdcached.pod | patch | blob | history | |
src/rrd_daemon.c | patch | blob | history |
diff --git a/doc/rrdcached.pod b/doc/rrdcached.pod
index bdb8949a893eaf589c364f739fbccbb907920137..3505728b08b1644e64c0960501275ae537f648cd 100644 (file)
--- a/doc/rrdcached.pod
+++ b/doc/rrdcached.pod
name are resolved using L<getaddrinfo>.
For network sockets, a port may be specified by using the form
-I<address>:I<port>. The default port is 42217.
+C<B<[>I<address>B<]:>I<port>>. If the address is an IPv4 address or a fully
+qualified domain name (i.E<nbsp>e. the address contains at least one dot
+(C<.>)), the square brackets can be omitted, resulting in the (simpler)
+C<I<address>B<:>I<port>> pattern.. The default port is B<42217/udp>.
-These formats are accepted:
+The following formats are accepted. Please note that the address of the UNIX
+domain socket B<must> start with a slash in the second case!
unix:</path/to/unix.sock>
- </path/to/unix.sock>
+ /<path/to/unix.sock>
<hostname-or-ip>
- <hostname-or-ip>:<port>
+ [<hostname-or-ip>]:<port>
+ <hostname-or-ipv4>:<port>
If the B<-l> option is not specified the default address,
C<unix:/tmp/rrdcached.sock>, will be used.
diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c
index 6f01f899cb8e03629257d4ed757ab63854af1753..a94e0794f649a9b323bf4bd42973b75d00d5d929 100644 (file)
--- a/src/rrd_daemon.c
+++ b/src/rrd_daemon.c
return (0);
} /* }}} int open_listen_socket_unix */
-static int open_listen_socket (const char *addr) /* {{{ */
+static int open_listen_socket (const char *addr_orig) /* {{{ */
{
struct addrinfo ai_hints;
struct addrinfo *ai_res;
struct addrinfo *ai_ptr;
+ char addr_copy[NI_MAXHOST];
+ char *addr;
char *port;
int status;
- assert (addr != NULL);
+ assert (addr_orig != NULL);
+
+ strncpy (addr_copy, addr_orig, sizeof (addr_copy));
+ addr_copy[sizeof (addr_copy) - 1] = 0;
+ addr = addr_copy;
if (strncmp ("unix:", addr, strlen ("unix:")) == 0)
return (open_listen_socket_unix (addr + strlen ("unix:")));
ai_hints.ai_family = AF_UNSPEC;
ai_hints.ai_socktype = SOCK_STREAM;
- port = rindex(addr, ':');
- if (port != NULL)
- *port++ = '\0';
+ port = NULL;
+ if (*addr == '[') /* IPv6+port format */
+ {
+ /* `addr' is something like "[2001:780:104:2:211:24ff:feab:26f8]:12345" */
+ addr++;
+ port = strchr (addr, ']');
+ if (port == NULL)
+ {
+ RRDD_LOG (LOG_ERR, "open_listen_socket: Malformed address: %s",
+ addr_orig);
+ return (-1);
+ }
+ *port = 0;
+ port++;
+
+ if (*port == ':')
+ port++;
+ else if (*port == 0)
+ port = NULL;
+ else
+ {
+ RRDD_LOG (LOG_ERR, "open_listen_socket: Garbage after address: %s",
+ port);
+ return (-1);
+ }
+ } /* if (*addr = ']') */
+ else if (strchr (addr, '.') != NULL) /* Hostname or IPv4 */
+ {
+ port = rindex(addr, ':');
+ if (port != NULL)
+ {
+ *port = 0;
+ port++;
+ }
+ }
ai_res = NULL;
status = getaddrinfo (addr,
port == NULL ? RRDCACHED_DEFAULT_PORT : port,