- address.sin_family = AF_INET;
- address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
- address.sin_port = htons(atoi(*(++argv)));
+ if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
+ perror_msg_and_die("bind");
+ }
+
+ if (do_listen) {
+ socklen_t addrlen = sizeof(address);
+
+ if (listen(sfd, 1) < 0)
+ perror_msg_and_die("listen");
+
+ if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0)
+ perror_msg_and_die("accept");
+
+ close(sfd);
+ sfd = tmpfd;
+ } else {
+ hostinfo = xgethostbyname(argv[optind]);
+
+ address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
+ address.sin_port = htons(atoi(argv[optind+1]));
+
+ if (connect(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
+ perror_msg_and_die("connect");
+ }
+
+#ifdef GAPING_SECURITY_HOLE
+ /* -e given? */
+ if (pr00gie) {
+ dup2(sfd, 0);
+ close(sfd);
+ dup2 (0, 1);
+ dup2 (0, 2);
+ execl (pr00gie, pr00gie, NULL);
+ /* Don't print stuff or it will go over the wire.... */
+ _exit(-1);
+ }
+#endif /* GAPING_SECURITY_HOLE */