// Source: https://basepath.com/aup/ex/sktcl_8c-source.html
// Rochkind's Book, page 574

#include <stdio.h>
#include <sys/socket.h> 
#include <arpa/inet.h>  
#include <unistd.h>     
#include <string.h>     
#include <stdlib.h>

#define REQUEST "GET / HTTP/1.0\r\n\r\n"

int main(int argc, char * argv[]) {
    struct sockaddr_in sa;
    int fd_skt;
    char buf[1000];
    ssize_t nread;
    if (argc!=2) {
       printf ("Usage: inetExample xxx.xxx.xxx.xxx\n");
       exit (-1); }
    sa.sin_family = AF_INET;
    sa.sin_port = htons(80);
    sa.sin_addr.s_addr =  inet_addr(argv[1]);
    if ((fd_skt = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
         perror("Message from socket [client] : ");
         exit(-1); }        
    if (connect(fd_skt, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
        printf("\nConnection Failed \n");
        return -1; }    
    write(fd_skt, REQUEST, strlen(REQUEST));
    nread = read(fd_skt, buf, sizeof(buf));
    (void) write(STDOUT_FILENO, buf, nread);
    close(fd_skt);
    exit(0); }




