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
b0aef086
Unverified
Commit
b0aef086
authored
Dec 14, 2021
by
Ali Güngör
Committed by
GitHub
Dec 14, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #458 from abousselmi/master
Allow using FQDN along with IPv4 and IPv6
parents
b8c86919
38a8b5e5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
src/utils/io.cpp
src/utils/io.cpp
+16
-11
src/utils/yaml_utils.cpp
src/utils/yaml_utils.cpp
+11
-5
No files found.
src/utils/io.cpp
View file @
b0aef086
...
@@ -252,33 +252,38 @@ std::string GetIp6OfInterface(const std::string &ifName)
...
@@ -252,33 +252,38 @@ std::string GetIp6OfInterface(const std::string &ifName)
std
::
string
GetHostByName
(
const
std
::
string
&
name
)
std
::
string
GetHostByName
(
const
std
::
string
&
name
)
{
{
struct
addrinfo
hints
=
{};
struct
addrinfo
hints
=
{};
struct
addrinfo
*
res
;
hints
.
ai_family
=
PF_UNSPEC
;
hints
.
ai_family
=
AF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_flags
|=
AI_CANONNAME
;
auto
*
res
=
gethostbyname
(
name
.
c_str
());
if
(
getaddrinfo
(
name
.
c_str
(),
NULL
,
&
hints
,
&
res
))
if
(
res
==
nullptr
)
return
""
;
if
(
res
->
h_addr_list
==
nullptr
)
return
""
;
return
""
;
if
(
res
->
h_addrtype
==
AF_INET
)
if
(
res
->
ai_family
==
AF_INET
)
{
{
char
str
[
INET_ADDRSTRLEN
]
=
{
0
};
char
str
[
INET_ADDRSTRLEN
]
=
{
0
};
if
(
inet_ntop
(
AF_INET
,
res
->
h_addr_list
[
0
],
str
,
INET_ADDRSTRLEN
)
==
nullptr
)
if
(
inet_ntop
(
AF_INET
,
&
((
struct
sockaddr_in
*
)
res
->
ai_addr
)
->
sin_addr
,
str
,
INET_ADDRSTRLEN
)
==
nullptr
)
{
freeaddrinfo
(
res
);
return
""
;
return
""
;
}
freeaddrinfo
(
res
);
return
std
::
string
{
str
};
return
std
::
string
{
str
};
}
}
else
if
(
res
->
h_addrtype
==
AF_INET
)
else
if
(
res
->
ai_family
==
AF_INET6
)
{
{
char
str
[
INET6_ADDRSTRLEN
]
=
{
0
};
char
str
[
INET6_ADDRSTRLEN
]
=
{
0
};
if
(
inet_ntop
(
AF_INET6
,
res
->
h_addr_list
[
0
],
str
,
INET6_ADDRSTRLEN
)
==
nullptr
)
if
(
inet_ntop
(
AF_INET6
,
&
((
struct
sockaddr_in6
*
)
res
->
ai_addr
)
->
sin6_addr
,
str
,
INET6_ADDRSTRLEN
)
==
nullptr
)
{
freeaddrinfo
(
res
);
return
""
;
return
""
;
}
freeaddrinfo
(
res
);
return
std
::
string
{
str
};
return
std
::
string
{
str
};
}
}
else
else
{
{
freeaddrinfo
(
res
);
return
""
;
return
""
;
}
}
}
}
...
...
src/utils/yaml_utils.cpp
View file @
b0aef086
...
@@ -146,15 +146,17 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
...
@@ -146,15 +146,17 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
{
{
std
::
string
s
=
GetString
(
node
,
name
);
std
::
string
s
=
GetString
(
node
,
name
);
s
=
io
::
GetHostByName
(
s
);
int
version
=
utils
::
GetIpVersion
(
s
);
int
version
=
utils
::
GetIpVersion
(
s
);
if
(
version
==
6
)
if
(
version
==
6
)
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
, FQDN
or a valid network interface with a IPv4 address"
);
if
(
version
==
4
)
if
(
version
==
4
)
return
s
;
return
s
;
auto
ipFromIf
=
io
::
GetIp4OfInterface
(
s
);
auto
ipFromIf
=
io
::
GetIp4OfInterface
(
s
);
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
, FQDN
or a valid network interface with a IPv4 address"
);
return
ipFromIf
;
return
ipFromIf
;
}
}
...
@@ -162,15 +164,17 @@ std::string GetIp6(const YAML::Node &node, const std::string &name)
...
@@ -162,15 +164,17 @@ std::string GetIp6(const YAML::Node &node, const std::string &name)
{
{
std
::
string
s
=
GetString
(
node
,
name
);
std
::
string
s
=
GetString
(
node
,
name
);
s
=
io
::
GetHostByName
(
s
);
int
version
=
utils
::
GetIpVersion
(
s
);
int
version
=
utils
::
GetIpVersion
(
s
);
if
(
version
==
4
)
if
(
version
==
4
)
FieldError
(
name
,
"must be a valid IPv6 address or a valid network interface with a IPv6 address"
);
FieldError
(
name
,
"must be a valid IPv6 address
, FQDN
or a valid network interface with a IPv6 address"
);
if
(
version
==
6
)
if
(
version
==
6
)
return
s
;
return
s
;
auto
ipFromIf
=
io
::
GetIp6OfInterface
(
s
);
auto
ipFromIf
=
io
::
GetIp6OfInterface
(
s
);
if
(
ipFromIf
.
empty
())
if
(
ipFromIf
.
empty
())
FieldError
(
name
,
"must be a valid IPv6 address or a valid network interface with a IPv6 address"
);
FieldError
(
name
,
"must be a valid IPv6 address
, FQDN
or a valid network interface with a IPv6 address"
);
return
ipFromIf
;
return
ipFromIf
;
}
}
...
@@ -178,6 +182,8 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
...
@@ -178,6 +182,8 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
{
{
std
::
string
s
=
GetString
(
node
,
name
);
std
::
string
s
=
GetString
(
node
,
name
);
s
=
io
::
GetHostByName
(
s
);
int
version
=
utils
::
GetIpVersion
(
s
);
int
version
=
utils
::
GetIpVersion
(
s
);
if
(
version
==
6
||
version
==
4
)
if
(
version
==
6
||
version
==
4
)
return
s
;
return
s
;
...
@@ -187,7 +193,7 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
...
@@ -187,7 +193,7 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
auto
ip6FromIf
=
io
::
GetIp6OfInterface
(
s
);
auto
ip6FromIf
=
io
::
GetIp6OfInterface
(
s
);
if
(
!
ip6FromIf
.
empty
())
if
(
!
ip6FromIf
.
empty
())
return
ip6FromIf
;
return
ip6FromIf
;
FieldError
(
name
,
"must be a valid IP address or a valid network interface with an IP address"
);
FieldError
(
name
,
"must be a valid IP address
, FQDN
or a valid network interface with an IP address"
);
}
}
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