#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <mach/boolean.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#include <signal.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <syslog.h>
#include "hostlist.h"
void
hostinsert(struct hosts * * hosts, struct hosts * hp)
{
hp->next = *hosts;
hp->prev = NULL;
if (*hosts)
(*hosts)->prev = hp;
*hosts = hp;
}
void
hostremove(struct hosts * * hosts, struct hosts * hp)
{
if (hp->prev)
hp->prev->next = hp->next;
else
*hosts = hp->next;
if (hp->next)
hp->next->prev = hp->prev;
}
void
hostprint(struct hosts * hp)
{
if (hp)
syslog(LOG_INFO,
"hw %s type %d len %d ip %s host '%s' bootfile '%s'\n",
ether_ntoa((struct ether_addr *)&hp->haddr), hp->htype,
hp->hlen, inet_ntoa(hp->iaddr),
hp->hostname ? hp->hostname : "",
hp->bootfile ? hp->bootfile : "");
}
void
hostfree(struct hosts * * hosts,
struct hosts *hp
)
{
hostremove(hosts, hp);
if (hp->hostname) {
free(hp->hostname);
hp->hostname = NULL;
}
if (hp->bootfile) {
free(hp->bootfile);
hp->bootfile = NULL;
}
free((char *)hp);
}
void
hostlistfree(struct hosts * * hosts)
{
while (*hosts)
hostfree(hosts, *hosts);
return;
}
struct hosts *
hostadd(struct hosts * * hosts, struct timeval * tv_p, int htype,
char * haddr, int hlen, struct in_addr * iaddr_p,
char * hostname, char * bootfile)
{
struct hosts * hp;
hp = (struct hosts *)malloc(sizeof(*hp));
if (!hp)
return (NULL);
bzero(hp, sizeof(*hp));
if (tv_p)
hp->tv = *tv_p;
hp->htype = htype;
hp->hlen = hlen;
if (hlen > sizeof(hp->haddr)) {
hlen = sizeof(hp->haddr);
}
bcopy(haddr, &hp->haddr, hlen);
if (iaddr_p)
hp->iaddr = *iaddr_p;
if (hostname)
hp->hostname = strdup(hostname);
if (bootfile)
hp->bootfile = strdup(bootfile);
hostinsert(hosts, hp);
return (hp);
}