#include #include #include #include #include #include #include #include #include int main(int argc, char * argv[]) { int n, s, len; char buf[256]; struct hostent *hp; struct sockaddr_in name; hp = gethostbyname(argv[2]); s = socket(AF_INET, SOCK_STREAM, 0); name.sin_family = AF_INET; name.sin_port = htons(atoi(argv[1])); memcpy(&name.sin_addr, hp->h_addr_list[0], hp->h_length); len = sizeof(struct sockaddr_in); connect(s, (struct sockaddr *) &name, len); while ((n = read(0, buf, sizeof(buf))) > 0) { if (send(s, buf, n, 0) < 0) { perror("send"); exit(1); } } close(s); exit(0); }