⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtsprequest.c

📁 RTSP协议中的客户端实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	
	len = send(sockfd, inbuffer, strlen(inbuffer), 0);
    if (len < 0)
        printf("DESCRIBE Request Msg:\n %s send error! error code is %d, error content is  %s \n", inbuffer, errno, strerror(errno));
    else
        printf("DESCRIBE Request Msg:\n %s send successfully,total content is %d bytes!\n", inbuffer, len);
}

void Handel_SETUP(char *inbuffer, int sockfd)
{
	char strCseq[5]= {0};
	int len;
	bzero(inbuffer, MAXBUF + 1);

	cseqCount++;
	//SETUP Request
	memcpy(inbuffer, sendSETUPRequstStr, sizeof(sendSETUPRequstStr));
	//Cseq number
	sprintf(strCseq, "%d", cseqCount);
	strcat(inbuffer + sizeof(inbuffer), CseqHeadStr);
	strcat(inbuffer + sizeof(inbuffer), strCseq);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//Transport
	strcat(inbuffer + sizeof(inbuffer), TransportHeadStr);
	strcat(inbuffer + sizeof(inbuffer),"RTP/AVP;unicast;client_port=31126-31127");
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//user-Agent infomation
	strcat(inbuffer + sizeof(inbuffer), UserHeadStr);
	strcat(inbuffer + sizeof(inbuffer),userAgentStr);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	len = send(sockfd, inbuffer, strlen(inbuffer), 0);
    if (len < 0)
        printf("SETUP Request Msg:\n %s send error! error code is %d, error content is  %s \n", inbuffer, errno, strerror(errno));
    else
        printf("SETUP Request Msg:\n %s send successfully,total content is %d bytes!\n", inbuffer, len);
}

void Handel_PLAY(char *inbuffer, int sockfd,char* sessionId)
{
	char strCseq[5]= {0};
	int len;
	bzero(inbuffer, MAXBUF + 1);

      cseqCount++;
	//SETUP Request
	memcpy(inbuffer, sendPLAYRequstStr, sizeof(sendPLAYRequstStr));
	//Cseq number
	sprintf(strCseq, "%d", cseqCount);
	strcat(inbuffer + sizeof(inbuffer), CseqHeadStr);
	strcat(inbuffer + sizeof(inbuffer), strCseq);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//Session
	strcat(inbuffer + sizeof(inbuffer), SessionHeadStr);
	strncat(inbuffer + sizeof(inbuffer),sessionId,strlen(sessionId));
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//Range
	strcat(inbuffer + sizeof(inbuffer), RangeHeadStr);
	strcat(inbuffer + sizeof(inbuffer),"npt=0.000-");
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//user-Agent infomation
	strcat(inbuffer + sizeof(inbuffer), UserHeadStr);
	strcat(inbuffer + sizeof(inbuffer),userAgentStr);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	len = send(sockfd, inbuffer, strlen(inbuffer), 0);
    if (len < 0)
        printf("PLAY Request Msg:\n %s send error! error code is %d, error content is  %s \n", inbuffer, errno, strerror(errno));
    else
        printf("PLAY Request Msg:\n %s send successfully,total content is %d bytes!\n", inbuffer, len);
}


void Handle_PAUSE(char *inbuffer, int sockfd,char *sessionId)
{
	char strCseq[5]= {0};
	int len;
	bzero(inbuffer, MAXBUF + 1);

	cseqCount++;
	//SETUP Request
	memcpy(inbuffer, sendPauseRequestStr, sizeof(sendPauseRequestStr));
	//Cseq number
	sprintf(strCseq, "%d", cseqCount);
	strcat(inbuffer + sizeof(inbuffer), CseqHeadStr);
	strcat(inbuffer + sizeof(inbuffer), strCseq);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//Session
	strcat(inbuffer + sizeof(inbuffer), SessionHeadStr);
	strncat(inbuffer + sizeof(inbuffer),sessionId,strlen(sessionId));
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//user-Agent infomation
	strcat(inbuffer + sizeof(inbuffer), UserHeadStr);
	strcat(inbuffer + sizeof(inbuffer),userAgentStr);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	len = send(sockfd, inbuffer, strlen(inbuffer), 0);
    if (len < 0)
        printf("PAUSE Request Msg:\n %s send error! error code is %d, error content is  %s \n", inbuffer, errno, strerror(errno));
    else
        printf("PAUSE Request Msg:\n %s send successfully,total content is %d bytes!\n", inbuffer, len);
}
	


void Handel_Teardown(char *inbuffer, int sockfd,char *sessionId)
{
	char strCseq[5]= {0};
	int len;
	bzero(inbuffer, MAXBUF + 1);

	cseqCount++;
	//SETUP Request
	memcpy(inbuffer, sendTeardownRequestStr, sizeof(sendTeardownRequestStr));
	//Cseq number
	sprintf(strCseq, "%d", cseqCount);
	strcat(inbuffer + sizeof(inbuffer), CseqHeadStr);
	strcat(inbuffer + sizeof(inbuffer), strCseq);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//Session
	strcat(inbuffer + sizeof(inbuffer), SessionHeadStr);
	strncat(inbuffer + sizeof(inbuffer),sessionId,strlen(sessionId));
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	//user-Agent infomation
	strcat(inbuffer + sizeof(inbuffer), UserHeadStr);
	strcat(inbuffer + sizeof(inbuffer),userAgentStr);
	strcat(inbuffer + sizeof(inbuffer), "\r\n");
	len = send(sockfd, inbuffer, strlen(inbuffer), 0);
    if (len < 0)
        printf("TEARDOWN Request Msg:\n %s send error! error code is %d, error content is  %s \n", inbuffer, errno, strerror(errno));
    else
        printf("TEARDOWN Request Msg:\n %s send successfully,total content is %d bytes!\n", inbuffer, len);

	
}


int udpSocket(int port, struct sockaddr_in6 *servaddr)
{
	int sockfd,n,flags;
	char  tmpSaddr[16]="fec0::123e:459f";
	char  tmpMaddr[16]="fec0::123e:4526";
	struct sockaddr_in6  myaddr;
	
//	bzero(&servaddr,sizeof(struct sockaddr_in6));
	servaddr->sin6_family=AF_INET6;
	servaddr->sin6_port=htons(port);
	if(inet_pton(AF_INET6,tmpSaddr,&servaddr->sin6_addr)<=0)
	{
		printf("udp error in inet\n");
		return -1;
	}
	if((sockfd=socket(AF_INET6, SOCK_DGRAM,0))<0)
	{
		printf("udp error in socket\n");
		return -1;
	}
	bzero(&myaddr,sizeof(struct sockaddr_in6));
	if(inet_pton(AF_INET6,tmpMaddr,&myaddr.sin6_addr)<=0)
	{
		printf("udp error in inet\n");
		return -1;
	}
	myaddr.sin6_family=AF_INET6;;
	myaddr.sin6_port=htons(port);
	flags=fcntl(sockfd, F_GETFL,0);
	fcntl(sockfd,F_SETFL,flags|O_NONBLOCK);
	if(bind(sockfd,(struct sockaddr*)&myaddr,sizeof(myaddr))<0)
	{
		printf("udp error in bind\n");
		return -1;
	}
	return sockfd;
	
}

void udp_process(FILE *fp,int udpSockfd,struct sockaddr *udpSevAddr)
{
	char sendStr[2048];
	char recvStr[2048];
	socklen_t len;
	int n=0;

	while(1)
	{
	      bzero(&recvStr,sizeof(recvStr));
		n=recvfrom(udpSockfd,recvStr,1024,0,udpSevAddr,&len);
		if(n>0)
		{
			printf("the rtcp sender report is: %s\n",recvStr);
		}
		if(fgets(sendStr,2048,fp)!=NULL)
			break;
	}
}

 int intsearch(char* buf, char* searchStr, int len)
{
	char *tmp1;
	char *tmp2;
	int	port=0;
	tmp1=buf;
	if(buf==NULL||searchStr==NULL||len==0)
		return -1;
	while((tmp2=strchr(tmp1,*searchStr))!=NULL)
	{
		if(memcmp(tmp2,searchStr,len)==0)
		{
			tmp2+=len;
			while(*tmp2>='0'&&*tmp2<='9')
			{
				port=(int)((*tmp2-'0')+port*10);
				tmp2++;
			}
			break;
		}
		else
			tmp2+=1;
		tmp1=tmp2;
	}
	if(tmp2==NULL)
		return -1;
	else
		return port;
}

  int strsearch(char* buf, char* searchStr, int len, char *dest)
{
	char *tmp1;
	char *tmp2;
	int	port=0;
	tmp1=buf;
	char *tmp3;
	tmp3=dest;
	if(buf==NULL||searchStr==NULL||len==0||dest==NULL)
		return -1;
	while((tmp2=strchr(tmp1,*searchStr))!=NULL)
	{
		if(memcmp(tmp2,searchStr,len)==0)
		{
			tmp2+=len;
			while(*tmp2>='0'&&*tmp2<='9')
			{
				*tmp3=*tmp2;
				tmp3++;
				tmp2++;
			}
			break;
		}
		else
			tmp2+=1;
		tmp1=tmp2;
	}
	if(tmp2==NULL)
		return -1;
	else
		return 1;
}
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -