Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
0ebba73c
Commit
0ebba73c
authored
Aug 20, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/SocketDescriptor: add method GetPeerCredentials()
parent
50c73379
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
SocketDescriptor.cxx
src/net/SocketDescriptor.cxx
+26
-0
SocketDescriptor.hxx
src/net/SocketDescriptor.hxx
+14
-0
No files found.
src/net/SocketDescriptor.cxx
View file @
0ebba73c
...
@@ -220,6 +220,32 @@ SocketDescriptor::GetError()
...
@@ -220,6 +220,32 @@ SocketDescriptor::GetError()
:
errno
;
:
errno
;
}
}
size_t
SocketDescriptor
::
GetOption
(
int
level
,
int
name
,
void
*
value
,
size_t
size
)
const
{
assert
(
IsDefined
());
socklen_t
size2
=
size
;
return
getsockopt
(
fd
,
level
,
name
,
(
char
*
)
value
,
&
size2
)
==
0
?
size2
:
0
;
}
#ifdef HAVE_STRUCT_UCRED
struct
ucred
SocketDescriptor
::
GetPeerCredentials
()
const
noexcept
{
struct
ucred
cred
;
if
(
GetOption
(
SOL_SOCKET
,
SO_PEERCRED
,
&
cred
,
sizeof
(
cred
))
<
sizeof
(
cred
))
cred
.
pid
=
-
1
;
return
cred
;
}
#endif
#ifdef _WIN32
#ifdef _WIN32
bool
bool
...
...
src/net/SocketDescriptor.hxx
View file @
0ebba73c
...
@@ -150,6 +150,20 @@ public:
...
@@ -150,6 +150,20 @@ public:
int
GetError
();
int
GetError
();
/**
* @return the value size or 0 on error
*/
size_t
GetOption
(
int
level
,
int
name
,
void
*
value
,
size_t
size
)
const
;
#ifdef HAVE_STRUCT_UCRED
/**
* Receive peer credentials (SO_PEERCRED). On error, the pid
* is -1.
*/
gcc_pure
struct
ucred
GetPeerCredentials
()
const
noexcept
;
#endif
bool
SetOption
(
int
level
,
int
name
,
const
void
*
value
,
size_t
size
);
bool
SetOption
(
int
level
,
int
name
,
const
void
*
value
,
size_t
size
);
bool
SetBoolOption
(
int
level
,
int
name
,
bool
_value
)
{
bool
SetBoolOption
(
int
level
,
int
name
,
bool
_value
)
{
...
...
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