STUN Client | Attributes

Every time a server sends a message to client, as a response message to a request binding, the STUN message contains a list of attributes with information about the response.

 

You can access to these attributes, using the TsgcSTUN_Message class and accessing to Attributes properties, which contains a list of TsgcSTUN_Attribute with useful information.

 


private void OnSTUNResponseSuccess(TObject * Sender, const TsgcSocketConnection *aSocket, 
  const TsgcSTUN_Message *aMessage, const sgcSTUN_ResponseBinding *aBinding)
{
  DoLog("#binding: " + aBinding->RemoteIP + ":" + IntToStr(aBinding->RemotePort));
  
  for (int i = 0; i < aMessage->Attributes->Count; i++)
  {
    switch (TsgcSTUN_Attribute(aMessage.Attributes.Items[i])->AttributeType)
      stmaFingerprint:
        DoLog("#fingerprint: " + IntToStr(dynamic_cast<TsgcSTUN_Attribute_FINGERPRINT*>
          (aMessage->Attributes.Items[i])->Fingerprint));
      stmaSoftware:
        DoLog("#software: " + dynamic_cast<TsgcSTUN_Attribute_SOFTWARE>
          (aMessage->Attributes->Items[i])->Software);
      stmaResponse_Origin:
        DoLog("#response_origin: " + dynamic_cast<TsgcSTUN_Attribute_RESPONSE_ORIGIN*>
          (aMessage->Attributes->Items[i])->Address + ":" +
          IntToStr(dynamic_cast<TsgcSTUN_Attribute_RESPONSE_ORIGIN*>(aMessage->Attributes->Items
          [i])->Port));
    end;
  }
}