createBindingRequestWithChangeRequest static method
Creates a binding request message with CHANGE-REQUEST attribute
changeIP
- Request the server to send the response from a different IP address
changePort
- Request the server to send the response from a different port
Implementation
static StunMessage createBindingRequestWithChangeRequest({
bool changeIP = false,
bool changePort = false,
}) {
final transactionId = List<int>.generate(12, (_) => _random.nextInt(256));
final attributes = <int, Uint8List>{};
// Create CHANGE-REQUEST attribute (4 bytes)
final changeRequestBytes = Uint8List(4);
final changeRequestBuffer = ByteData.view(changeRequestBytes.buffer);
// Set the appropriate bits for change IP (bit 2) and change port (bit 1)
int flags = 0;
if (changeIP) flags |= 0x04;
if (changePort) flags |= 0x02;
changeRequestBuffer.setUint32(0, flags);
attributes[StunAttribute.changeRequest] = changeRequestBytes;
return StunMessage(StunMessageType.bindingRequest, transactionId, attributes);
}