Add option to only bind to localhost

Add option to only bind to localhost
This commit is contained in:
BjoernSch 2015-12-22 17:36:17 +01:00
parent d8f75fdfd7
commit 2d81581f09
3 changed files with 18 additions and 5 deletions

View File

@ -7496,7 +7496,14 @@ int initInitialise(void)
if (portStr) port = atoi(portStr); else port = gpioCfg.socketPort;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
if (gpioCfg.ifFlags & PI_LOCALHOST_SOCK_IF)
{
server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
}
else
{
server.sin_addr.s_addr = htonl(INADDR_ANY);
}
server.sin_port = htons(port);
if (bind(fdSock,(struct sockaddr *)&server , sizeof(server)) < 0)
@ -11508,7 +11515,7 @@ int gpioCfgInterfaces(unsigned ifFlags)
CHECK_NOT_INITED;
if (ifFlags > 3)
if (ifFlags > 7)
SOFT_ERROR(PI_BAD_IF_FLAGS, "bad ifFlags (%X)", ifFlags);
gpioCfg.ifFlags = ifFlags;

View File

@ -731,8 +731,9 @@ typedef void *(gpioThreadFunc_t) (void *);
/* ifFlags: */
#define PI_DISABLE_FIFO_IF 1
#define PI_DISABLE_SOCK_IF 2
#define PI_DISABLE_FIFO_IF 1
#define PI_DISABLE_SOCK_IF 2
#define PI_LOCALHOST_SOCK_IF 4
/* memAllocMode */

View File

@ -93,6 +93,7 @@ void usage()
" -e value, secondary DMA channel, 0-6, default 5\n" \
" -f, disable fifo interface, default enabled\n" \
" -k, disable socket interface, default enabled\n" \
" -l, localhost socket only default all interfaces\n" \
" -p value, socket port, 1024-32000, default 8888\n" \
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \
@ -120,7 +121,7 @@ static void initOpts(int argc, char *argv[])
int opt, err, i;
int64_t mask;
while ((opt = getopt(argc, argv, "a:b:c:d:e:fkp:s:t:x:")) != -1)
while ((opt = getopt(argc, argv, "a:b:c:d:e:fklp:s:t:x:")) != -1)
{
switch (opt)
{
@ -167,6 +168,10 @@ static void initOpts(int argc, char *argv[])
ifFlags |= PI_DISABLE_SOCK_IF;
break;
case 'l':
ifFlags |= PI_LOCALHOST_SOCK_IF;
break;
case 'p':
i = getNum(optarg, &err);
if ((i >= PI_MIN_SOCKET_PORT) && (i <= PI_MAX_SOCKET_PORT))