caddr_t tha;
int retval;
- arp = xmalloc (arpsize);
- memset (arp, 0, arpsize);
-
+ arp = xzalloc (arpsize);
arp->ar_hrd = htons (iface->family);
arp->ar_pro = htons (ETHERTYPE_IP);
arp->ar_hln = iface->hwlen;
if (! iface)
goto eexit;
- state = xmalloc (sizeof (state_t));
- memset (state, 0, sizeof (state_t));
-
- state->dhcp = xmalloc (sizeof (dhcp_t));
- memset (state->dhcp, 0, sizeof (dhcp_t));
-
+ state = xzalloc (sizeof (state_t));
+ state->dhcp = xzalloc (sizeof (dhcp_t));
state->pidfd = pidfd;
state->interface = iface;
/* NOTREACHED */
}
+void *xzalloc (size_t s)
+{
+ void *value = xmalloc (s);
+ memset (value, 0, s);
+ return (value);
+}
+
void *xrealloc (void *ptr, size_t s)
{
void *value = realloc (ptr, s);
void writepid (int fd, pid_t pid);
void *xrealloc (void *ptr, size_t size);
void *xmalloc (size_t size);
+void *xzalloc (size_t size);
char *xstrdup (const char *str);
#endif
if (remember >= 0) {
if (! new_routes) {
new_routes = xmalloc (sizeof (route_t));
- memset (new_routes, 0, sizeof (route_t));
new_route = new_routes;
} else {
new_route->next = xmalloc (sizeof (route_t));
if (remember >= 0) {
if (! new_routes) {
new_routes = xmalloc (sizeof (route_t));
- memset (new_routes, 0, sizeof (route_t));
new_route = new_routes;
} else {
new_route->next = xmalloc (sizeof (route_t));
new_route = new_route->next;
- new_route->next = NULL;
}
new_route->destination.s_addr = dest.s_addr;
new_route->netmask.s_addr = mask.s_addr;
new_route->gateway.s_addr = gate.s_addr;
+ new_route->next = NULL;
}
}
#endif
if (type == DHCP_RELEASE)
to.s_addr = dhcp->serveraddress.s_addr;
- message = xmalloc (sizeof (dhcpmessage_t));
- memset (message, 0, sizeof (dhcpmessage_t));
+ message = xzalloc (sizeof (dhcpmessage_t));
m = (unsigned char *) message;
p = (unsigned char *) &message->options;
message_length = p - m;
- packet = xmalloc (sizeof (struct udp_dhcp_packet));
- memset (packet, 0, sizeof (struct udp_dhcp_packet));
+ packet = xzalloc (sizeof (struct udp_dhcp_packet));
make_dhcp_packet (packet, (unsigned char *) message, message_length,
from, to);
free (message);
if (len < 5)
return NULL;
- first = xmalloc (sizeof (route_t));
+ first = xzalloc (sizeof (route_t));
route = first;
while (q - p < len) {
/* We have another route */
if (q - p < len) {
- route->next = xmalloc (sizeof (route_t));
+ route->next = xzalloc (sizeof (route_t));
route = route->next;
}
}
for (i = 0; i < length; i += 4) {
if (*address == NULL) {
- *address = xmalloc (sizeof (address_t));
+ *address = xzalloc (sizeof (address_t));
p = *address;
} else {
- p->next = xmalloc (sizeof (address_t));
+ p->next = xzalloc (sizeof (address_t));
p = p->next;
}
- memset (p, 0, sizeof (address_t));
/* Sanity check */
if (i + 4 > length) {
for (i = 0; i < length; i += 8) {
if (routes) {
- routes->next = xmalloc (sizeof (route_t));
+ routes->next = xzalloc (sizeof (route_t));
routes = routes->next;
} else
- head = routes = xmalloc (sizeof (route_t));
- memset (routes, 0, sizeof (route_t));
+ head = routes = xzalloc (sizeof (route_t));
memcpy (&routes->destination.s_addr, data + i, 4);
memcpy (&routes->gateway.s_addr, data + i + 4, 4);
routes->netmask.s_addr =
for (i = 0; i < length; i += 4) {
if (routes) {
- routes->next = xmalloc (sizeof (route_t));
+ routes->next = xzalloc (sizeof (route_t));
routes = routes->next;
} else
- head = routes = xmalloc (sizeof (route_t));
- memset (routes, 0, sizeof (route_t));
+ head = routes = xzalloc (sizeof (route_t));
memcpy (&routes->gateway.s_addr, data + i, 4);
}
bool retval = true;
while ((token = strsep (&p, " "))) {
- address_t *a = xmalloc (sizeof (address_t));
- memset (a, 0, sizeof (address_t));
+ address_t *a = xzalloc (sizeof (address_t));
if (inet_aton (token, &a->address) == 0) {
logger (LOG_ERR, "%s: invalid address `%s'", var, token);
}
/* See if we can create a route */
- route = xmalloc (sizeof (route_t));
- memset (route, 0, sizeof (route_t));
+ route = xzalloc (sizeof (route_t));
if (inet_aton (dest, &route->destination) == 0) {
logger (LOG_ERR, "read_info ROUTES `%s': not a valid destination address",
dest);
} else if (strcmp (var, "GATEWAYS") == 0) {
p = value;
while ((value = strsep (&p, " "))) {
- route_t *route = xmalloc (sizeof (route_t));
- memset (route, 0, sizeof (route_t));
+ route_t *route = xzalloc (sizeof (route_t));
if (parse_address (&route->gateway, value, "GATEWAYS")) {
if (dhcp->routes) {
route_t *r = dhcp->routes;
}
}
- iface = xmalloc (sizeof (interface_t));
- memset (iface, 0, sizeof (interface_t));
+ iface = xzalloc (sizeof (interface_t));
strlcpy (iface->name, ifname, IF_NAMESIZE);
#ifdef ENABLE_INFO
snprintf (iface->infofile, PATH_MAX, INFOFILE, ifname);
return -1;
}
- buffer = xmalloc (sizeof (char) * BUFFERLEN);
- memset (buffer, 0, BUFFERLEN);
+ buffer = xzalloc (sizeof (char) * BUFFERLEN);
iov.iov_base = buffer;
for (;;) {
if (!ifname)
return -1;
- nlm = xmalloc (sizeof (struct nlma));
- memset (nlm, 0, sizeof (struct nlma));
-
+ nlm = xzalloc (sizeof (struct nlma));
nlm->hdr.nlmsg_len = NLMSG_LENGTH (sizeof (struct ifaddrmsg));
nlm->hdr.nlmsg_flags = NLM_F_REQUEST;
if (! del)
return -1;
}
- nlm = xmalloc (sizeof (struct nlmr));
- memset (nlm, 0, sizeof (struct nlmr));
-
+ nlm = xzalloc (sizeof (struct nlmr));
nlm->hdr.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtmsg));
if (change)
nlm->hdr.nlmsg_flags = NLM_F_REPLACE;