{"id":13842205,"url":"https://github.com/marv2097/siprocket","last_synced_at":"2025-07-11T14:31:14.750Z","repository":{"id":41497633,"uuid":"75967341","full_name":"marv2097/siprocket","owner":"marv2097","description":"Fast SIP and SDP Parser","archived":false,"fork":false,"pushed_at":"2022-08-23T16:40:07.000Z","size":25,"stargazers_count":70,"open_issues_count":1,"forks_count":21,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-05T17:30:53.754Z","etag":null,"topics":["parse","sdp","sip","sip-headers","sip-messages"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marv2097.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-08T19:11:28.000Z","updated_at":"2024-02-27T22:10:27.000Z","dependencies_parsed_at":"2022-08-28T11:51:44.771Z","dependency_job_id":null,"html_url":"https://github.com/marv2097/siprocket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marv2097%2Fsiprocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marv2097%2Fsiprocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marv2097%2Fsiprocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marv2097%2Fsiprocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marv2097","download_url":"https://codeload.github.com/marv2097/siprocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225729902,"owners_count":17515186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parse","sdp","sip","sip-headers","sip-messages"],"created_at":"2024-08-04T17:01:29.377Z","updated_at":"2024-11-21T12:31:01.896Z","avatar_url":"https://github.com/marv2097.png","language":"Go","funding_links":[],"categories":["Developer Resources","Go"],"sub_categories":["Go Libraries"],"readme":"# siprocket\nFast SIP and SDP Parser\n\n![Alt](https://travis-ci.org/marv2097/siprocket.svg?branch=master \"Travis Build\")\n\n\nsiprocket is intended for Monitoring applications that need to parse SIP messages on the fly. It allows fast and structured access to the most commonly needed fields from both the SIP header and SDP payload. While intended for use in packet capture systems it could also be adapted to SIP Client and Server tasks.\n\n### Performance:\n\nWithout concurrency siprocket can parse approx 100k messages per second on a average xeon CPU. Depending on your application you may be able to parse concurrently which would greatly increase the throughput. The size and complexity of the SIP messages you have to parse will also influence performance. \n\n### Install:\n\nInstall using `go get -u github.com/marv2097/siprocket`\nAdd the Import `\"github.com/marv2097/siprocket\"` in your code.\n\n### Usage:\n\nsiprocket expects data from a capture interface, socket or file as a slice of bytes. In most applications you will have already parsed the lower layers and pass the SIP payload to siprocket to be parsed. The output from the Parse function is a stuct that contains all of the top level items found in the SIP message. These can then be accessed using a simple dot notation. Most outputs are also slices of bytes with the exception of a few fields. \n\nIn this simple example we will use a SIP message defined directly in our code below. It will parse the message and print out the user-part of the 'From' and 'To' header fields.\n\n```go\n// Load up a test message\nraw := []byte(\"SIP/2.0 200 OK\\r\\n\" +\n              \"Via: SIP/2.0/UDP 192.168.2.242:5060;received=22.23.24.25;branch=z9hG4bK5ea22bdd74d079b9;alias;rport=5060\\r\\n\" +\n              \"To: \u003csip:JohnSmith@mycompany.com\u003e;tag=aprqu3hicnhaiag03-2s7kdq2000ob4\\r\\n\" +\n              \"From: sip:HarryJones@mycompany.com;tag=89ddf2f1700666f272fb861443003888\\r\\n\" +\n              \"CSeq: 57413 REGISTER\\r\\n\" +\n              \"Call-ID: b5deab6380c4e57fa20486e493c68324\\r\\n\" +\n              \"Contact: \u003csip:JohnSmith@192.168.2.242:5060\u003e;expires=192\\r\\n\\r\\n\")\n\n// Parse the sip data\nsip := siprocket.Parse(raw)\n\n// Print out the To User-part.\nfmt.Print(\"From: \", string(sip.From.User), \" To: \", string(sip.To.User))\n\n```\nWill Print `From: HarryJones To: JohnSmith`\n\n### Output Data Structure\n\nMany of the SIP headers are in simple key value pairs. For example the Call-ID field, these kinds of fields all share the same format used to store them. It has a slice of bytes for the value, and an optional source variable.\n\n```go\ntype sipVal struct {\n\tValue []byte // Sip Value\n\tSrc   []byte // Full source if needed\n}\n```\n\nTo access them we just reference the field name followed by the word `Value`. So if we wanted to get the Call-ID from the example above we would just reference `sip.CallId.Value`. Other fields that support this format are:\n\nHeader Field | Reference\n--- | ---\nUser-Agent | `Ua`\nExpires | `Exp`\nMax-Forwards | `MaxFwd`\nCall-Id | `CallId`\nContent-Type | `ContType`\nContent-Length | `ContLen`\n\nMore complicated fields have specific structs to hold the data they contain, for example the From and To header field has each section broken out and are identical:\n\n```go\ntype sipTo struct {\n\tUriType  string // Type of URI sip, sips, tel etc\n\tName     []byte // Named portion of URI\n\tUser     []byte // User part\n\tHost     []byte // Host part\n\tPort     []byte // Port number\n\tTag      []byte // Tag\n\tUserType []byte // User Type\n\tSrc      []byte // Full source if needed\n}\n```\n\n#### Multiple values\n\nWhen a field is present in the SIP header multiple times we can use a slice of its struct to hold the multiple values. These can then be itterated over with the `range` keyword or their size checked with the `len` keyword. An example of this is the Via header field. There can be multiple Via's in a SIP message and they are kept in order as the message is parsed from the first line to the last.\n\nFor a Via, The key part of the `SipMsg` struct is shown along with the `sipVia` struct:\n\n```go\ntype SipMsg struct\n    Via []sipVia    // Slice of SIP Vias\n    \n\ntype sipVia struct {\n\tTrans  string // Type of Transport udp, tcp, tls, sctp etc\n\tHost   []byte // Host part\n\tPort   []byte // Port number\n\tBranch []byte //\n\tRport  []byte //\n\tMaddr  []byte //\n\tTtl    []byte //\n\tRcvd   []byte //\n\tSrc    []byte // Full source if needed\n}\n```\n\nThe SDP Attributes field also supports multiple entries.\n\n#### SDP\n\nIf SDP is found within a SIP message then it will be parsed too. Media Descriptions, Attributes and Connection Data are all available from the SDP payload. If you wanted to get the media port number from an INVITE with SDP and convert it to an integer, you could use something like:\n\n```go\n\tport, _ := strconv.Atoi(string(sip.Sdp.MediaDesc.Port))\n```\n\n### Reading SIP from other sources\n\nIn most real world applications you want to read SIP from an external source. This may be a file, network socket or capture device. If you are wanting to capture with pf_ring then you can checkout my cutdown [pf_ring go library](https://github.com/marv2097/gopfring).\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarv2097%2Fsiprocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarv2097%2Fsiprocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarv2097%2Fsiprocket/lists"}