public static Attribute BuildChangeRequest(bool changeIp, bool changePort) { return(new() { Type = AttributeType.ChangeRequest, Length = 4, Value = new ChangeRequestAttribute { ChangeIp = changeIp, ChangePort = changePort } }); }
/* * public STUN( int ourport, GotExternalAddress callback ) * { * LogFile.WriteLine( "STUN( ourport: " + ourport + " callback: " + callback.Target + "." + callback.Method.Name ); * * INetworkImplementation level1net = NetworkImplementationFactory.CreateNewInstance(); * level1net.ConnectAsClient( new IPAddress( stunser ), serverinfo.port * * UdpClient udpclient = new UdpClient( StunServerHostname, StunServerPort ); * byte[] bytes = CreateSTUNBindingRequestPacket(); * udpclient.Send( bytes, bytes.Length ); * } */ byte[] CreateSTUNBindingRequestPacket() { Request request = MessageFactory.CreateBindingRequest(); ChangeRequestAttribute changeRequest = (ChangeRequestAttribute)request.GetAttribute(net.voxx.stun4cs.Attribute.CHANGE_REQUEST); changeRequest.SetChangeIpFlag(false); changeRequest.SetChangePortFlag(false); TransactionID transactionID = TransactionID.CreateTransactionID(); request.SetTransactionID(transactionID.GetTransactionID()); byte[] bytes = request.Encode(); return(bytes); }