SAP (RFC 2974) 和 SDP (RFC 2327) 头部大小

huangapple go评论73阅读模式
英文:

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

问题

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.

英文:

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

得分: 1

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

第1至4字节为 | V=1 |A|R|T|E|C| auth len | msg id hash |,接下来的4字节是 originating source (32或128位)

We also need parts from mumudvb2 sap.h

需要从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:

以及与IPv4处理相关的sap.c的部分 https://github.com/braice/MuMuDVB/blob/mumudvb2/src/sap.c#L267

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++;
}

第1至4字节是 | V=1 |A|R|T|E|C| auth len | msg id hash |,接下来的4字节是 originating source (32或128位)。这些字节后面的内容是关于payload type和application/sdp的信息。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月30日 01:44:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76583458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定