summaryrefslogtreecommitdiff
path: root/frontend/saned.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2021-05-18 07:43:35 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2021-05-18 07:43:35 +0200
commit9f8889f928ce86ba4a78659d378c6ba29bc9f735 (patch)
treec9567cb0d015b68ce3da8d03472b6443f1cb1ca9 /frontend/saned.c
parent446e9454b8cbe5b689149415d11d36e88442ca88 (diff)
parent154785ab2d5df7ddc8c2cf813b773c340e5e2aea (diff)
Merge branch 'release/debian/1.0.32-1'debian/1.0.32-1
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;