VirtualBox

Changeset 43171 in vbox for trunk/include


Ignore:
Timestamp:
Sep 4, 2012 5:07:27 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
80557
Message:

Runtime: add IPv6 parsing/resolving functions (contributed by Oliver Loch)
ExtPacks/VNC: add IPv6 support (contributed by Oliver Loch)

Location:
trunk/include/iprt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r42712 r43171  
    1111
    1212/*
    13  * Copyright (C) 2011 Oracle Corporation
     13 * Copyright (C) 2011-2012 Oracle Corporation
    1414 *
    1515 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    11971197# define RTSocketClose                                  RT_MANGLER(RTSocketClose)
    11981198# define RTSocketFromNative                             RT_MANGLER(RTSocketFromNative)
     1199# define RTSocketGetAddrInfo                            RT_MANGLER(RTSocketGetAddrInfo)
    11991200# define RTSocketGetLocalAddress                        RT_MANGLER(RTSocketGetLocalAddress)
    12001201# define RTSocketGetPeerAddress                         RT_MANGLER(RTSocketGetPeerAddress)
     
    12841285# define RTStrICmp                                      RT_MANGLER(RTStrICmp)
    12851286# define RTStrIStr                                      RT_MANGLER(RTStrIStr)
     1287# define RTStrIsIpAddr4                                 RT_MANGLER(RTStrIsIpAddr4)
     1288# define RTStrIsIpAddr6                                 RT_MANGLER(RTStrIsIpAddr6)
    12861289# define RTStrIsValidEncoding                           RT_MANGLER(RTStrIsValidEncoding)
    12871290# define RTStrmClearError                               RT_MANGLER(RTStrmClearError)
  • trunk/include/iprt/socket.h

    r39804 r43171  
    44
    55/*
    6  * Copyright (C) 2006-2011 Oracle Corporation
     6 * Copyright (C) 2006-2012 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    126126 */
    127127RTDECL(int) RTSocketParseInetAddress(const char *pszAddress, unsigned uPort, PRTNETADDR pAddr);
     128
     129/**
     130 * Gets the ip addresses of a hostname via getaddrinfo()
     131 * Returns only the first result for the moment
     132 * This will change with the upcoming IPv6 struct.
     133 *
     134 * @returns IPRT status code.
     135 * @param   psz szString we want to lookup
     136 * @param   pszResult - memory used to write the result to
     137 * @param   resultSize - size of pszResult in bytes.
     138 *                       Holds size of string of the returned
     139 *                       address on out
     140 * @param   pAddrType   Which address to lookup, valid values are:
     141 *                      RTNETADDRTYPE_IPV4 -> lookup AF_INET
     142 *                      RTNETADDRTYPE_IPV6 -> lookup AF_INET6
     143 *                      RTNETADDRTYPE_INVALID,NULL,... -> lookup anything
     144 */
     145RTDECL(int) RTSocketGetAddrInfo(const char *psz, char *pszResult, size_t *resultSize, PRTNETADDRTYPE pAddrType);
    128146
    129147/**
  • trunk/include/iprt/string.h

    r40938 r43171  
    44
    55/*
    6  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2012 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    38603860/** @} */
    38613861
     3862/** @defgroup rt_str_net    Network Address related String operations
     3863 * @ingroup grp_rt_str
     3864 * @{ */
     3865
     3866/** @page IPv6 Address Format
     3867 *
     3868 * IPv6 Addresses, their representation in text and other problems.
     3869 *
     3870 * The following is based on:
     3871 *
     3872 * - http://tools.ietf.org/html/rfc4291
     3873 * - http://tools.ietf.org/html/rfc5952
     3874 * - http://tools.ietf.org/html/rfc6052
     3875 *
     3876 *
     3877 * Before you start using those functions, you should have an idea of
     3878 * what you're dealing with, before you come and blame the functions...
     3879 *
     3880 * First of all, the address itself:
     3881 *
     3882 * An address is written like this: (READ THIS FINE MANUAL!)
     3883 *
     3884 * - 2001:db8:abc:def::1
     3885 *
     3886 * The characters between two colons are called a "hextet".
     3887 * Each hextet consists of four characters and each IPv6 address
     3888 * consists of a maximum of eight hextets. So a full blown address
     3889 * would look like this:
     3890 *
     3891 * - 1111:2222:3333:4444:5555:6666:7777:8888
     3892 *
     3893 * The allowed characters are "0123456789abcdef". They have to be
     3894 * lower case. Upper case is not allowed.
     3895 *
     3896 * *** Gaps and adress shortening
     3897 *
     3898 * If an address contains hextets that contain only "0"s, they
     3899 * can be shortened, like this:
     3900 *
     3901 * - 1111:2222:0000:0000:0000:0000:7777:8888 -> 1111:2222::7777:8888
     3902 *
     3903 * The double colon represents the hextets that have been shortened "::".
     3904 * The "::" will be called "gap" from now on.
     3905 *
     3906 * When shortening an address, there are some special rules that need to be applied:
     3907 *
     3908 * - Shorten always the longest group of hextets.
     3909 *
     3910 *   Let's say, you have this address: 2001:db8:0:0:0:1:0:0 then it has to be
     3911 *   shortened to "2001:db8::1:0:0". Shortening to "2001:db8:0:0:0:1::" would
     3912 *   return an error.
     3913 *
     3914 * - Two or more gaps the same size.
     3915 *
     3916 *   Let's say you have this address: 2001:db8:0:0:1:0:0:1. As you can see, there
     3917 *   are two gaps, both the size of two hextets. If you shorten the last two hextets,
     3918 *   you end up in pain, as the RFC forbids this, so the correct address is:
     3919 *   "2001:db8::1:0:0:1"
     3920 *
     3921 * It's important to note that an address can only be shortened ONE TIME!
     3922 * This is invalid: "2001:db8::1::1"
     3923 *
     3924 * *** The scope.
     3925 *
     3926 * Each address has a so called "scope" it is added to the end of the address,
     3927 * separated by a percent sign "%". If there is no scope at the end, it defaults
     3928 * to "0".
     3929 *
     3930 * So "2001:db8::1" is the same as "2001:db8::1%0".
     3931 *
     3932 * As in IPv6 all network interfaces can/should have the same address, the scope
     3933 * gives you the ability to choose on which interface the system should listen.
     3934 *
     3935 * AFAIK, the scope can be used with unicast as well as link local addresses, but
     3936 * it is mandatory with link local addresses (starting with fe80::).
     3937 *
     3938 * On Linux the default scope is the interface's name. On Windows it's just the index
     3939 * of the interface. Run "route print -6" in the shell, to see the interface's index
     3940 * on Winodows.
     3941 *
     3942 * All functions can deal with the scope, and DO NOT warn if you put garbage there.
     3943 *
     3944 * *** Port added to the IPv6 address
     3945 *
     3946 * There is only one way to add a port to an IPv6 address is to embed it in brackets:
     3947 *
     3948 * [2001:db8::1]:12345
     3949 *
     3950 * This gives you the address "2001:db8::1" and the port "12345".
     3951 *
     3952 * What also works, but is not recommended by rfc is to separate the port
     3953 * by a dot:
     3954 *
     3955 * 2001:db8::1.12345
     3956 *
     3957 * It even works with embedded IPv4 addresses.
     3958 *
     3959 * *** Special addresses and how they are written
     3960 *
     3961 * The following are notations to represent "special addresses".
     3962 *
     3963 * "::" IN6ADDR_ANY
     3964 * ":::123" IN6ADDR_ANY with port "123"
     3965 * "[::]:123" IN6ADDR_ANY with port "123"
     3966 * "[:::123]" -> NO. Not allowed and makes no sense
     3967 * "::1" -> address of the loopback device (127.0.0.1 in v4)
     3968 *
     3969 * On systems with dual sockets, one can use so called embedded IPv4 addresses:
     3970 *
     3971 * "::ffff:192.168.1.1" results in the IPv6 address "::ffff:c0a8:0101" as two octets
     3972 * of the IPv4 address will be converted to one hextet in the IPv6 address.
     3973 *
     3974 * The prefix of such addresses MUST BE "::ffff:", 10 bytes as zero and two bytes as 255.
     3975 *
     3976 * The so called IPv4-compatible IPv6 addresses are deprecated and no longer in use.
     3977 *
     3978 * *** Valid addresses and string
     3979 *
     3980 * If you use any of the IPv6 address functions, keep in mind, that those addresses
     3981 * are all returning "valid" even if the underlying system (e.g. VNC) doesn't like
     3982 * such strings.
     3983 *
     3984 * [2001:db8::1]
     3985 * [2001:db8::1]:12345
     3986 *
     3987 * and so on. So to make sure you only pass the underlying software a pure IPv6 address
     3988 * without any garbage, you should use the "outAddress" parameters to get a RFC compliant
     3989 * address returned.
     3990 *
     3991 * So after reading the above, you'll start using the functions and see a bool called
     3992 * "followRfc" which is true by default. This is what this bool does:
     3993 *
     3994 * The following addresses all represent the exact same address:
     3995 *
     3996 * 1 - 2001:db8::1
     3997 * 2 - 2001:db8:0::1
     3998 * 3 - 2001:0db8:0000:0000:0000:0000:0000:0001
     3999 * 4 - 2001:DB8::1
     4000 * 5 - [2001:db8::1]
     4001 * 6 - [2001:db8:0::1]
     4002 *
     4003 * According to RFC 5952, number two, three, four and six are invalid.
     4004 *
     4005 * #2 - because there is a single hextet that hasn't been shortened
     4006 *
     4007 * #3 - because there has nothing been shortened (hextets 3 to 7) and
     4008 *      there are leading zeros in at least one hextet ("0db8")
     4009 *
     4010 * #4 - all characters in an IPv6 address have to be lower case
     4011 *
     4012 * #6 - same as two but included in brackets
     4013 *
     4014 * If you follow RFC, the above addresses are not converted and an
     4015 * error is returned. If you turn RFC off, you will get the expected
     4016 * representation of the address.
     4017 *
     4018 * It's a nice way to convert "weird" addresses to rfc compliant addresses
     4019 *
     4020 */
     4021
     4022/**
     4023 * Takes a string and tests if it is a valid IPv6 representation
     4024 *
     4025 * @returns iprt status code.
     4026 * @param psz                  The string to test
     4027 * @param pszResultAddress     plain address, optional read "valid addresses
     4028 *                             and strings" above.
     4029 * @param resultAddressSize    size of pszResultAddress
     4030 * @param addressOnly          return only the plain address (no scope)
     4031 *                             Ignored, and will always return the if id
     4032 *
     4033 */
     4034RTDECL(int) RTStrIsIpAddr6(const char *psz, char *pszResultAddress, size_t resultAddressSize, bool addressOnly, bool followRfc);
     4035
     4036/**
     4037 * Takes a string and returns 0 if it is an IPv4 address
     4038 *
     4039 * @returns iprt status code
     4040 * @param pst              The string to test
     4041 */
     4042RTDECL(int) RTStrIsIpAddr4(const char *psz);
     4043
     4044/** @} */
     4045
    38624046
    38634047RT_C_DECLS_END
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette