1 | /* $Id: netaddrstr2.cpp 45123 2013-03-21 10:42:26Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Network Address String Handling.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include "internal/iprt.h"
|
---|
31 | #include <iprt/net.h>
|
---|
32 |
|
---|
33 | #include <iprt/mem.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 | #include <iprt/stream.h>
|
---|
36 | #include "internal/string.h"
|
---|
37 |
|
---|
38 | RTDECL(int) RTNetStrToIPv4Addr(const char *pszAddr, PRTNETADDRIPV4 pAddr)
|
---|
39 | {
|
---|
40 | char *pszNext;
|
---|
41 | AssertPtrReturn(pszAddr, VERR_INVALID_PARAMETER);
|
---|
42 | AssertPtrReturn(pAddr, VERR_INVALID_PARAMETER);
|
---|
43 |
|
---|
44 | int rc = RTStrToUInt8Ex(RTStrStripL(pszAddr), &pszNext, 10, &pAddr->au8[0]);
|
---|
45 | if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
|
---|
46 | return VERR_INVALID_PARAMETER;
|
---|
47 | if (*pszNext++ != '.')
|
---|
48 | return VERR_INVALID_PARAMETER;
|
---|
49 |
|
---|
50 | rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[1]);
|
---|
51 | if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
|
---|
52 | return VERR_INVALID_PARAMETER;
|
---|
53 | if (*pszNext++ != '.')
|
---|
54 | return VERR_INVALID_PARAMETER;
|
---|
55 |
|
---|
56 | rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[2]);
|
---|
57 | if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
|
---|
58 | return VERR_INVALID_PARAMETER;
|
---|
59 | if (*pszNext++ != '.')
|
---|
60 | return VERR_INVALID_PARAMETER;
|
---|
61 |
|
---|
62 | rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[3]);
|
---|
63 | if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES)
|
---|
64 | return VERR_INVALID_PARAMETER;
|
---|
65 | pszNext = RTStrStripL(pszNext);
|
---|
66 | if (*pszNext)
|
---|
67 | return VERR_INVALID_PARAMETER;
|
---|
68 |
|
---|
69 | return VINF_SUCCESS;
|
---|
70 | }
|
---|
71 | RT_EXPORT_SYMBOL(RTNetStrToIPv4Addr);
|
---|
72 |
|
---|
73 |
|
---|