- 论坛徽章:
- 0
|
回复 20# pmerofc
while(1){
/*
memset(pic_name, 0, 100);
sprintf(pic_name, "%d.jpeg", i++);
if((fd = open(pic_name, O_WRONLY | O_CREAT)) < 0){
printf("open error\n");
return -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];
printf("pic_len = %d\n", pic_len);
buf = (uint8_t *)malloc(pic_len);
if(buf == NULL){
printf("malloc error for pic buf! \n");
return -1;
}
printf("malloc address buf = %x\n", buf);
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;
}
}
/*
write(fd, buf, pic_len);
close(fd);
*/
if(buf != NULL){
free(buf);
printf("free address buf = %x\n", buf);
buf = NULL;
}
}
完整代码!! |
|