示例#1
0
 public TunnelOneInOneOut(UInt16 port1, UInt16 port2)
 {
     if (port1 == port2)
     {
         throw new ArgumentException(String.Format("port1 and port2 ({0}) cannot be the same, you must have wanted a TunnelOnSinglePort", port1));
     }
     this.port1       = port1;
     this.port2       = port2;
     this.fullPortSet = new SortedNumberSet();
     this.fullPortSet.Add(port1);
     this.fullPortSet.Add(port2);
 }
示例#2
0
        public static Int32 Run(Options options, List <String> nonOptionArgs)
        {
            log = Console.Out;

            //
            // Options
            //
            if (nonOptionArgs.Count < 2)
            {
                return(options.ErrorAndUsage("Not enough arguments"));
            }

            String clientSideConnector = nonOptionArgs[0];
            String listenPortsString   = nonOptionArgs[1];

            {
                Proxy  proxy;
                String ipOrHostAndPort = Proxy.StripAndParseProxies(clientSideConnector, DnsPriority.IPv4ThenIPv6, out proxy);
                UInt16 port;
                String ipOrHost = EndPoints.SplitIPOrHostAndPort(ipOrHostAndPort, out port);
                server = new InternetHost(ipOrHost, port, DnsPriority.IPv4ThenIPv6, proxy);
            }
            SortedNumberSet listenPortSet = PortSet.ParsePortSet(listenPortsString);

            SelectServer selectServer = new SelectServer(false, new Buf(options.readBufferSize.ArgValue));
            IPAddress    listenIP     = IPAddress.Any;

            foreach (var port in listenPortSet)
            {
                IPEndPoint listenEndPoint = new IPEndPoint(listenIP, port);
                Socket     socket         = new Socket(listenEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                socket.Bind(listenEndPoint);
                socket.Listen(options.socketBackLog.ArgValue);
                selectServer.control.AddListenSocket(socket, AcceptCallback);
            }

            selectServer.Run();
            return(0);
        }
示例#3
0
        public static SortedNumberSet ParsePortSet(String ports, UInt32 offset, UInt32 limit)
        {
            if (limit < offset)
            {
                throw new FormatException(String.Format("limit ({0}) cannot be less then offset ({1})", limit, offset));
            }

            SortedNumberSet portSet = new SortedNumberSet();

            UInt32 lastStartOffset = offset;

            while (true)
            {
                if (offset >= limit)
                {
                    if (offset > lastStartOffset)
                    {
                        String portString = ports.Substring((int)lastStartOffset, (int)(offset - lastStartOffset));
                        UInt16 port;
                        if (!UInt16Parser.TryParse(portString, out port))
                        {
                            throw new FormatException(String.Format("Failed to parse '{0}' as a port", portString));
                        }
                        portSet.Add(port);
                    }

                    return(portSet);
                }

                Char c = ports[(int)offset];
                if (c == ',')
                {
                    String portString = ports.Substring((int)lastStartOffset, (int)(offset - lastStartOffset));
                    UInt16 port;
                    if (!UInt16Parser.TryParse(portString, out port))
                    {
                        throw new FormatException(String.Format("Failed to parse '{0}' as a port", portString));
                    }
                    portSet.Add(port);
                    offset++;
                    lastStartOffset = offset;
                }
                else if (c == '-')
                {
                    throw new NotImplementedException();

                    /*
                     * String portString = ports.Substring((int)lastStartOffset, (int)(offset - lastStartOffset));
                     * UInt16 port;
                     * if (!UInt16.TryParse(portString, out port))
                     * {
                     *  throw new FormatException(String.Format("Failed to parse '{0}' as a port", portString));
                     * }
                     * portSet.Add(port);
                     */
                }
                else
                {
                    offset++;
                }
            }
        }
示例#4
0
 public TunnelOnSinglePort(UInt16 port)
 {
     this.port        = port;
     this.fullPortSet = new SortedNumberSet();
     this.fullPortSet.Add(port);
 }