VirtualBox

Changeset 43214 in vbox for trunk/include


Ignore:
Timestamp:
Sep 6, 2012 9:16:55 AM (12 years ago)
Author:
vboxsync
Message:

RTStrIsIpAddr[46] -> RTNetIsIpv\1AddrStr; made the buggers return bool like predicate functions shall.

Location:
trunk/include/iprt
Files:
3 edited

Legend:

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

    r43213 r43214  
    881881# define RTNetTCPChecksum                               RT_MANGLER(RTNetTCPChecksum)
    882882# define RTNetUDPChecksum                               RT_MANGLER(RTNetUDPChecksum)
     883# define RTNetIsIPv4AddrStr                             RT_MANGLER(RTNetIsIPv4AddrStr)
     884# define RTNetIsIPv6AddrStr                             RT_MANGLER(RTNetIsIPv6AddrStr)
    883885# define RTOnceSlow                                     RT_MANGLER(RTOnceSlow)
    884886# define RTOnceReset                                    RT_MANGLER(RTOnceReset)
     
    12851287# define RTStrICmp                                      RT_MANGLER(RTStrICmp)
    12861288# define RTStrIStr                                      RT_MANGLER(RTStrIStr)
    1287 # define RTStrIsIpAddr4                                 RT_MANGLER(RTStrIsIpAddr4)
    1288 # define RTStrIsIpAddr6                                 RT_MANGLER(RTStrIsIpAddr6)
    12891289# define RTStrIsValidEncoding                           RT_MANGLER(RTStrIsValidEncoding)
    12901290# define RTStrmClearError                               RT_MANGLER(RTStrmClearError)
  • trunk/include/iprt/net.h

    r42956 r43214  
    44
    55/*
    6  * Copyright (C) 2008 Oracle Corporation
     6 * Copyright (C) 2008-2012 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    5050
    5151/**
     52 * Tests if the given string is an IPv4 address.
     53 *
     54 * @returns boolean.
     55 * @param   pszAddress          String which may be an IPv4 address.
     56 */
     57RTDECL(bool) RTNetIsIPv4AddrStr(const char *pszAddress);
     58
     59
     60/**
    5261 * IPv6 address.
    5362 */
     
    5867/** Pointer to a const IPv6 address. */
    5968typedef RTNETADDRIPV6 const *PCRTNETADDRIPV6;
     69
     70/**
     71 * Tests if the given string is a valid IPv6 address.
     72 *
     73 * @returns @c true if it is, @c false if not.
     74 * @param   pszAddress          String which may be an IPv6 address.
     75 */
     76RTDECL(bool) RTNetIsIPv6AddrStr(const char *pszAddress);
     77
    6078
    6179/**
     
    344362RTDECL(bool)     RTNetIPv4IsUDPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, size_t cbPktMax);
    345363RTDECL(bool)     RTNetIPv4IsUDPValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData, size_t cbPktMax, bool fChecksum);
     364
    346365
    347366/**
  • trunk/include/iprt/string.h

    r43171 r43214  
    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  */
    4034 RTDECL(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  */
    4042 RTDECL(int) RTStrIsIpAddr4(const char *psz);
     3862
     3863RT_C_DECLS_END
    40433864
    40443865/** @} */
    40453866
    4046 
    4047 RT_C_DECLS_END
    4048 
    4049 /** @} */
    4050 
    40513867#endif
    40523868
Note: See TracChangeset for help on using the changeset viewer.

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