月度归档:2013年07月

小菜瞎搞HTTP–简单GET请求

//
//  main.c
//
//  Created by qixingyue on 13-7-19.
//  Copyright (c) 2013年 qixingyue. All rights reserved.
//

#include <stdio.h>
#include <unistd.h>
#include <string.h>

//socket 程序需要的头文件
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, const char * argv[])
{
    if(argc != 5 ) {
        printf("Error Happend. Params not enough.\n");
        return 1;
    }
    
    printf("Get FILE:%s from %s User: %s , Passowrd : %s",argv[4],argv[1],argv[2],argv[3]);
    
    int client_socket ;
    char buffer[1000];
    
    if((client_socket = socket(AF_INET, SOCK_STREAM, 0))<0) {
        printf("Socket create error . \n");
        return 1;
    }
    
    struct sockaddr_in serverAddr;
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port =  htons(80) ;
    serverAddr.sin_addr.s_addr = inet_addr(argv[1]);
    
    if(connect(client_socket, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0 ) {
        printf("Connect Error:\n");
        return 1;
    }
    
    
    char *first_line = "GET / HTTP/1.1\n";
    char *second_line = "Host: itianmen.com\n";
    send(client_socket, first_line,strlen(first_line),0);
    send(client_socket, second_line,strlen(second_line),0);
    send(client_socket, "\n", 1,0);
    
    while(recv(client_socket, buffer, 1000, 0) >0 ){
        printf("GET MESSAGE : %s \n",buffer);
    }
    
    close(client_socket);
    return 0;
}

mac 下的automake安装shell



curl -O http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
tar -xzvf m4-1.4.13.tar.gz
cd m4-1.4.13
./configure –prefix=/usr/local
make
sudo make install


cd ..
curl -O http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
tar -xzvf autoconf-2.65.tar.gz
cd autoconf-2.65
./configure –prefix=/usr/local
make
sudo make install
cd ..
curl -O http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
tar xzvf automake-1.11.tar.gz
cd automake-1.11
./configure –prefix=/usr/local
make
sudo make install
cd ..
curl -O http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
tar xzvf libtool-2.2.6b.tar.gz
cd libtool-2.2.6b
./configure –prefix=/usr/local
make

sudo make install