summaryrefslogtreecommitdiffstats
path: root/loader2
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2006-10-31 18:16:21 +0000
committerChris Lumens <clumens@redhat.com>2006-10-31 18:16:21 +0000
commit7f3f656e06ff44bd12a1197b99d17542cb8e82ff (patch)
treeec14c7c652faddae9e34f2d0f45a450edd505ebe /loader2
parentfe6b9c7a146fa745fce07d015703c6c56e17b9e1 (diff)
downloadanaconda-7f3f656e06ff44bd12a1197b99d17542cb8e82ff.tar.gz
anaconda-7f3f656e06ff44bd12a1197b99d17542cb8e82ff.tar.xz
anaconda-7f3f656e06ff44bd12a1197b99d17542cb8e82ff.zip
Add a function to split hostname/port number pairs up that takes IPv6 numeric
addresses into account.
Diffstat (limited to 'loader2')
-rw-r--r--loader2/net.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/loader2/net.c b/loader2/net.c
index 614231ead..1398185d4 100644
--- a/loader2/net.c
+++ b/loader2/net.c
@@ -27,6 +27,8 @@
*/
/* #define RAWHIDE_STUPID_OPTIONS 1 */
+#define _GNU_SOURCE
+
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@@ -1787,4 +1789,56 @@ int kickstartNetworkUp(struct loaderData_s * loaderData,
return 0;
}
+static int strcount (char *str, int ch)
+{
+ int retval = 0;
+ char *tmp = str;
+
+ do {
+ if ((tmp = index(tmp, ch)) != NULL) {
+ tmp++;
+ retval++;
+ }
+ } while (tmp != NULL);
+
+ return retval;
+}
+
+void splitHostname (char *str, char **host, char **port)
+{
+ char *rightbrack = strchr(str, ']');
+
+ *host = NULL;
+ *port = NULL;
+
+ if (*str == '[' && rightbrack) {
+ /* An IPv6 address surrounded by brackets, optionally with a colon and
+ * port number.
+ */
+ char *colon = strrchr(rightbrack, ':');
+
+ if (colon) {
+ *host = strndup(str+1, rightbrack-1-str);
+ *port = strdup(colon+1);
+ }
+ else
+ *host = strndup(str+1, rightbrack-1-str);
+ } else if (strcount(str, ':') > 1) {
+ /* An IPv6 address without brackets. Don't make the user surround the
+ * address with brackets if there's no port number.
+ */
+ *host = strdup(str);
+ } else {
+ /* An IPv4 address, optionally with a colon and port number. */
+ char *colon = strrchr(str, ':');
+
+ if (colon) {
+ *host = strndup(str, colon-str);
+ *port = strdup(colon+1);
+ }
+ else
+ *host = strdup(str);
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4: */