ココサブ #719(2007/07/13 04:40 GMT) [ C ] Rating1/1=1.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <unistd.h> #include <stdio.h> #include <string.h> int main() { char *request = "GET /feeds/comments/ HTTP/1.1\nHost: ja.doukaku.org\n\n"; int sockfd; struct addrinfo hint; struct addrinfo *result; char buf[256]; int size; /* アクセスしたいホストの情報を得る */ memset(&hint, 0, sizeof(hint)); hint.ai_family = AF_INET; hint.ai_socktype = SOCK_STREAM; getaddrinfo("ja.doukaku.org", "80", &hint, &result); /* ソケットを作成し、接続しに行く */ sockfd = socket(result->ai_family, result->ai_socktype, result->ai_protocol); connect(sockfd, result->ai_addr, result->ai_addrlen); /* リクエストし、返ってくる文字列を表示 */ write(sockfd, request, strlen(request)); while (size = read(sockfd, buf, sizeof(buf))) { write(1, buf, size); } close(sockfd); return 0; }
Rating1/1=1.00-0+
1 reply [ reply ]
ココサブ
#719()
[
C
]
Rating1/1=1.00
Rating1/1=1.00-0+