Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-SMF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-SMF
Commits
695269c4
Commit
695269c4
authored
Jun 05, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support FQDN Resolver
parent
284aa70e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
0 deletions
+104
-0
src/common/utils/CMakeLists.txt
src/common/utils/CMakeLists.txt
+1
-0
src/common/utils/fqdn.cpp
src/common/utils/fqdn.cpp
+58
-0
src/common/utils/fqdn.hpp
src/common/utils/fqdn.hpp
+45
-0
No files found.
src/common/utils/CMakeLists.txt
View file @
695269c4
...
...
@@ -48,6 +48,7 @@ set(CN_UTILS_SRC STATIC
${
CMAKE_CURRENT_SOURCE_DIR
}
/string.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/thread_sched.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/mime_parser.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/fqdn.cpp
)
add_library
(
CN_UTILS
${
CN_UTILS_SRC
}
)
\ No newline at end of file
src/common/utils/fqdn.cpp
0 → 100644
View file @
695269c4
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (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.openairinterface.org/?page_id=698
*
* 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.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "fqdn.hpp"
#include "logger.hpp"
#include <boost/asio.hpp>
#include <iostream>
bool
fqdn
::
resolve
(
const
std
::
string
&
host_name
,
std
::
string
&
address
,
uint32_t
&
port
,
uint8_t
&
addr_type
,
const
std
::
string
&
protocol
)
{
try
{
boost
::
asio
::
io_context
io_context
=
{};
boost
::
asio
::
ip
::
tcp
::
resolver
resolver
{
io_context
};
boost
::
asio
::
ip
::
tcp
::
resolver
::
results_type
endpoints
=
resolver
.
resolve
(
host_name
,
protocol
);
addr_type
=
0
;
// IPv4 by default
for
(
auto
it
=
endpoints
.
cbegin
();
it
!=
endpoints
.
cend
();
it
++
)
{
// get the first Endpoint
boost
::
asio
::
ip
::
tcp
::
endpoint
endpoint
=
*
it
;
address
=
endpoint
.
address
().
to_string
();
port
=
endpoint
.
port
();
Logger
::
smf_app
().
debug
(
"Resolve a DNS (name %s, protocol %s): Ip Addr %s, port %u"
,
host_name
.
c_str
(),
protocol
.
c_str
(),
address
.
c_str
(),
port
);
if
(
endpoint
.
address
().
is_v4
())
addr_type
=
0
;
else
addr_type
=
1
;
return
true
;
}
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
'\n'
;
return
false
;
}
return
false
;
}
src/common/utils/fqdn.hpp
0 → 100644
View file @
695269c4
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (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.openairinterface.org/?page_id=698
*
* 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.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file fqdn.hpp
\brief
\author
\company Eurecom
\email:
*/
#ifndef FILE_FQDN_HPP_SEEN
#define FILE_FQDN_HPP_SEEN
#include <string>
class
fqdn
{
public:
/*
* Resolve a DNS name to get host's IP Addr
* @param [const std::string &] host_name: host's name/url
* @param [const std::string &] protocol: protocol
* @param [uint8_t &] addr_type: addr_type (Ipv4/v6)
* @return void
*/
static
bool
resolve
(
const
std
::
string
&
host_name
,
std
::
string
&
address
,
uint32_t
&
port
,
uint8_t
&
addr_type
,
const
std
::
string
&
protocol
=
"http"
);
};
#endif
/* FILE_FQDN_HPP_SEEN */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment