[Drbd-dev] [PATCH master] Fix bug in split_address() when handling IPv6 addresses
Manuel Franceschini
livewire at google.com
Wed Jul 21 16:55:35 CEST 2010
Signed-off-by: Manuel Franceschini <livewire at google.com>
---
Hi all,
this small patch fixes a bug when using "drbdsetup /dev/drbdX net" with
IPv6 addresses without specifying a port number as in
"ipv6:2001:db8::1".
This patch relies, however, on a slighlty different syntax:
$ drbdsetup /dev/drbdX net ipv6:[2001:db8::1] ipv6:[2001:db8::2]:7799 A
The introduction of brackets is necessary, since there is no way to
reliably separate the IPv6 address with the port number being optional.
I'm happy for any feedback/suggestions.
Cheers, Manuel.
user/drbdsetup.c | 31 +++++++++++++++++++++++++------
1 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/user/drbdsetup.c b/user/drbdsetup.c
index b479128..4b030a2 100644
--- a/user/drbdsetup.c
+++ b/user/drbdsetup.c
@@ -673,7 +673,7 @@ static void split_address(char* text, int *af, char** address, int* port)
};
unsigned int i;
- char *b;
+ char *b1 = NULL, *b2;
*af=AF_INET;
*address = text;
@@ -687,11 +687,30 @@ static void split_address(char* text, int *af, char** address, int* port)
if (*af == -1)
*af = get_af_ssocks(1);
- b=strrchr(text,':');
- if (b) {
- *b = 0;
- *port = m_strtoll(b+1,1);
- } else
+ if (*af == AF_INET6) {
+ b2=strchr(*address,'[');
+ if (!b2) {
+ fprintf(stderr, "IPv6 address in '%s' missing starting delimiter '['\n", text);
+ exit(20);
+ }
+ *address += 1;
+ b2=strrchr(*address,']');
+ if (b2) {
+ b1 = strchr(b2,':');
+ *b2 = 0;
+ } else {
+ fprintf(stderr, "IPv6 address in '%s' missing ending delimiter ']'\n", text);
+ exit(20);
+ }
+ } else {
+ b1=strrchr(text,':');
+ if (b1) {
+ *b1 = 0;
+ }
+ }
+ if (b1)
+ *port = m_strtoll(b1+1,1);
+ else
*port = 7788;
}
--
1.7.1
More information about the drbd-dev
mailing list