- FILE *f;
- u32 buf[2];
-
- if (!config->save_state)
- return;
-
- do
- {
- if (!(f = fopen(STATEFILE, "w")))
- break;
-
- log(1, 0, 0, 0, "Dumping state information\n");
-
- if (fwrite(DUMP_MAGIC, sizeof(DUMP_MAGIC) - 1, 1, f) != 1)
- break;
-
- log(2, 0, 0, 0, "Dumping %u ip addresses\n", ip_pool_size);
- buf[0] = ip_pool_size;
- buf[1] = sizeof(ippoolt);
- if (fwrite(buf, sizeof(buf), 1, f) != 1)
- break;
- if (fwrite(ip_address_pool, sizeof(ippoolt), ip_pool_size, f) != ip_pool_size)
- break;
-
- log(2, 0, 0, 0, "Dumping %u tunnels\n", MAXTUNNEL);
- buf[0] = MAXTUNNEL;
- buf[1] = sizeof(tunnelt);
- if (fwrite(buf, sizeof(buf), 1, f) != 1)
- break;
- if (fwrite(tunnel, sizeof(tunnelt), MAXTUNNEL, f) != MAXTUNNEL)
- break;
-
- log(2, 0, 0, 0, "Dumping %u sessions\n", MAXSESSION);
- buf[0] = MAXSESSION;
- buf[1] = sizeof(sessiont);
- if (fwrite(buf, sizeof(buf), 1, f) != 1)
- break;
- if (fwrite(session, sizeof(sessiont), MAXSESSION, f) != MAXSESSION)
- break;
-
- if (fclose(f) == 0)
- return ; // OK
- }
- while (0);
-
- log(0, 0, 0, 0, "Can't write state information: %s\n", strerror(errno));
- unlink(STATEFILE);