Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
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
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
Libraries
UERANSIM
Commits
10d09d55
Commit
10d09d55
authored
Jul 02, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GetIp4 improvements for domain improvements
parent
dd821784
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletion
+41
-1
src/utils/io.cpp
src/utils/io.cpp
+35
-0
src/utils/io.hpp
src/utils/io.hpp
+2
-0
src/utils/yaml_utils.cpp
src/utils/yaml_utils.cpp
+4
-1
No files found.
src/utils/io.cpp
View file @
10d09d55
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
#include <netdb.h>
#include <utils/constants.hpp>
#include <utils/constants.hpp>
#include <utils/libc_error.hpp>
#include <utils/libc_error.hpp>
...
@@ -218,4 +219,38 @@ std::string GetIp4OfInterface(const std::string &ifName)
...
@@ -218,4 +219,38 @@ std::string GetIp4OfInterface(const std::string &ifName)
return
std
::
string
{
str
};
return
std
::
string
{
str
};
}
}
std
::
string
GetHostByName
(
const
std
::
string
&
name
)
{
struct
addrinfo
hints
=
{};
hints
.
ai_family
=
PF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_flags
|=
AI_CANONNAME
;
auto
*
res
=
gethostbyname
(
name
.
c_str
());
if
(
res
==
nullptr
)
return
""
;
if
(
res
->
h_addr_list
==
nullptr
)
return
""
;
if
(
res
->
h_addrtype
==
AF_INET
)
{
char
str
[
INET_ADDRSTRLEN
]
=
{
0
};
if
(
inet_ntop
(
AF_INET
,
res
->
h_addr_list
[
0
],
str
,
INET_ADDRSTRLEN
)
==
nullptr
)
return
""
;
return
std
::
string
{
str
};
}
else
if
(
res
->
h_addrtype
==
AF_INET
)
{
char
str
[
INET6_ADDRSTRLEN
]
=
{
0
};
if
(
inet_ntop
(
AF_INET6
,
res
->
h_addr_list
[
0
],
str
,
INET6_ADDRSTRLEN
)
==
nullptr
)
return
""
;
return
std
::
string
{
str
};
}
else
{
return
""
;
}
}
}
// namespace io
}
// namespace io
src/utils/io.hpp
View file @
10d09d55
...
@@ -42,4 +42,6 @@ void AppendPath(std::string &source, const std::string &target);
...
@@ -42,4 +42,6 @@ void AppendPath(std::string &source, const std::string &target);
std
::
string
GetIp4OfInterface
(
const
std
::
string
&
ifName
);
std
::
string
GetIp4OfInterface
(
const
std
::
string
&
ifName
);
std
::
string
GetHostByName
(
const
std
::
string
&
name
);
}
// namespace io
}
// namespace io
src/utils/yaml_utils.cpp
View file @
10d09d55
...
@@ -156,7 +156,10 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
...
@@ -156,7 +156,10 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
if
(
ipFromIf
.
empty
())
if
(
ipFromIf
.
empty
())
FieldError
(
name
,
"must be a valid IPv4 address or a valid network interface with a IPv4 address"
);
FieldError
(
name
,
"must be a valid IPv4 address or a valid network interface with a IPv4 address"
);
return
ipFromIf
;
auto
n
=
io
::
GetHostByName
(
name
);
if
(
utils
::
GetIpVersion
(
n
)
==
4
)
return
n
;
return
""
;
}
}
void
AssertHasBool
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
void
AssertHasBool
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
...
...
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