红联Linux门户
Linux帮助

跪求。。。十万火急

发布时间:2011-10-21 08:56:34来源:红联作者:LinusLin
2、请解释下面程序段的相关作用?
#define SERVPORT 3333
#define MAXDATASIZE 100 /*每次最大数据传输量 */

int main(int argc, char *argv[])
{
int sockfd, recvbytes;
char buf[MAXDATASIZE];
struct hostent *host;
struct sockaddr_in serv_addr;
if (argc < 2)
{ fprintf(stderr,"Please enter the server's hostname!\n"); exit(1); }
//____________________________________
serv_addr.sin_family=AF_INET;
serv_addr.sin_port=htons(SERVPORT);
serv_addr.sin_addr = *((struct in_addr *)host->h_addr);
bzero(&(serv_addr.sin_zero),8);

//___________________________________
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1)
{ perror("connect error!"); exit(1); }

//___________________________________
if ((recvbytes=recv(sockfd, buf, MAXDATASIZE, 0)) ==-1)
{ perror("recv出错!"); exit(1); }
buf[recvbytes] = '\0';
printf("Received: %s",buf);
close(sockfd);
return 0;
}
作用:_______________________________________________________
文章评论

共有 2 条评论

  1. ai0909 于 2011-10-21 15:20:17发表:

    路过。。。

  2. shanot 于 2011-10-21 10:16:10发表:

    帮不忙啊