int PraseURL(const char *url, char *szip, int *iport)
{
char *dstIP = NULL;
int len = 0;
char *s = NULL, *ss = NULL;
if (url == NULL) {
return -1;
}
len = strlen(url);
if (len<=0 || _strnicmp(url, "rtsp://", 7)) {//1.先找到rtsp这个协议字段
return -1;
}
dstIP = (char *)malloc(len);
if (dstIP == NULL) {
return -1;
}
s = (char*)url + strlen("rtsp://");//2.再找ip地址
ss = strchr(s, '/');
strncpy_s(dstIP,len, s, ss - s);
dstIP[ss - s] = '\0';
s = strchr(dstIP, ':');//3.查找下是否是有端口设置
if (s)
{
//4.如果有端口设置,还需要修改IP地址
ss = s;
s++;
*iport = atoi(s);
dstIP[ss - dstIP] = '\0';//同时修正ip地址
}
else {
*iport = 554;//rtsp默认端口554
}
strncpy_s(szip, 16, dstIP, strlen(dstIP));//ipv4地址最大16字节
free(dstIP);
dstIP = NULL;
return 0;
}
从rtsp地址获取ip地址和端口号
于 2021-01-03 15:39:55 首次发布