summaryrefslogtreecommitdiff
path: root/frontend/saned.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2021-02-16 18:24:46 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2021-02-16 18:24:46 +0100
commitecaaf250cb33ff61f37a7b441f2337584a655350 (patch)
tree4303648095deff998ae20c2393b56db527742ac9 /frontend/saned.c
parent5793a221e112fa49073de0137d6bfa750a61b0a1 (diff)
parent351b7328520c16730ceb46e5acae16038c42185e (diff)
Update upstream source from tag 'upstream/1.0.32'
Update to upstream version '1.0.32' with Debian dir 2c1111c59d9d68bcbf479a4a4de7697fe2de127f
Diffstat (limited to 'frontend/saned.c')
-rw-r--r--frontend/saned.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/frontend/saned.c b/frontend/saned.c
index 0317542..5b16980 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -17,8 +17,8 @@
for more details.
You should have received a copy of the GNU General Public License
- along with sane; see the file COPYING. If not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with sane; see the file COPYING.
+ If not, see <https://www.gnu.org/licenses/>.
The SANE network daemon. This is the counterpart to the NET
backend.
@@ -256,6 +256,7 @@ static int run_once;
static int data_connect_timeout = 4000;
static Handle *handle;
static char *bind_addr;
+static short bind_port = -1;
static union
{
int w;
@@ -2841,6 +2842,7 @@ do_bindings_family (int family, int *nfds, struct pollfd **fds, struct addrinfo
int on = 1;
int i;
+ sane_port = bind_port;
fdp = *fds;
for (resp = res, i = 0; resp != NULL; resp = resp->ai_next, i++)
@@ -2851,12 +2853,18 @@ do_bindings_family (int family, int *nfds, struct pollfd **fds, struct addrinfo
if (resp->ai_family == AF_INET)
{
- sane_port = ntohs (((struct sockaddr_in *) resp->ai_addr)->sin_port);
+ if (sane_port != -1)
+ ((struct sockaddr_in *) resp->ai_addr)->sin_port = htons(sane_port);
+ else
+ sane_port = ntohs(((struct sockaddr_in *) resp->ai_addr)->sin_port);
}
#ifdef ENABLE_IPV6
else if (resp->ai_family == AF_INET6)
{
- sane_port = ntohs (((struct sockaddr_in6 *) resp->ai_addr)->sin6_port);
+ if (sane_port != -1)
+ ((struct sockaddr_in6 *) resp->ai_addr)->sin6_port = htons(sane_port);
+ else
+ sane_port = ntohs (((struct sockaddr_in6 *) resp->ai_addr)->sin6_port);
}
#endif /* ENABLE_IPV6 */
else
@@ -2903,6 +2911,28 @@ do_bindings_family (int family, int *nfds, struct pollfd **fds, struct addrinfo
continue;
}
+ if (sane_port == 0)
+ {
+ /* sane was asked to bind to an ephemeral port, log it */
+ socklen_t len = sizeof (*resp->ai_addr);
+ if (getsockname(fd, resp->ai_addr, &len) != -1)
+ {
+ if (resp->ai_family == AF_INET)
+ {
+ DBG (DBG_INFO, "do_bindings: [%d] selected ephemeral port: %d\n", i, ntohs(((struct sockaddr_in *) resp->ai_addr)->sin_port));
+ }
+
+#ifdef ENABLE_IPV6
+ if (resp->ai_family == AF_INET6)
+ {
+ DBG (DBG_INFO, "do_bindings: [%d] selected ephemeral port: %d\n", i, ntohs(((struct sockaddr_in6 *) resp->ai_addr)->sin6_port));
+ }
+
+#endif /* ENABLE_IPV6 */
+
+ }
+ }
+
fdp->fd = fd;
fdp->events = POLLIN;
@@ -3391,6 +3421,7 @@ static void usage(char *me, int err)
" -d, --debug=level set debug level `level' (default is 2)\n"
" -e, --stderr output to stderr\n"
" -b, --bind=addr bind address `addr' (default all interfaces)\n"
+ " -p, --port=port bind port `port` (default sane-port or 6566)\n"
" -h, --help show this help message and exit\n", me);
exit(err);
@@ -3410,6 +3441,7 @@ static struct option long_options[] =
{"debug", required_argument, 0, 'd'},
{"stderr", no_argument, 0, 'e'},
{"bind", required_argument, 0, 'b'},
+ {"port", required_argument, 0, 'p'},
{0, 0, 0, 0 }
};
@@ -3435,7 +3467,7 @@ main (int argc, char *argv[])
run_foreground = SANE_TRUE;
run_once = SANE_FALSE;
- while((c = getopt_long(argc, argv,"ha::lu:Dod:eb:", long_options, &long_index )) != -1)
+ while((c = getopt_long(argc, argv,"ha::lu:Dod:eb:p:", long_options, &long_index )) != -1)
{
switch(c) {
case 'a':
@@ -3465,6 +3497,9 @@ main (int argc, char *argv[])
case 'b':
bind_addr = optarg;
break;
+ case 'p':
+ bind_port = atoi(optarg);
+ break;
case 'h':
usage(argv[0], EXIT_SUCCESS);
break;