- 论坛徽章:
- 0
|
8楼
发表于 2013-04-18 15:55
回复 5# hellioncu
while(1){
recv_num = read(sock_fd, re_buf, 2000);
if(strncmp(re_buf, ipcam_video_trans_proto, 4) == 0)
{
pic_len = ((uint16_t *)(&re_buf[32]))[0];
buf = (uint8_t *)malloc(pic_len);
if(buf == NULL){
printf("malloc error for pic buf! \n");
return -1;
}
memset(buf, 0, pic_len);
total_num = recv_num - 36;
memcpy(buf, re_buf+36, recv_num-36);
while( total_num < pic_len){
recv_num = read(sock_fd, re_buf, 2000);
memcpy(buf+total_num, re_buf, recv_num);
total_num = recv_num + total_num;
}
}
if(buf != NULL)
free(buf);
}
这是完整代码!!! |
|