summaryrefslogtreecommitdiff
path: root/src/VBox/Runtime/common/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/VBox/Runtime/common/net')
-rw-r--r--src/VBox/Runtime/common/net/macstr.cpp91
-rw-r--r--src/VBox/Runtime/common/net/netaddrstr.cpp10
-rw-r--r--src/VBox/Runtime/common/net/netaddrstr2.cpp72
3 files changed, 170 insertions, 3 deletions
diff --git a/src/VBox/Runtime/common/net/macstr.cpp b/src/VBox/Runtime/common/net/macstr.cpp
new file mode 100644
index 00000000..84ac038f
--- /dev/null
+++ b/src/VBox/Runtime/common/net/macstr.cpp
@@ -0,0 +1,91 @@
+/* $Id: macstr.cpp $ */
+/** @file
+ * IPRT - Command Line Parsing
+ */
+
+/*
+ * Copyright (C) 2013 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <iprt/cidr.h>
+#include <iprt/net.h> /* must come before getopt.h */
+#include "internal/iprt.h"
+
+#include <iprt/assert.h>
+#include <iprt/ctype.h>
+#include <iprt/err.h>
+#include <iprt/message.h>
+#include <iprt/string.h>
+
+
+/**
+ * Converts an stringified Ethernet MAC address into the RTMAC representation.
+ *
+ * @returns VINF_SUCCESS on success.
+ *
+ * @param pszValue The value to convert.
+ * @param pAddr Where to store the result.
+ */
+RTDECL(int) RTNetStrToMacAddr(const char *pszValue, PRTMAC pAddr)
+{
+ /*
+ * Not quite sure if I should accept stuff like "08::27:::1" here...
+ * The code is accepting "::" patterns now, except for for the first
+ * and last parts.
+ */
+
+ /* first */
+ char *pszNext;
+ int rc = RTStrToUInt8Ex(RTStrStripL(pszValue), &pszNext, 16, &pAddr->au8[0]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
+ return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
+ if (*pszNext++ != ':')
+ return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
+
+ /* middle */
+ for (unsigned i = 1; i < 5; i++)
+ {
+ if (*pszNext == ':')
+ pAddr->au8[i] = 0;
+ else
+ {
+ rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &pAddr->au8[i]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
+ return rc;
+ if (*pszNext != ':')
+ return VERR_INVALID_PARAMETER;
+ }
+ pszNext++;
+ }
+
+ /* last */
+ rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &pAddr->au8[5]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES)
+ return rc;
+ pszNext = RTStrStripL(pszNext);
+ if (*pszNext)
+ return VERR_INVALID_PARAMETER;
+
+ return VINF_SUCCESS;
+}
+RT_EXPORT_SYMBOL(RTNetStrToMacAddr);
diff --git a/src/VBox/Runtime/common/net/netaddrstr.cpp b/src/VBox/Runtime/common/net/netaddrstr.cpp
index 4cc88a39..ba4df40f 100644
--- a/src/VBox/Runtime/common/net/netaddrstr.cpp
+++ b/src/VBox/Runtime/common/net/netaddrstr.cpp
@@ -1,6 +1,10 @@
/* $Id: netaddrstr.cpp $ */
/** @file
* IPRT - Network Address String Handling.
+ *
+ * @remarks Don't add new functionality to this file, it goes into netaddrstr2.cpp
+ * or some other suitable file (legal reasons + code not up to oracle
+ * quality standards and requires rewrite from scratch).
*/
/*
@@ -202,7 +206,8 @@
* This function should NOT be used directly. If you do, note
* that no security checks are done at the moment. This can change.
*
- * @returns iprt sstatus code.
+ * @returns iprt sstatus code, yeah, right... This function most certainly DOES
+ * NOT RETURN ANY IPRT STATUS CODES. It's also a unreadable mess.
* @param pszAddress The strin that holds the IPv6 address
* @param addressLength The length of pszAddress
* @param pszAddressOut Returns a plain, full blown IPv6 address
@@ -1147,7 +1152,7 @@ static int rtNetIpv6CheckAddrStr(const char *psz, char *pszResultAddress, size_t
{
int rc;
int rc2;
- int returnValue;
+ int returnValue = VERR_NOT_SUPPORTED; /* gcc want's this initialized, I understand its confusion. */
char *p = NULL, *pl = NULL;
@@ -1283,4 +1288,3 @@ RTDECL(bool) RTNetIsIPv4AddrStr(const char *pszAddress)
return true;
}
RT_EXPORT_SYMBOL(RTNetIsIPv4AddrStr);
-
diff --git a/src/VBox/Runtime/common/net/netaddrstr2.cpp b/src/VBox/Runtime/common/net/netaddrstr2.cpp
new file mode 100644
index 00000000..eb9c70a8
--- /dev/null
+++ b/src/VBox/Runtime/common/net/netaddrstr2.cpp
@@ -0,0 +1,72 @@
+/* $Id: netaddrstr2.cpp $ */
+/** @file
+ * IPRT - Network Address String Handling.
+ */
+
+/*
+ * Copyright (C) 2013 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include "internal/iprt.h"
+#include <iprt/net.h>
+
+#include <iprt/mem.h>
+#include <iprt/string.h>
+#include <iprt/stream.h>
+#include "internal/string.h"
+
+RTDECL(int) RTNetStrToIPv4Addr(const char *pszAddr, PRTNETADDRIPV4 pAddr)
+{
+ char *pszNext;
+ AssertPtrReturn(pszAddr, VERR_INVALID_PARAMETER);
+ AssertPtrReturn(pAddr, VERR_INVALID_PARAMETER);
+
+ int rc = RTStrToUInt8Ex(RTStrStripL(pszAddr), &pszNext, 10, &pAddr->au8[0]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
+ return VERR_INVALID_PARAMETER;
+ if (*pszNext++ != '.')
+ return VERR_INVALID_PARAMETER;
+
+ rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[1]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
+ return VERR_INVALID_PARAMETER;
+ if (*pszNext++ != '.')
+ return VERR_INVALID_PARAMETER;
+
+ rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[2]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
+ return VERR_INVALID_PARAMETER;
+ if (*pszNext++ != '.')
+ return VERR_INVALID_PARAMETER;
+
+ rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[3]);
+ if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES)
+ return VERR_INVALID_PARAMETER;
+ pszNext = RTStrStripL(pszNext);
+ if (*pszNext)
+ return VERR_INVALID_PARAMETER;
+
+ return VINF_SUCCESS;
+}
+RT_EXPORT_SYMBOL(RTNetStrToIPv4Addr);
+