netaddrstr2.cpp revision 7d67a9be8c4cdeac7a114229784de49dc1d21307
/* $Id$ */
/** @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;
* 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 *
*******************************************************************************/
char **ppszNext)
{
char *pszNext;
int rc;
return VERR_INVALID_PARAMETER;
if (*pszNext++ != '.')
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
if (*pszNext++ != '.')
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
if (*pszNext++ != '.')
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
char **ppszNext)
{
}
{
char *pszNext;
int rc;
if (rc != VINF_SUCCESS)
return VERR_INVALID_PARAMETER;
if (*pszNext != '\0')
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
{
char *pszNext;
int rc;
return false;
if (rc != VINF_SUCCESS)
return false;
if (*pszNext != '\0')
return false;
return true;
}
{
char *pszNext;
int rc;
if (RT_FAILURE(rc))
return rc;
if ( rc != VINF_SUCCESS
&& rc != VWRN_TRAILING_CHARS
&& rc != VWRN_TRAILING_SPACES)
{
return -rc; /* convert warning to error */
}
/* parser always accepts 0x prefix */
{
if (pu16)
*pu16 = 0;
if (ppszNext)
return VWRN_TRAILING_CHARS;
}
/* parser accepts leading zeroes "000000f" */
return VERR_PARSE_ERROR;
if (ppszNext)
return rc;
}
/*
* This function deals only with the hex-group IPv6 address syntax
* proper (with possible embedded IPv4).
*/
char **ppszNext)
{
const char *pcszPos;
char *pszNext;
int iGroup;
int rc;
{
return VERR_PARSE_ERROR;
iGroup = 1;
}
else
{
/*
* Scan forward until we either get complete address or find
* "::" compressed zero run.
*/
{
/* check for embedded IPv4 at the end */
if (iGroup == 6)
{
if (rc == VINF_SUCCESS)
{
break; /* we are done */
}
}
if (RT_FAILURE(rc))
return VERR_PARSE_ERROR;
if (iGroup == 7)
else
{
/* skip the colon that delimits this group */
if (*pszNext != ':')
return VERR_PARSE_ERROR;
/* compressed zero run? */
if (*pcszPos == ':')
{
++pcszPos; /* skip over :: */
break;
}
}
}
}
if (iGroup != 8)
{
/*
* iGroup is the first group that can be filled by the part of
* the address after "::".
*/
const int iMaybeStart = iGroup;
int j;
/*
* We try to accept longest match; we'll shift if necessary.
* Unlike the first loop, a failure to parse a group doesn't
* mean invalid address.
*/
{
/* check for embedded IPv4 at the end */
if (iGroup <= 6)
{
if (rc == VINF_SUCCESS)
{
break; /* the rest is trailer */
}
}
if (RT_FAILURE(rc))
break;
if (iGroup == 7)
else
{
if (*pszNext != ':')
{
++iGroup; /* this one is done */
break; /* the rest is trailer */
}
}
}
}
if (pAddrResult != NULL)
return VINF_SUCCESS;
}
{
int rc;
if (RT_FAILURE(rc))
return rc;
{
}
else
{
if (*pszZone == '\0')
return VERR_PARSE_ERROR; /* empty zone id */
/*
* XXX: this is speculative as zone id syntax is
* implementation dependent, so we kinda guess here (accepting
* unreserved characters from URI syntax).
*/
{
const char c = *pszNext;
if ( !('0' <= c && c <= '9')
&& !('a' <= c && c <= 'z')
&& !('A' <= c && c <= 'Z')
&& c != '_'
&& c != '.'
&& c != '-'
&& c != '~')
{
break;
}
}
}
return VINF_SUCCESS;
else
{
++pszNext;
if (*pszNext == '\0')
return VWRN_TRAILING_SPACES;
else
return VWRN_TRAILING_CHARS;
}
}
char **ppszNext)
{
}
char **ppszZone)
{
int rc;
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
{
int rc;
return false;
if (rc != VINF_SUCCESS)
return false;
return true;
}