+struct out_host {
+ char name[32];
+ struct nwho_pkt *pkt;
+};
+
+struct out_user {
+ struct userinfo *user;
+ struct out_host *host;
+};
+
+static struct out_host **host_array;
+static int num_hosts;
+static int max_hosts = 16;
+
+static struct out_user *user_array;
+static int num_users;
+static int max_users = 16;
+
+static void *
+xmalloc(size_t size)
+{
+ void *p = malloc(size);
+ if (!p)
+ die("Out of memory");
+ return p;
+}
+
+static struct out_host *
+new_host(struct nwho_pkt *orig_pkt, char *name)
+{
+ int len = nwho_pkt_size(orig_pkt);
+ struct nwho_pkt *pkt = xmalloc(len);
+ memcpy(pkt, orig_pkt, len);
+
+ struct out_host *host = xmalloc(sizeof(*host));
+ snprintf(host->name, sizeof(host->name), "%s", name);
+ host->pkt = pkt;
+
+ if (!host_array || num_hosts >= max_hosts)
+ {
+ max_hosts *= 2;
+ host_array = realloc(host_array, max_hosts * sizeof(struct out_host));
+ }
+ host_array[num_hosts++] = host;
+
+ return host;
+}
+
+static void
+new_user(struct out_host *host, struct userinfo *ui)
+{
+ if (!user_array || num_users >= max_users)
+ {
+ max_users *= 2;
+ user_array = realloc(user_array, max_users * sizeof(struct out_user));
+ }
+ user_array[num_users++] = (struct out_user) {
+ .user = ui,
+ .host = host
+ };
+}
+