Program Listing for File IPFinder.hpp

Return to documentation for file (include/fastdds/utils/IPFinder.hpp)

// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FASTDDS_UTILS__IPFINDER_HPP
#define FASTDDS_UTILS__IPFINDER_HPP

#include <string>
#include <vector>

#include <fastdds/rtps/common/Locator.hpp>
#include <fastdds/rtps/common/LocatorList.hpp>
#include <fastdds/rtps/common/LocatorWithMask.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {
class IPFinder
{
public:

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
    enum IPTYPE
    {
        IP4,
        IP6,
        IP4_LOCAL,
        IP6_LOCAL
    };
    typedef struct info_IP
    {
        IPTYPE type;
        std::string name;
        std::string dev;
        Locator_t locator;
        fastdds::rtps::LocatorWithMask masked_locator;
    }info_IP;

    typedef struct info_MAC
    {
        unsigned char address[6];

        bool operator == (
                const info_MAC& other)
        {
            return memcmp(address, other.address, 6) == 0;
        }

    }info_MAC;

#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
    IPFinder();
    virtual ~IPFinder();

    FASTDDS_EXPORTED_API static bool getIPs(
            std::vector<info_IP>* vec_name,
            bool return_loopback = false);

    FASTDDS_EXPORTED_API static bool getIP4Address(
            LocatorList_t* locators);
    FASTDDS_EXPORTED_API static bool getIP6Address(
            LocatorList_t* locators);
    FASTDDS_EXPORTED_API static bool getAllIPAddress(
            LocatorList_t* locators);
    FASTDDS_EXPORTED_API static bool parseIP4(
            info_IP& info);
    FASTDDS_EXPORTED_API static bool parseIP6(
            info_IP& info);

    FASTDDS_EXPORTED_API static std::string getIPv4Address(
            const std::string& name);
    FASTDDS_EXPORTED_API static std::string getIPv6Address(
            const std::string& name);

    FASTDDS_EXPORTED_API static bool getAllMACAddress(
            std::vector<info_MAC>* macs);
};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif // FASTDDS_UTILS__IPFINDER_HPP