#define BASEDIR "/var/lib/nfs"
#endif
-#define _SM_STATE_PATH BASEDIR "/state"
-#define _SM_DIR_PATH BASEDIR "/sm"
-#define _SM_BAK_PATH _SM_DIR_PATH ".bak"
+#define DEFAULT_SM_STATE_PATH BASEDIR "/state"
+#define DEFAULT_SM_DIR_PATH BASEDIR "/sm"
+#define DEFAULT_SM_BAK_PATH DEFAULT_SM_DIR_PATH ".bak"
+
+char *_SM_BASE_PATH = BASEDIR;
+char *_SM_STATE_PATH = DEFAULT_SM_STATE_PATH;
+char *_SM_DIR_PATH = DEFAULT_SM_DIR_PATH;
+char *_SM_BAK_PATH = DEFAULT_SM_BAK_PATH;
#define NSM_PROG 100024
#define NSM_PROGRAM 100024
static void get_hosts(const char *);
static void insert_host(struct nsm_host *);
struct nsm_host * find_host(uint32_t);
-static int addr_parse(int, const char *, nsm_address *);
static int addr_get_port(nsm_address *);
static void addr_set_port(nsm_address *, int);
static int host_lookup(int, const char *, nsm_address *);
{
int c;
- while ((c = getopt(argc, argv, "dm:np:v:q")) != -1) {
+ while ((c = getopt(argc, argv, "dm:np:v:qP:")) != -1) {
switch (c) {
case 'd':
opt_debug++;
case 'q':
opt_quiet = 1;
break;
+ case 'P':
+ _SM_BASE_PATH = strdup(optarg);
+ _SM_STATE_PATH = malloc(strlen(optarg)+1+sizeof("state"));
+ _SM_DIR_PATH = malloc(strlen(optarg)+1+sizeof("sm"));
+ _SM_BAK_PATH = malloc(strlen(optarg)+1+sizeof("sm.bak"));
+ if (_SM_BASE_PATH == NULL ||
+ _SM_STATE_PATH == NULL ||
+ _SM_DIR_PATH == NULL ||
+ _SM_BAK_PATH == NULL) {
+ nsm_log(LOG_WARNING, "unable to allocate memory");
+ exit(1);
+ }
+ strcat(strcpy(_SM_STATE_PATH, _SM_BASE_PATH), "/state");
+ strcat(strcpy(_SM_DIR_PATH, _SM_BASE_PATH), "/sm");
+ strcat(strcpy(_SM_BAK_PATH, _SM_BASE_PATH), "/sm.bak");
+ break;
+
default:
goto usage;
}
/* Bind source IP if provided on command line */
if (opt_srcaddr) {
- if (!addr_parse(AF_INET, opt_srcaddr, &local_addr)
- && !host_lookup(AF_INET, opt_srcaddr, &local_addr)) {
+ if (!host_lookup(AF_INET, opt_srcaddr, &local_addr)) {
nsm_log(LOG_WARNING,
"Not a valid hostname or address: \"%s\"\n",
opt_srcaddr);
host = calloc(1, sizeof(*host));
snprintf(path, sizeof(path), "%s/%s", dirname, de->d_name);
- if (!addr_parse(AF_INET, de->d_name, &host->addr)
- && !addr_parse(AF_INET6, de->d_name, &host->addr)
- && !host_lookup(AF_INET, de->d_name, &host->addr)) {
+ if (!host_lookup(AF_UNSPEC, de->d_name, &host->addr)) {
nsm_log(LOG_WARNING,
"%s doesn't seem to be a valid address, skipped",
de->d_name);
/*
* Address handling utilities
*/
-static int
-addr_parse(int af, const char *name, nsm_address *addr)
-{
- void *ptr;
-
- if (af == AF_INET)
- ptr = &((struct sockaddr_in *) addr)->sin_addr;
- else if (af == AF_INET6)
- ptr = &((struct sockaddr_in6 *) addr)->sin6_addr;
- else
- return 0;
- if (inet_pton(af, name, ptr) <= 0)
- return 0;
- ((struct sockaddr *) addr)->sa_family = af;
- return 1;
-}
int
addr_get_port(nsm_address *addr)