1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 * This file is open source software, licensed to you under the terms
4 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
5 * distributed with this work for additional information regarding copyright
6 * ownership. You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 * Copyright (C) 2014 Cloudius Systems, Ltd.
24 * Ceph - scalable distributed file system
26 * Copyright (C) 2015 XSky <haomai@xsky.com>
28 * Author: Haomai Wang <haomaiwang@gmail.com>
30 * This is free software; you can redistribute it and/or
31 * modify it under the terms of the GNU Lesser General Public
32 * License version 2.1, as published by the Free Software
33 * Foundation. See file COPYING.
37 #ifndef CEPH_IP_TYPES_H_H
38 #define CEPH_IP_TYPES_H_H
40 #include <boost/asio/ip/address_v4.hpp>
44 class ethernet_address;
45 using resolution_cb = std::function<void (const ethernet_address&, Packet, int)>;
51 ipv4_addr() : ip(0), port(0) {}
52 ipv4_addr(uint32_t ip, uint16_t port) : ip(ip), port(port) {}
53 ipv4_addr(uint16_t port) : ip(0), port(port) {}
54 ipv4_addr(const std::string &addr);
55 ipv4_addr(const std::string &addr, uint16_t port);
57 ipv4_addr(const entity_addr_t &ad) {
58 ip = ntoh(ad.in4_addr().sin_addr.s_addr);
62 ipv4_addr(entity_addr_t &&addr) : ipv4_addr(addr) {}
66 ipv4_address() : ip(0) {}
67 explicit ipv4_address(uint32_t ip) : ip(ip) {}
68 explicit ipv4_address(const std::string& addr) {
69 ip = static_cast<uint32_t>(boost::asio::ip::address_v4::from_string(addr).to_ulong());
71 ipv4_address(ipv4_addr addr) {
88 friend bool operator==(ipv4_address x, ipv4_address y) {
91 friend bool operator!=(ipv4_address x, ipv4_address y) {
94 } __attribute__((packed));
96 static inline bool is_unspecified(ipv4_address addr) { return addr.ip == 0; }
98 std::ostream& operator<<(std::ostream& os, const ipv4_address& a);
103 struct hash<ipv4_address> {
104 size_t operator()(ipv4_address a) const { return a.ip; }
109 #endif //CEPH_IP_TYPES_H_H