SAP (RFC 2974) and SDP (RFC 2327) Head size

51 Views Asked by At

I'm learning c(++) and trying to implement SAP and SDP announcement protocols. Currently, I'm following the RFCs and some code from Git Hub (like gestream and mumudvb). There I can see that after the SAP header, there are 8 bytes "head" before the SDP text. I could find such instructions in the RFCs or at least I didn't understand such a thing. This is my first try to implement something from RFC and I'm a bit confused about this "head".

Sorry, if my question looks dumb, but I want to understand it.

Thanks

I've checked the implemented SAP services and the RFC but I could not find why there are 8 bytes there.

1

There are 1 best solutions below

2
KamilCuk On

We need https://datatracker.ietf.org/doc/html/rfc2974 section 5 page 6:

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | V=1 |A|R|T|E|C|   auth len    |         msg id hash           |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   :                originating source (32 or 128 bits)            :
   :                                                               :
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    optional authentication data               |
   :                              ....                             :
   *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
   |                      optional payload type                    |
   +                                         +-+- - - - - - - - - -+
   |                                         |0|                   |
   + - - - - - - - - - - - - - - - - - - - - +-+                   |
   |                                                               |
   :                            payload                            :
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

We also need parts from mumudvb2 sap.h

#define SAP_HEADER4_BYTE0 0x20 /**00100000 : version 1 and nothing else*/
#define SAP_HEADER4_BYTE1 0x00 /**No auth header*/

#define SAP_HEADER6_BYTE0 0x30 /**00110000 : version 1 and IPv6*/
#define SAP_HEADER6_BYTE1 0x00 /**No auth header*/

#define SAP_HEAD_LEN4 8
#define SAP_HEAD_LEN6 20

and parts of sap.c https://github.com/braice/MuMuDVB/blob/mumudvb2/src/sap.c#L267 related to ipv4 handling:

    sap_message4->buf[0]=SAP_HEADER4_BYTE0;
    sap_message4->buf[1]=SAP_HEADER4_BYTE1;
    //Hash of SAP message: see end of this function
    sap_message4->buf[2]=0;
    sap_message4->buf[3]=0;

[...]

        log_message( log_module, MSG_DEBUG,"sap sending ipv4  address : %s (binary : 0x%x)\n",sap_p->sap_sending_ip4, ip4);
        memcpy (sap_message4->buf + 4, &ip4, 4);

[...]

sprintf(temp_string,"application/sdp");
if(channel->socketOut4)
{
    memcpy(sap_message4->buf + SAP_HEAD_LEN4, temp_string, strlen(temp_string));
    sap_message4->len=SAP_HEAD_LEN4+strlen(temp_string);
    sap_message4->buf[sap_message4->len]=0;
    sap_message4->len++;

The first 4 bytes are | V=1 |A|R|T|E|C| auth len | msg id hash | and the next 4 bytes is originating source (32 [...] bits.

That said, I do fully understand your confusion. It is part of the protocol, the payload type set to application/sdp mime type goes after what is in front of it.