#include #include #include #include #include #include #include #include #include #include #include #include #include int open_socket(char *host, int clientPort); int main(int argc,char * argv[]) { char buffer[50000]; int fd,ret,loop; if (argc <= 2) { puts("Usage: domain_search ... "); exit (0); } fd = open_socket("www.uwhois.com",999); for(loop=1;loop 0) { if (write(1,buffer,ret) != ret) perror("write"); fflush(stdout); } shutdown(fd,1); close(fd); return 0; } int open_socket(char *host, int clientPort) { int sock; unsigned long inaddr; struct sockaddr_in ad; struct hostent *hp; memset(&ad, 0, sizeof(ad)); ad.sin_family = AF_INET; inaddr = inet_addr(host); if (inaddr != INADDR_NONE) memcpy(&ad.sin_addr, &inaddr, sizeof(inaddr)); else { if ((hp = gethostbyname(host))==NULL) return -1; memcpy(&ad.sin_addr, hp->h_addr, hp->h_length); } ad.sin_port = htons(clientPort); if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) return sock; if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) { shutdown(sock,2); close(sock); return -1; } return sock; }