Browse Source

add the ability to set the socket listen address

master
Matthew Bowman 8 years ago
parent
commit
fc2ba94684
1 changed files with 10 additions and 6 deletions
  1. 10
    6
      postsrsd.c

+ 10
- 6
postsrsd.c View File

48
 
48
 
49
 static char *self = NULL;
49
 static char *self = NULL;
50
 
50
 
51
-static size_t bind_service (const char *service, int family, int* socks, size_t max_socks)
51
+static size_t bind_service (const char *listen_addr, const char *service, int family, int* socks, size_t max_socks)
52
 {
52
 {
53
   struct addrinfo *addr, *it;
53
   struct addrinfo *addr, *it;
54
   struct addrinfo hints;
54
   struct addrinfo hints;
60
   hints.ai_family = family;
60
   hints.ai_family = family;
61
   hints.ai_socktype = SOCK_STREAM;
61
   hints.ai_socktype = SOCK_STREAM;
62
 
62
 
63
-  err = getaddrinfo(NULL, service, &hints, &addr);
63
+  err = getaddrinfo(listen_addr, service, &hints, &addr);
64
   if (err != 0) {
64
   if (err != 0) {
65
     fprintf(stderr, "%s: bind_service(%s): %s\n", self, service, gai_strerror(err));
65
     fprintf(stderr, "%s: bind_service(%s): %s\n", self, service, gai_strerror(err));
66
     return count;
66
     return count;
219
     "   -s<file>       read secrets from file (required)\n"
219
     "   -s<file>       read secrets from file (required)\n"
220
     "   -d<domain>     set domain name for rewrite (required)\n"
220
     "   -d<domain>     set domain name for rewrite (required)\n"
221
     "   -a<char>       set first separator character which can be one of: -=+ (default: =)\n"
221
     "   -a<char>       set first separator character which can be one of: -=+ (default: =)\n"
222
+    "   -l<addr>       set socket listen address (default: 127.0.0.1)\n"
222
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
223
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
223
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
224
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
224
     "   -p<pidfile>    write process ID to pidfile (default: none)\n"
225
     "   -p<pidfile>    write process ID to pidfile (default: none)\n"
243
 {
244
 {
244
   int opt, timeout = 1800, family = AF_UNSPEC;
245
   int opt, timeout = 1800, family = AF_UNSPEC;
245
   int daemonize = FALSE;
246
   int daemonize = FALSE;
246
-  char *forward_service = NULL, *reverse_service = NULL,
247
+  char *listen_addr = NULL, *forward_service = NULL, *reverse_service = NULL,
247
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
248
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
248
   char separator = '=';
249
   char separator = '=';
249
   char *secret_file = NULL, *pid_file = NULL;
250
   char *secret_file = NULL, *pid_file = NULL;
264
   tmp = strrchr(argv[0], '/');
265
   tmp = strrchr(argv[0], '/');
265
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
266
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
266
 
267
 
267
-  while ((opt = getopt(argc, argv, "46d:a:f:r:s:u:t:p:c:X::Dhev")) != -1) {
268
+  while ((opt = getopt(argc, argv, "46d:a:l:f:r:s:u:t:p:c:X::Dhev")) != -1) {
268
     switch (opt) {
269
     switch (opt) {
269
       case '?':
270
       case '?':
270
         return EXIT_FAILURE;
271
         return EXIT_FAILURE;
280
       case 'a':
281
       case 'a':
281
         separator = *optarg;
282
         separator = *optarg;
282
         break;
283
         break;
284
+      case 'l':
285
+        listen_addr = strdup(optarg);
286
+        break;
283
       case 'f':
287
       case 'f':
284
         forward_service = strdup(optarg);
288
         forward_service = strdup(optarg);
285
         break;
289
         break;
404
     return EXIT_FAILURE;
408
     return EXIT_FAILURE;
405
   }
409
   }
406
   /* Bind ports. May require privileges if the config specifies ports below 1024 */
410
   /* Bind ports. May require privileges if the config specifies ports below 1024 */
407
-  sc = bind_service(forward_service, family, &sockets[socket_count], 4 - socket_count);
411
+  sc = bind_service(listen_addr, forward_service, family, &sockets[socket_count], 4 - socket_count);
408
   if (sc == 0) return EXIT_FAILURE;
412
   if (sc == 0) return EXIT_FAILURE;
409
   while (sc-- > 0) handler[socket_count++] = handle_forward;
413
   while (sc-- > 0) handler[socket_count++] = handle_forward;
410
   free (forward_service);
414
   free (forward_service);
411
-  sc = bind_service(reverse_service, family, &sockets[socket_count], 4 - socket_count);
415
+  sc = bind_service(listen_addr, reverse_service, family, &sockets[socket_count], 4 - socket_count);
412
   if (sc == 0) return EXIT_FAILURE;
416
   if (sc == 0) return EXIT_FAILURE;
413
   while (sc-- > 0) handler[socket_count++] = handle_reverse;
417
   while (sc-- > 0) handler[socket_count++] = handle_reverse;
414
   free (reverse_service);
418
   free (reverse_service);

Loading…
Cancel
Save