+void load_state(void)
+{
+ DIR *d;
+ struct dirent *de;
+ char buf[LINELEN + 1 + SM_MAXSTRLEN + 2];
+
+ d = opendir(SM_DIR);
+ if (!d)
+ return;
+ while ((de = readdir(d))) {
+ char *path;
+ FILE *f;
+ int p;
+
+ if (de->d_name[0] == '.')
+ continue;
+ path = xmalloc(strlen(SM_DIR)+strlen(de->d_name)+2);
+ sprintf(path, "%s/%s", SM_DIR, de->d_name);
+ f = fopen(path, "r");
+ free(path);
+ if (f == NULL)
+ continue;
+ while (fgets(buf, sizeof(buf), f) != NULL) {
+ int addr, proc, prog, vers;
+ char priv[SM_PRIV_SIZE];
+ char *monname, *myname;
+ char *b;
+ int i;
+ notify_list *clnt;
+
+ buf[sizeof(buf)-1] = 0;
+ b = strchr(buf, '\n');
+ if (b) *b = 0;
+ sscanf(buf, "%x %x %x %x ",
+ &addr, &prog, &vers, &proc);
+ b = buf+36;
+ for (i=0; i<SM_PRIV_SIZE; i++) {
+ sscanf(b, "%2x", &p);
+ priv[i] = p;
+ b += 2;
+ }
+ b++;
+ monname = b;
+ while (*b && *b != ' ') b++;
+ if (*b) *b++ = '\0';
+ while (*b == ' ') b++;
+ myname = b;
+ clnt = nlist_new(myname, monname, 0);
+ if (!clnt)
+ break;
+ NL_ADDR(clnt).s_addr = addr;
+ NL_MY_PROG(clnt) = prog;
+ NL_MY_VERS(clnt) = vers;
+ NL_MY_PROC(clnt) = proc;
+ clnt->dns_name = xstrdup(de->d_name);
+ memcpy(NL_PRIV(clnt), priv, SM_PRIV_SIZE);
+ nlist_insert(&rtnl, clnt);
+ }
+ fclose(f);
+ }
+ closedir(d);
+}
+
+
+