socket fdopen问题
#include <stdio.h>#include <stdlib.h>#include <netinet/in.h>#include <unistd.h>#include <sys/socket.h>#include <string.h>#include <fcntl.h>int main(void) { struct sockaddr_in sin; struct sockaddr_in cin; int lfd; int afd; FILE * fp; socklen_t len; char buf[400]; bzero(&sin,sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(8000); sin.sin_addr.s_addr = INADDR_ANY; lfd = socket(AF_INET,SOCK_STREAM,0); if(lfd < 0) { perror("socket"); exit(1); } if(bind(lfd,(struct sockaddr *)&sin,sizeof(sin)) == -1) { perror("bind"); exit(1); } listen(lfd,10); while(1) { bzero(buf,400); afd = accept(lfd,(struct sockaddr *)&cin,&len); if(afd < 0) { perror("afd"); exit(1); } printf("错在哪?\n"); fp = fdopen(afd,"a+"); fgets(buf,400,fp); printf("%s\n",buf); fclose(fp); close(afd); } return EXIT_SUCCESS;}fp = fdopen(afd,"a+");fgets(buf,400,fp);printf("%s\n",buf);