public SIPEndPoint ToSIPEndPoint() { if (IPSocket.IsIPSocket(Host) || IPSocket.IsIPAddress(Host)) { if (Host.IndexOf(":") != -1) { return(new SIPEndPoint(Protocol, IPSocket.GetIPEndPoint(Host))); } else { if (Protocol == SIPProtocolsEnum.tls) { return(new SIPEndPoint(Protocol, IPSocket.GetIPEndPoint(Host + ":" + m_defaultSIPTLSPort))); } else { return(new SIPEndPoint(Protocol, IPSocket.GetIPEndPoint(Host + ":" + m_defaultSIPPort))); } } } else { return(null); } }
private void SendRTPPacket(string sourceSocket, string destinationSocket) { try { //logger.Debug("Attempting to send RTP packet from " + sourceSocket + " to " + destinationSocket + "."); Log("Attempting to send RTP packet from " + sourceSocket + " to " + destinationSocket + "."); IPEndPoint sourceEP = IPSocket.GetIPEndPoint(sourceSocket); IPEndPoint destEP = IPSocket.GetIPEndPoint(destinationSocket); RTPPacket rtpPacket = new RTPPacket(80); rtpPacket.Header.SequenceNumber = (UInt16)6500; rtpPacket.Header.Timestamp = 100000; UDPPacket udpPacket = new UDPPacket(sourceEP.Port, destEP.Port, rtpPacket.GetBytes()); IPv4Header ipHeader = new IPv4Header(ProtocolType.Udp, Crypto.GetRandomInt(6), sourceEP.Address, destEP.Address); IPv4Packet ipPacket = new IPv4Packet(ipHeader, udpPacket.GetBytes()); byte[] data = ipPacket.GetBytes(); Socket rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); rawSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1); rawSocket.SendTo(data, destEP); } catch (Exception excp) { logger.Error("Exception SendRTPPacket. " + excp.Message); } }
public SIPResponse GetOkResponse(SIPRequest sipRequest, SIPEndPoint localSIPEndPoint, string contentType, string messageBody) { try { SIPResponse okResponse = new SIPResponse(SIPResponseStatusCodesEnum.Ok, null, sipRequest.LocalSIPEndPoint); SIPHeader requestHeader = sipRequest.Header; okResponse.Header = new SIPHeader(new SIPContactHeader(null, new SIPURI(sipRequest.URI.Scheme, localSIPEndPoint)), requestHeader.From, requestHeader.To, requestHeader.CSeq, requestHeader.CallId); if (m_contactIPAddress != null) { IPEndPoint contactEP = IPSocket.GetIPEndPoint(okResponse.Header.Contact.First().ContactURI.Host); contactEP.Address = m_contactIPAddress; okResponse.Header.Contact.First().ContactURI.Host = contactEP.ToString(); } okResponse.Header.To.ToTag = m_localTag; okResponse.Header.CSeqMethod = requestHeader.CSeqMethod; okResponse.Header.Vias = requestHeader.Vias; okResponse.Header.Server = m_sipServerAgent; okResponse.Header.MaxForwards = Int32.MinValue; okResponse.Header.RecordRoutes = requestHeader.RecordRoutes; okResponse.Body = messageBody; okResponse.Header.ContentType = contentType; okResponse.Header.ContentLength = (messageBody != null) ? messageBody.Length : 0; return(okResponse); } catch (Exception excp) { logger.Error("Exception GetOkResponse. " + excp.Message); throw excp; } }
/// <summary> /// Initialises the SIP transport layer. /// </summary> public async Task InitialiseSIP() { if (_isIntialised == false) { await Task.Run(() => { _isIntialised = true; if (String.IsNullOrEmpty(m_DnsServer) == false) { // Use a custom DNS server. m_DnsServer = m_DnsServer.Contains(":") ? m_DnsServer : m_DnsServer + ":53"; DNSManager.SetDNSServers(new List <IPEndPoint> { IPSocket.GetIPEndPoint(m_DnsServer) }); } // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); if (m_sipSocketsNode != null) { // Set up the SIP channels based on the app.config file. List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipSocketsNode); m_sipTransport.AddSIPChannel(sipChannels); } else { // Use default options to set up a SIP channel. int port = FreePort.FindNextAvailableUDPPort(_defaultSIPUdpPort); var sipChannel = new SIPUDPChannel(new IPEndPoint(_defaultLocalAddress, port)); m_sipTransport.AddSIPChannel(sipChannel); } }); // Wire up the transport layer so incoming SIP requests have somewhere to go. m_sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; // Log all SIP packets received to a log file. m_sipTransport.SIPRequestInTraceEvent += (localSIPEndPoint, endPoint, sipRequest) => { _sipTraceLogger.Debug("Request Received : " + localSIPEndPoint + "<-" + endPoint + "\r\n" + sipRequest.ToString()); }; m_sipTransport.SIPRequestOutTraceEvent += (localSIPEndPoint, endPoint, sipRequest) => { _sipTraceLogger.Debug("Request Sent: " + localSIPEndPoint + "->" + endPoint + "\r\n" + sipRequest.ToString()); }; m_sipTransport.SIPResponseInTraceEvent += (localSIPEndPoint, endPoint, sipResponse) => { _sipTraceLogger.Debug("Response Received: " + localSIPEndPoint + "<-" + endPoint + "\r\n" + sipResponse.ToString()); }; m_sipTransport.SIPResponseOutTraceEvent += (localSIPEndPoint, endPoint, sipResponse) => { _sipTraceLogger.Debug("Response Sent: " + localSIPEndPoint + "->" + endPoint + "\r\n" + sipResponse.ToString()); }; } }
public string ToResultsString() { IPEndPoint remoteEndPoint = IPSocket.GetIPEndPoint(RemoteEndPoint); string results = "SourceIPAddress = " + remoteEndPoint.Address + "\r\n" + "SourceIPPort = " + remoteEndPoint.Port + "\r\n" + "StartTime = " + SampleStartTime.ToString("dd MMM yyyy HH:mm:ss:fff") + "\r\n" + "EndTime = " + SampleEndTime.ToString("dd MMM yyyy HH:mm:ss:fff") + "\r\n" + "Duration = " + SampleEndTime.Subtract(SampleStartTime).TotalSeconds.ToString("0.###") + "(s)\r\n" + "TotalPackets = " + TotalPackets + "\r\n" + "OutOfOrder = " + OutOfOrder + "\r\n" + //"AlreadyDropped = " + OutsideWindow + "\r\n" + "JitterDiscards = " + JitterDiscards + "\r\n" + "JitterMaximum = " + JitterMaximum + "(ms)\r\n" + "JitterAverage = " + JitterAverage.ToString("0.##") + "(ms)\r\n"; return(results); }
public void SendSIPRequest(SIPRequest sipRequest, string dstSocket) { //ResetSIPResponse(); if (sipRequest.Method == SIPMethodsEnum.INVITE) { //m_inviteRequest = sipRequest; UACInviteTransaction inviteTransaction = m_sipTransport.CreateUACTransaction(sipRequest, IPSocket.GetIPEndPoint(dstSocket), m_sipTransport.GetTransportContact(null), SIPProtocolsEnum.UDP); inviteTransaction.UACInviteTransactionInformationResponseReceived += new SIPTransactionResponseReceivedDelegate(TransactionInformationResponseReceived); inviteTransaction.UACInviteTransactionFinalResponseReceived += new SIPTransactionResponseReceivedDelegate(TransactionFinalResponseReceived); m_sipTransport.SendSIPReliable(inviteTransaction); } else { SIPNonInviteTransaction sipTransaction = m_sipTransport.CreateNonInviteTransaction(sipRequest, IPSocket.GetIPEndPoint(dstSocket), m_sipTransport.GetTransportContact(null), SIPProtocolsEnum.UDP); sipTransaction.NonInviteTransactionFinalResponseReceived += new SIPTransactionResponseReceivedDelegate(TransactionFinalResponseReceived); m_sipTransport.SendSIPReliable(sipTransaction); } }