diff --git a/dev/tcploop/tcploop.c b/dev/tcploop/tcploop.c index 1ac543b48..5e8b39b0a 100644 --- a/dev/tcploop/tcploop.c +++ b/dev/tcploop/tcploop.c @@ -99,7 +99,7 @@ __attribute__((noreturn)) void usage(int code, const char *arg0) "actions :\n" " A[] : Accepts incoming sockets and closes count-1\n" " Note: fd=accept(fd)\n" - " C : Connects to ip:port\n" + " C[[ip]:port] : Connects to ip:port or default ones if unspecified.\n" " Note: fd=socket,connect(fd)\n" " D : Disconnect (connect to AF_UNSPEC)\n" " E[] : Echo this amount of bytes. 0=infinite. unset=any amount.\n" @@ -236,7 +236,7 @@ void sig_handler(int sig) /* converts str in the form [[||]:]port to struct sockaddr_storage. * Returns < 0 with err set in case of error. */ -int addr_to_ss(char *str, struct sockaddr_storage *ss, struct err_msg *err) +int addr_to_ss(const char *str, struct sockaddr_storage *ss, struct err_msg *err) { char *port_str; int port; @@ -418,8 +418,17 @@ int tcp_accept(int sock, const char *arg) /* Try to establish a new connection to . Return the fd or -1 in case of error */ int tcp_connect(const struct sockaddr_storage *sa, const char *arg) { + struct sockaddr_storage conn_addr; int sock; + if (arg[1]) { + struct err_msg err; + + if (addr_to_ss(arg + 1, &conn_addr, &err) < 0) + die(1, "%s\n", err.msg); + sa = &conn_addr; + } + sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) return -1;