+ /* peek first packet and remember peer addr */
+ arm(o_wait); /* might as well timeout this, too */
+ if (setjmp(jbuf) == 0) { /* do timeout for initial connect */
+ /* (*ouraddr) is prefilled with "default" address */
+ /* and here we block... */
+ rr = recv_from_to(netfd, NULL, 0, MSG_PEEK, /*was bigbuf_net, BIGSIZ*/
+ &remend.u.sa, &ouraddr->u.sa, ouraddr->len);
+ if (rr < 0)
+ bb_perror_msg_and_die("recvfrom");
+ unarm();
+ } else
+ bb_error_msg_and_die("timeout");
+/* Now we learned *to which IP* peer has connected, and we want to anchor
+our socket on it, so that our outbound packets will have correct local IP.
+Unfortunately, bind() on already bound socket will fail now (EINVAL):
+ xbind(netfd, &ouraddr->u.sa, ouraddr->len);
+Need to read the packet, save data, close this socket and
+create new one, and bind() it. TODO */
+ if (!themaddr)
+ xconnect(netfd, &remend.u.sa, ouraddr->len);