/***** inetclient.c *****/ 
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>    /* Internet domain header */
#include <netdb.h>

#define SERVER_PORT  4900
struct sockaddr_in peer = {AF_INET, htonl(SERVER_PORT)}; 

int main(int argc, char* argv[])
{ int soc;
  char buf[256];
  struct hostent *hp;
    if ( argc != 2 )
    {  fprintf(stderr, "Usage: %s hostname\n", argv[0]);
       exit(1);
    }
/* fill in peer address */
    hp = gethostbyname(argv[1]);                /* (A) */
    if ( hp == NULL )
    {  fprintf(stderr, "%s: %s unknow host\n",
               argv[0], argv[1]);
       exit(1);
    }
    bcopy(hp->h_addr_list[0],                   /* (B) */
          (char*)&peer.sin_addr, hp->h_length);
/* create socket */
    soc = socket(AF_INET, SOCK_STREAM, 0);
/* request connection to server */
    if (connect(soc, &peer, sizeof(peer)) == -1)/* (C) */
    {  perror("client:connect"); close(soc);
       exit(1); 
    }
    write(soc, "Hello Internet", 15);           /* (D) */
    read(soc, buf, sizeof(buf));
    printf("SERVER ECHOED: %s\n", buf);
    close(soc); return(0);
}
/***** end of inetclient.c *****/ 
