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
77c747a8
Commit
77c747a8
authored
May 17, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/SocketAddress: add method GetPort()
parent
907fb257
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
SocketAddress.cxx
src/net/SocketAddress.cxx
+32
-1
SocketAddress.hxx
src/net/SocketAddress.hxx
+10
-1
No files found.
src/net/SocketAddress.cxx
View file @
77c747a8
/*
* Copyright (C) 2012-201
5
Max Kellermann <max.kellermann@gmail.com>
* Copyright (C) 2012-201
7
Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -27,12 +27,43 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "SocketAddress.hxx"
#include <string.h>
#ifdef HAVE_TCP
#ifdef WIN32
#include <ws2tcpip.h>
#else
#include <netinet/in.h>
#endif
#endif
bool
SocketAddress
::
operator
==
(
SocketAddress
other
)
const
noexcept
{
return
size
==
other
.
size
&&
memcmp
(
address
,
other
.
address
,
size
)
==
0
;
}
#ifdef HAVE_TCP
unsigned
SocketAddress
::
GetPort
()
const
{
if
(
IsNull
())
return
0
;
switch
(
GetFamily
())
{
case
AF_INET
:
return
ntohs
(((
const
struct
sockaddr_in
*
)(
const
void
*
)
address
)
->
sin_port
);
case
AF_INET6
:
return
ntohs
(((
const
struct
sockaddr_in6
*
)(
const
void
*
)
address
)
->
sin6_port
);
default
:
return
0
;
}
}
#endif
src/net/SocketAddress.hxx
View file @
77c747a8
/*
* Copyright (C) 2012-201
5
Max Kellermann <max.kellermann@gmail.com>
* Copyright (C) 2012-201
7
Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -30,6 +30,7 @@
#ifndef SOCKET_ADDRESS_HXX
#define SOCKET_ADDRESS_HXX
#include "Features.hxx"
#include "Compiler.h"
#include <cstddef>
...
...
@@ -92,6 +93,14 @@ public:
return
GetFamily
()
!=
AF_UNSPEC
;
}
#ifdef HAVE_TCP
/**
* Extract the port number. Returns 0 if not applicable.
*/
gcc_pure
unsigned
GetPort
()
const
;
#endif
gcc_pure
bool
operator
==
(
const
SocketAddress
other
)
const
noexcept
;
...
...
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