www.pudn.com > date.c.zip > date.c, change:2017-05-15,size:734b


#include "unp.h"
#include <stdio.h>

int main(int argc, char **argv){
  int sockfd, n;
  char recvline[MAXLINE+1];
  struct sockaddr_in servaddr;
  if(argc!=2)
    puts("usage: a.out <IPadress>");
  if((sockfd=socket(AF_INET, SOCK_STREAM, 0))<0)
    puts("socket error");
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(80);
  if(inet_pton(AF_INET, argv[1], &servaddr.sin_addr)<=0)
    puts("inet_pton error for s");
  if(connect(sockfd, (SA*)&servaddr, sizeof(servaddr))<0)
    puts("connect error");
  while((n=read(sockfd, recvline, MAXLINE))>0){
    recvline[n]=0;
    if(fputs(recvline, stdout)==EOF)
      puts("read error");
  }
  if(n<0)
    puts("read error");
  exit(0);
}