+struct sdp_info {
+ char *service;
+ char *host;
+ char *proto;
+ char *port;
+};
+
+struct sdp_info *parse_sdp(char *sdp, int len)
+{
+ char *pos;
+ static struct sdp_info sdpinfo;
+
+ /* RFC 2327
+ * v=0
+ * o=- 6dca 1 IN IP4 192.168.100.17:2000
+ * s=TV Das Erste
+ * t=0 0
+ * c=IN IP4 192.168.100.17/1
+ * m=video 2000 http 33
+ * a=tool:getstream
+ * a=type:broadcast
+ */
+
+ bzero(&sdpinfo, sizeof(struct sdp_info));
+
+ pos = sdp;
+ while(*pos != 0 && (pos-sdp) < len) {
+ if (*pos == 0x0d)
+ *pos = 0;
+
+ if (*pos == 0x0a) {
+ *pos = 0;
+
+ if (!strncasecmp("s=", sdp, 2)) {
+ sdpinfo.service = sdp + 2;
+ } else if (!strncasecmp("c=", sdp, 2)) {
+ int poscnt = 0;
+
+ sdp += 2;
+ while (*sdp != 0) {
+ if (poscnt == 2 && *sdp == '/') {
+ *sdp = 0;
+ break;
+ }
+
+ if (*sdp == ' ') {
+ *sdp = 0;
+ poscnt++;
+
+ /* c=<network type> <address type> <connection address> */
+ if (poscnt == 2)
+ sdpinfo.host = sdp + 1;
+
+ if (poscnt > 2)
+ break;
+ }
+ sdp++;
+ }
+ } else if (!strncasecmp("m=", sdp, 2)) {
+ int poscnt = 0;
+
+ sdp += 2;
+ while (*sdp != 0) {
+ if (*sdp == ' ') {
+ *sdp = 0;
+ poscnt++;
+
+ /* m=<media> <port> <transport> <fmt list> */
+ if (poscnt == 1)
+ sdpinfo.port = sdp + 1;
+
+ if (poscnt == 2)
+ sdpinfo.proto = sdp + 1;
+
+ if (poscnt > 2)
+ break;
+ }
+ sdp++;
+ }
+ }
+
+ sdp = ++pos;
+ continue;
+ }
+ pos++;
+ }
+
+ return &sdpinfo;
+}
+
+