[sane-devel] [PATCH v2 2/2] add option to bind address
Matteo Croce
matteo at openwrt.org
Sun Sep 13 01:58:44 UTC 2015
add optional argument '-b' to let saned bind a specific address
---
also bind the address if AF_INDEP
add man and help documentation
doc/saned.man | 29 ++++++++++++++++++++---------
frontend/saned.c | 17 ++++++++++++-----
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/doc/saned.man b/doc/saned.man
index 8721b15..311b484 100644
--- a/doc/saned.man
+++ b/doc/saned.man
@@ -4,14 +4,21 @@
saned \- SANE network daemon
.SH SYNOPSIS
.B saned
-.B [ \-a
-.I [ username ]
-.B | \-d
-.I [ n ]
-.B | \-s
-.I [ n ]
-.B | \-h
-.B ]
+[
+.B \-a
+.I username
+] [
+.B \-d
+.I n
+] [
+.B \-s
+.I n
+] [
+.B \-b
+.I address
+] [
+.B \-h
+]
.SH DESCRIPTION
.B saned
is the SANE (Scanner Access Now Easy) daemon that allows remote clients
@@ -25,7 +32,11 @@ flag requests that
run in standalone daemon mode. In this mode,
.B saned
will detach from the console and run in the background, listening for incoming
-client connections;
+client connections, if
+.B \-b
+is specified then saned will bind the address
+.I address
+;
.B inetd
is not required for
.B saned
diff --git a/frontend/saned.c b/frontend/saned.c
index 5ef7c23..bce91e2 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -247,6 +247,7 @@ static int num_handles;
static int debug;
static int run_mode;
static Handle *handle;
+static char *bind_addr;
static union
{
int w;
@@ -2807,13 +2808,13 @@ do_bindings (int *nfds, struct pollfd **fds)
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
- err = getaddrinfo (NULL, SANED_SERVICE_NAME, &hints, &res);
+ err = getaddrinfo (bind_addr, SANED_SERVICE_NAME, &hints, &res);
if (err)
{
DBG (DBG_WARN, "do_bindings: \" %s \" service unknown on your host; you should add\n", SANED_SERVICE_NAME);
DBG (DBG_WARN, "do_bindings: %s %d/tcp saned # SANE network scanner daemon\n", SANED_SERVICE_NAME, SANED_SERVICE_PORT);
DBG (DBG_WARN, "do_bindings: to your /etc/services file (or equivalent). Proceeding anyway.\n");
- err = getaddrinfo (NULL, SANED_SERVICE_PORT_S, &hints, &res);
+ err = getaddrinfo (bind_addr, SANED_SERVICE_PORT_S, &hints, &res);
if (err)
{
DBG (DBG_ERR, "do_bindings: getaddrinfo() failed even with numeric port: %s\n", gai_strerror (err));
@@ -2891,7 +2892,10 @@ do_bindings (int *nfds, struct pollfd **fds)
memset (&sin, 0, sizeof (sin));
sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = INADDR_ANY;
+ if(bind_addr)
+ sin.sin_addr.s_addr = inet_addr(bind_addr);
+ else
+ sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = port;
DBG (DBG_DBG, "do_bindings: socket ()\n");
@@ -3259,7 +3263,7 @@ run_inetd ()
void usage(char *me, int err)
{
- fprintf (stderr, "Usage: %s [-a username] [-d n] [-s n] [-h]\n", me);
+ fprintf (stderr, "Usage: %s [-a username] [-d n] [-s n] [-b addr] [-h]\n", me);
exit(err);
}
@@ -3280,7 +3284,7 @@ main (int argc, char *argv[])
numchildren = 0;
run_mode = SANED_RUN_INETD;
- while((c = getopt(argc, argv, "a::d::s::h")) != -1)
+ while((c = getopt(argc, argv, "a::d::s::b:h")) != -1)
{
switch(c) {
case 'a':
@@ -3295,6 +3299,9 @@ main (int argc, char *argv[])
break;
case 'h':
usage(argv[0], EXIT_SUCCESS);
+ case 'b':
+ bind_addr = optarg;
+ break;
default:
usage(argv[0], EXIT_FAILURE);
}
--
2.1.4
More information about the sane-devel
mailing list