Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STUN Server null reference exception fix #1337

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0c3e3cc
fix stream retrieval bug
ispysoftware Oct 31, 2024
86973dc
Merge branch 'sipsorcery-org:master' into master
ispysoftware Nov 5, 2024
1a8b920
add translations for tray app and installer
ispysoftware Nov 10, 2024
32a5d87
Merge branch 'master' of https://github.com/ispysoftware/sipsorcery
ispysoftware Nov 11, 2024
e484d9c
fix for ptz serialization
ispysoftware Nov 15, 2024
94160b2
Merge branch 'master' of https://github.com/ispysoftware/sipsorcery
ispysoftware Nov 21, 2024
ed8cd70
fix bug in g722 codec
ispysoftware Nov 21, 2024
de318f6
Only get stream format once
ispysoftware Dec 1, 2024
c49c0c9
revert
ispysoftware Dec 1, 2024
8e7b251
Optimise SendVideo and SendAudio (only get SendingFormat once)
ispysoftware Dec 2, 2024
44c733c
Optimise SendVideo and SendAudio (only get SendingFormat once)
ispysoftware Nov 21, 2024
66c7568
remove turn folder
ispysoftware Dec 2, 2024
e1748d8
Merge branch 'Optimise' of https://github.com/ispysoftware/sipsorcery…
ispysoftware Dec 2, 2024
dc1aa26
Remove turn folder
ispysoftware Dec 2, 2024
52076bc
Move gather timeout to config
ispysoftware Dec 2, 2024
ebc9a43
Fix rounding bug in SendAudioFrame
ispysoftware Dec 6, 2024
3948ae2
Merge pull request #1 from ispysoftware/Optimise
ispysoftware Dec 6, 2024
c763db3
Merge branch 'sipsorcery-org:master' into master
ispysoftware Dec 6, 2024
1c65a2d
Remove comment marker
ispysoftware Dec 8, 2024
8eb5837
remove comment marker
ispysoftware Dec 8, 2024
3296e02
Merge branch 'sipsorcery-org:master' into master
ispysoftware Dec 17, 2024
dca7447
Check for null
ispysoftware Dec 17, 2024
ae9c22c
Fix bug with HasVideo and HasAudio
ispysoftware Dec 30, 2024
1d6755e
Merge pull request #2 from ispysoftware/Optimise
ispysoftware Dec 30, 2024
f88dab4
Merge branch 'sipsorcery-org:master' into master
ispysoftware Dec 30, 2024
2e79aa4
Merge branch 'sipsorcery-org:master' into master
ispysoftware Jan 1, 2025
3756b05
Merge branch 'sipsorcery-org:master' into master
ispysoftware Jan 16, 2025
1184e8b
Merge branch 'sipsorcery-org:master' into master
ispysoftware Jan 26, 2025
a8050a6
Fix for allocate requests into the STUN server resulting in null refe…
ispysoftware Feb 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions src/net/STUN/STUNServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,49 +206,50 @@ public void STUNSecondaryReceived(IPEndPoint localEndPoint, IPEndPoint receivedE

private STUNMessage GetResponse(IPEndPoint receivedEndPoint, STUNMessage stunRequest, bool primary)
{
if (stunRequest.Header.MessageType == STUNMessageTypesEnum.BindingRequest)
switch(stunRequest.Header.MessageType)
{
STUNMessage stunResponse = new STUNMessage();
stunResponse.Header.MessageType = STUNMessageTypesEnum.BindingSuccessResponse;
stunResponse.Header.TransactionId = stunRequest.Header.TransactionId;

// Add MappedAddress attribute to indicate the socket the request was received from.
STUNAddressAttribute mappedAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.MappedAddress, receivedEndPoint.Port, receivedEndPoint.Address);
stunResponse.Attributes.Add(mappedAddressAtt);
stunResponse.AddXORMappedAddressAttribute(receivedEndPoint.Address, receivedEndPoint.Port);//Compatible with the client code

// Add SourceAddress attribute to indicate the socket used to send the response.
if (primary)
{
STUNAddressAttribute sourceAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.SourceAddress, m_primaryEndPoint.Port, m_primaryEndPoint.Address);
stunResponse.Attributes.Add(sourceAddressAtt);
}
else
{
STUNAddressAttribute sourceAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.SourceAddress, m_secondaryEndPoint.Port, m_secondaryEndPoint.Address);
stunResponse.Attributes.Add(sourceAddressAtt);
}
case STUNMessageTypesEnum.BindingRequest:
STUNMessage stunResponse = new STUNMessage();
stunResponse.Header.MessageType = STUNMessageTypesEnum.BindingSuccessResponse;
stunResponse.Header.TransactionId = stunRequest.Header.TransactionId;

// Add MappedAddress attribute to indicate the socket the request was received from.
STUNAddressAttribute mappedAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.MappedAddress, receivedEndPoint.Port, receivedEndPoint.Address);
stunResponse.Attributes.Add(mappedAddressAtt);
stunResponse.AddXORMappedAddressAttribute(receivedEndPoint.Address, receivedEndPoint.Port);//Compatible with the client code

// Add SourceAddress attribute to indicate the socket used to send the response.
if (primary)
{
STUNAddressAttribute sourceAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.SourceAddress, m_primaryEndPoint.Port, m_primaryEndPoint.Address);
stunResponse.Attributes.Add(sourceAddressAtt);
}
else
{
STUNAddressAttribute sourceAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.SourceAddress, m_secondaryEndPoint.Port, m_secondaryEndPoint.Address);
stunResponse.Attributes.Add(sourceAddressAtt);
}

// Add ChangedAddress attribute to indicate the servers alternative socket.
if (primary)
{
STUNAddressAttribute changedAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.ChangedAddress, m_secondaryEndPoint.Port, m_secondaryEndPoint.Address);
stunResponse.Attributes.Add(changedAddressAtt);
}
else
{
STUNAddressAttribute changedAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.ChangedAddress, m_primaryEndPoint.Port, m_primaryEndPoint.Address);
stunResponse.Attributes.Add(changedAddressAtt);
}
// Add ChangedAddress attribute to indicate the servers alternative socket.
if (primary)
{
STUNAddressAttribute changedAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.ChangedAddress, m_secondaryEndPoint.Port, m_secondaryEndPoint.Address);
stunResponse.Attributes.Add(changedAddressAtt);
}
else
{
STUNAddressAttribute changedAddressAtt = new STUNAddressAttribute(STUNAttributeTypesEnum.ChangedAddress, m_primaryEndPoint.Port, m_primaryEndPoint.Address);
stunResponse.Attributes.Add(changedAddressAtt);
}

//Console.WriteLine(stunResponse.ToString());
//Console.WriteLine(stunResponse.ToString());

//byte[] stunResponseBuffer = stunResponse.ToByteBuffer();
//byte[] stunResponseBuffer = stunResponse.ToByteBuffer();

return stunResponse;
return stunResponse;
default://Allocate not supported - this is a STUN server only not a full TURN server
throw new ApplicationException("Unsupported MessageType " + stunRequest.Header.MessageType);
}

return null;
}

public void Stop()
Expand Down