Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
86be1fc6
Commit
86be1fc6
authored
Apr 19, 2018
by
honfika
Committed by
GitHub
Apr 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #415 from antrv/feature/opt-getprocessid
Additonal optimizations in GetProcessIdByLocalPort
parents
78297c2b
42cbf631
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
17 deletions
+19
-17
NativeMethods.Tcp.cs
Titanium.Web.Proxy/Helpers/NativeMethods.Tcp.cs
+4
-15
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+15
-2
No files found.
Titanium.Web.Proxy/Helpers/NativeMethods.Tcp.cs
View file @
86be1fc6
...
...
@@ -37,9 +37,9 @@ namespace Titanium.Web.Proxy.Helpers
{
public
TcpState
state
;
public
uint
localAddr
;
public
TcpPort
localPort
;
public
uint
localPort
;
// in network byte order (order of bytes - 1,0,3,2)
public
uint
remoteAddr
;
public
TcpPort
remotePort
;
public
uint
remotePort
;
// in network byte order (order of bytes - 1,0,3,2)
public
int
owningPid
;
}
...
...
@@ -51,23 +51,12 @@ namespace Titanium.Web.Proxy.Helpers
{
public
fixed
byte
localAddr
[
16
];
public
uint
localScopeId
;
public
TcpPort
localPort
;
public
uint
localPort
;
// in network byte order (order of bytes - 1,0,3,2)
public
fixed
byte
remoteAddr
[
16
];
public
uint
remoteScopeId
;
public
TcpPort
remotePort
;
public
uint
remotePort
;
// in network byte order (order of bytes - 1,0,3,2)
public
TcpState
state
;
public
int
owningPid
;
}
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
TcpPort
{
public
byte
port1
;
public
byte
port2
;
public
byte
port3
;
public
byte
port4
;
public
int
Port
=>
(
port1
<<
8
)
+
port2
+
(
port3
<<
24
)
+
(
port4
<<
16
);
}
}
}
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
86be1fc6
...
...
@@ -37,6 +37,7 @@ namespace Titanium.Web.Proxy.Helpers
0
)
==
0
)
{
int
rowCount
=
*(
int
*)
tcpTable
;
uint
portInNetworkByteOrder
=
ToNetworkByteOrder
((
uint
)
localPort
);
if
(
ipVersion
==
IpVersion
.
Ipv4
)
{
...
...
@@ -44,7 +45,7 @@ namespace Titanium.Web.Proxy.Helpers
for
(
int
i
=
0
;
i
<
rowCount
;
++
i
)
{
if
(
rowPtr
->
localPort
.
Port
==
localPort
)
if
(
rowPtr
->
localPort
==
portInNetworkByteOrder
)
{
return
rowPtr
->
owningPid
;
}
...
...
@@ -58,7 +59,7 @@ namespace Titanium.Web.Proxy.Helpers
for
(
int
i
=
0
;
i
<
rowCount
;
++
i
)
{
if
(
rowPtr
->
localPort
.
Port
==
localPort
)
if
(
rowPtr
->
localPort
==
portInNetworkByteOrder
)
{
return
rowPtr
->
owningPid
;
}
...
...
@@ -80,6 +81,18 @@ namespace Titanium.Web.Proxy.Helpers
return
0
;
}
/// <summary>
/// Converts 32-bit integer from native byte order (little-endian)
/// to network byte order for port,
/// switches 0th and 1st bytes, and 2nd and 3rd bytes
/// </summary>
/// <param name="port"></param>
/// <returns></returns>
private
static
uint
ToNetworkByteOrder
(
uint
port
)
{
return
((
port
>>
8
)
&
0x00FF00FFu
)
|
((
port
<<
8
)
&
0xFF00FF00u
);
}
/// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix
...
...
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