MySQL 9.0.0
Source Code Documentation
hostname_validator.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_HOSTNAME_VALIDATOR_INCLUDED
27#define MYSQL_HARNESS_HOSTNAME_VALIDATOR_INCLUDED
28
29#include "harness_export.h"
30
31#include <string>
32
33namespace mysql_harness {
34
35bool HARNESS_EXPORT is_valid_ip_address(const std::string &address);
36
37/**
38 * check if address is a hostname.
39 *
40 * hostname is verified according to RFC 1123.
41 *
42 * - fully qualified domain names like "mysql.com." are not valid hostnames
43 * (trailing dot)
44 * - service names like "_mysql.example.com" are not valid hostnames (leading
45 * underscore)
46 *
47 * @param address name of a host
48 *
49 * @retval false hostname is invalid
50 * @retval true hostname is valid
51 */
52bool HARNESS_EXPORT is_valid_hostname(const std::string &address);
53
54/**
55 * check if address is a domainname.
56 *
57 * domainnames according to RFC 2181:
58 *
59 * - max size 255 chars
60 * - labels are separated by dots
61 * - each label is min 1, max 63 chars.
62 *
63 * That means
64 *
65 * - IPv4 addresses
66 * - IPv6 addresses
67 * - hostnames
68 *
69 * are domainnames.
70 *
71 * @param address address to check
72 *
73 * @retval true address is a domainname
74 * @retval false address is not a domainname
75 */
76bool HARNESS_EXPORT is_valid_domainname(const std::string &address);
77
78} // namespace mysql_harness
79
80#endif // #define MYSQL_HARNESS_HOSTNAME_VALIDATOR_INCLUDED
Definition: common.h:42
bool HARNESS_EXPORT is_valid_ip_address(const std::string &address)
Definition: hostname_validator.cc:34
bool HARNESS_EXPORT is_valid_hostname(const std::string &address)
check if address is a hostname.
Definition: hostname_validator.cc:50
bool HARNESS_EXPORT is_valid_domainname(const std::string &address)
check if address is a domainname.
Definition: hostname_validator.cc:65