Add FBPortForwarding source code

Summary:
See FBPortForwarding/README.md for an explanation of what this is.
It's required for the upcoming support for physical iOS devices.

To simplify development of the JS app, We're going to bundle the pre-built PortForwardingMacApp
inside the repo, and inside the electron app (static/PortForwardingMacApp.app).
Adding this source so users can build it from source if they choose to.

Reviewed By: danielbuechele

Differential Revision: D13276022

fbshipit-source-id: 99b18e0412cf443bb4a67eb4846cc780e0014de1
This commit is contained in:
John Knox
2018-12-03 11:32:37 -08:00
committed by Facebook Github Bot
parent 98110bc230
commit 8d93946739
11 changed files with 515 additions and 96 deletions

View File

@@ -0,0 +1,34 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <Foundation/Foundation.h>
#import <FKPortForwarding/FKPortForwardingClient.h>
static const char kPortForwardParamPrefix[] = "-portForward=";
static const char kMultiplexChannelPortParamPrefix[] = "-multiplexChannelPort=";
static BOOL prefix(const char *pre, const char *str) {
return strncmp(pre, str, strlen(pre)) == 0;
}
int main(int argc, char *argv[])
{
long connectionsPort = 8081;
long multiplexPort = 8025;
for (int i = 1; i < argc; ++i) {
if (prefix(kPortForwardParamPrefix, argv[i])) {
connectionsPort = strtol(argv[i] + strlen(kPortForwardParamPrefix), NULL, 10);
} else if (prefix(kMultiplexChannelPortParamPrefix, argv[i])) {
multiplexPort = strtol(argv[i] + strlen(kMultiplexChannelPortParamPrefix), NULL, 10);
}
}
FKPortForwardingClient *client = [FKPortForwardingClient new];
[client forwardConnectionsToPort:connectionsPort];
[client connectToMultiplexingChannelOnPort:multiplexPort];
[[NSRunLoop currentRunLoop] run];
client = nil;
return 0;
}