// I have got this code from http://www.pcs.cnu.edu/~dgame/sockets/client.c
#define PORT 80
#define HOST "128.121.243.228"
#define DIRSIZE 8192000
#define HTTP_HEADER "GET /statuses/user_timeline/Neo_4583.json HTTP/1.1\nHost: twitter.com\n\n"
char* strToSend = HTTP_HEADER;
char hostname[100];
char dir[DIRSIZE];
int sd;
struct sockaddr_in pin;
struct hostent *hp;
strcpy(hostname,HOST);
if ((hp = gethostbyname(hostname)) == 0) {
exit(1);
}
memset(&pin, 0, sizeof(pin));
pin.sin_family = AF_INET;
pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
pin.sin_port = htons(PORT);
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
perror("connect");
exit(1);
}
if (send(sd, strToSend, strlen(strToSend), 0) == -1) {
exit(1);
}
if (recv(sd, dir, DIRSIZE, MSG_WAITALL) == -1) {
exit(1);
}else {
// The data is ready to be served
printf("%s\n", dir);
}
close(sd);
4 comments:
very good job , put i don't really get it..does this code try to retrieve a different IP from twitter instead of the blocked ip? or do you try to force the browser to use the ip 128.121.243.228 insted of the domain in the request? i think the code need more explaining
nice - simpler way is this:
telnet 128.121.243.228 80
you'll get:
Trying 128.121.243.228...
Connected to 128.121.243.228.
Escape character is '^]'.
type:
GET / HTTP/1.0
(hit enter twice)
lxrman: If u have twitter IP address and u managed to get connection with it then it is fine but the problem with the browser that it must added the host which will be the ip, the server will send 302 message to forward the browser to twitter.com which is blocked
ahmedre: I have a little file on desktop "text (has some message for different protocols weird but it saved me many times.) and python" but unfortunately people don't understand python so I wrote it in c :D
It is *nix C, correct?
I never do network programming in C on Linux but I feel the lib names (all in lower case) as opposite to the ugly win APIs (all in UPPER CASE) .. :)
Good work BTW, but I think you need to refer to the hash includes + the platform..
Thanks
Post a Comment