Пример #1
0
        public List <IPEndPoint> GetPortBroadcast(Mapping arg)
        {
            List <IPEndPoint> list    = new List <IPEndPoint>();
            RpcCallMessage    getport = new RpcCallMessage(RpcProgram.Portmapper, Consts.PortmapperVersion,
                                                           (uint)PortmapperProcedure.GETPORT, arg.ToBytes());
            //if (!Client.Connected) Client.Connect();
            //Client.Call(getport);
            //Dictionary<EndPoint, RpcReplyMessage> reply = Client.RecieveBroadcast();
            Dictionary <EndPoint, RpcReplyMessage> reply = Client.Call(getport);

            foreach (var r in reply)
            {
                if (r.Value.AcceptState == ReplyAcceptState.SUCCESS)
                {
                    int       port = NetUtils.ToIntFromBigEndian(r.Value.Result);
                    IPAddress ad   = ((IPEndPoint)r.Key).Address;
                    if (port != 0)
                    {
                        list.Add(new IPEndPoint(((IPEndPoint)r.Key).Address, port));
                    }
                }
            }

            return(list);
        }
Пример #2
0
        public uint GetPort(Mapping arg)
        {
            RpcCallMessage getport = new RpcCallMessage(RpcProgram.Portmapper,
                                                        Consts.PortmapperVersion, (uint)PortmapperProcedure.GETPORT,
                                                        arg.ToBytes());
            Dictionary <EndPoint, RpcReplyMessage> replies = Client.Call(getport);

            foreach (var reply in replies.Values)
            {
                if (reply.AcceptState == ReplyAcceptState.SUCCESS)
                {
                    uint port = (uint)NetUtils.ToIntFromBigEndian(reply.Result);
                    if (port == 0)
                    {
                        throw new Exception("Portmapper. Program " + arg.Program +
                                            " version " + arg.Version + " not available to " +
                                            arg.Protocol.ToString() + ".");
                    }
                    else
                    {
                        return(port);
                    }
                }
            }
            throw new Exception("Portmapper. No success answer or no answer.");
        }