11 #include <netinet/in.h>
12 #include <arpa/inet.h>
19 static int usage(char *name)
21 fprintf(stderr, "%s: target port\n", name);
25 int main(int argc, char *argv[])
27 struct sockaddr_in addr;
32 return usage(argv[0]);
34 if (check_input_pipe())
35 return usage(argv[0]);
39 memset(&addr, 0, sizeof(addr));
40 addr.sin_family = AF_INET;
41 addr.sin_port = htons(port);
43 if (inet_aton(argv[1], &addr.sin_addr) != 1) {
44 struct hostent *hent = gethostbyname(argv[1]);
47 return error("gethostbyname");
49 memcpy(&addr.sin_addr, hent->h_addr, 4);
52 printf("Connecting to %s/%d\n", argv[1], port);
54 fd = socket(AF_INET, SOCK_STREAM, 0);
56 return error("socket");
58 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
59 return error("connect");
62 ret = splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, SPLICE_F_NONBLOCK);
64 if (errno == EAGAIN) {
68 return error("splice");