#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#define GET_HTTP "GET / HTTP1.0\r\nHOST:%s\r\n\r\n"
int main(){
int sockfd = socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)perror("sock");
struct sockaddr_in mine,dest;
bzero(&mine,sizeof(mine));
mine.sin_family = AF_INET;
mine.sin_port = htons(atoi(argv1));
inet_pton(AF_INET,"192.168.3.44", &mine.sin_addr);
bzero(&dest,sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(80);
inet_pton(AF_INET, argv[2],&dest.sin_addr);
int b = bind(sockfd,(struct sockaddr*)&mine,sizeof(mine));
if(b==-1)perror("");
int c = connect(sockfd,(struct sockaddr*)&dest,sizeof(dest));
if(c!=0)perror("");
char get[1024];
snprintf(get, sizeof(get), GET_HTTP, "www.baidu.com");
write(sockfd, get, strlen(get));
while(read(sockfd, get, sizeof(get)) > 0) {
printf("%s\n", get);
}
close(sockfd);
}
#include <stdlib.h>
#include <strings.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#define GET_HTTP "GET / HTTP1.0\r\nHOST:%s\r\n\r\n"
int main(){
int sockfd = socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)perror("sock");
struct sockaddr_in mine,dest;
bzero(&mine,sizeof(mine));
mine.sin_family = AF_INET;
mine.sin_port = htons(atoi(argv1));
inet_pton(AF_INET,"192.168.3.44", &mine.sin_addr);
bzero(&dest,sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(80);
inet_pton(AF_INET, argv[2],&dest.sin_addr);
int b = bind(sockfd,(struct sockaddr*)&mine,sizeof(mine));
if(b==-1)perror("");
int c = connect(sockfd,(struct sockaddr*)&dest,sizeof(dest));
if(c!=0)perror("");
char get[1024];
snprintf(get, sizeof(get), GET_HTTP, "www.baidu.com");
write(sockfd, get, strlen(get));
while(read(sockfd, get, sizeof(get)) > 0) {
printf("%s\n", get);
}
close(sockfd);
}