Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
54e9622e
Commit
54e9622e
authored
Dec 30, 2010
by
Mark Olesen
Browse files
ENH: add Foam::domainName(), implemented as per 'hostname -d' from net-tools
parent
da439f54
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/OSspecific/POSIX/POSIX.C
View file @
54e9622e
...
...
@@ -111,16 +111,16 @@ bool Foam::setEnv
Foam
::
word
Foam
::
hostName
(
bool
full
)
{
char
buf
[
256
];
gethostname
(
buf
,
256
);
char
buf
[
128
];
gethostname
(
buf
,
sizeof
(
buf
)
);
// implementation as per hostname from net-tools
if
(
full
)
{
struct
hostent
*
hptr
=
gethostbyname
(
buf
);
if
(
hptr
)
struct
hostent
*
hp
=
gethostbyname
(
buf
);
if
(
hp
)
{
return
hp
tr
->
h_name
;
return
hp
->
h_name
;
}
}
...
...
@@ -128,6 +128,27 @@ Foam::word Foam::hostName(bool full)
}
Foam
::
word
Foam
::
domainName
()
{
char
buf
[
128
];
gethostname
(
buf
,
sizeof
(
buf
));
// implementation as per hostname from net-tools
struct
hostent
*
hp
=
gethostbyname
(
buf
);
if
(
hp
)
{
char
*
p
=
strchr
(
hp
->
h_name
,
'.'
);
if
(
p
)
{
++
p
;
return
p
;
}
}
return
word
::
null
;
}
Foam
::
word
Foam
::
userName
()
{
struct
passwd
*
pw
=
getpwuid
(
getuid
());
...
...
@@ -201,8 +222,8 @@ Foam::fileName Foam::home(const word& userName)
Foam
::
fileName
Foam
::
cwd
()
{
char
buf
[
25
5
];
if
(
getcwd
(
buf
,
255
))
char
buf
[
25
6
];
if
(
getcwd
(
buf
,
sizeof
(
buf
)
))
{
return
buf
;
}
...
...
@@ -957,8 +978,6 @@ bool Foam::ping
const
label
timeOut
)
{
char
*
serverAddress
;
struct
in_addr
*
ptr
;
struct
hostent
*
hostPtr
;
volatile
int
sockfd
;
struct
sockaddr_in
destAddr
;
// will hold the destination addr
...
...
@@ -968,15 +987,13 @@ bool Foam::ping
{
FatalErrorIn
(
"Foam::ping(const word&,
const label
)"
"Foam::ping(const word&,
...
)"
)
<<
"gethostbyname error "
<<
h_errno
<<
" for host "
<<
destName
<<
abort
(
FatalError
);
}
// Get first of the SLL of addresses
serverAddress
=
*
(
hostPtr
->
h_addr_list
);
ptr
=
reinterpret_cast
<
struct
in_addr
*>
(
serverAddress
);
addr
=
ptr
->
s_addr
;
addr
=
(
reinterpret_cast
<
struct
in_addr
*>
(
*
(
hostPtr
->
h_addr_list
)))
->
s_addr
;
// Allocate socket
sockfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
...
...
@@ -990,7 +1007,7 @@ bool Foam::ping
}
// Fill sockaddr_in structure with dest address and port
memset
(
reinterpret_cast
<
char
*>
(
&
destAddr
),
'\0'
,
sizeof
(
destAddr
));
memset
(
reinterpret_cast
<
char
*>
(
&
destAddr
),
'\0'
,
sizeof
(
destAddr
));
destAddr
.
sin_family
=
AF_INET
;
destAddr
.
sin_port
=
htons
(
ushort
(
destPort
));
destAddr
.
sin_addr
.
s_addr
=
addr
;
...
...
src/OpenFOAM/include/OSspecific.H
View file @
54e9622e
...
...
@@ -67,10 +67,13 @@ string getEnv(const word&);
//- Set an environment variable
bool
setEnv
(
const
word
&
name
,
const
string
&
value
,
const
bool
overwrite
);
//- Return the system's host name
// Optionally the full name
reported from gethostbyname
//- Return the system's host name
, as per hostname(1)
// Optionally
with
the full name
(as per the '-f' option)
word
hostName
(
const
bool
full
=
false
);
//- Return the system's domain name, as per hostname(1) with the '-d' option
word
domainName
();
//- Return the user's login name
word
userName
();
...
...
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