return (false);
/* Vitaly important we remove the server information here */
- memset (&dhcp->serveraddress, 0, sizeof (struct in_addr));
+ memset (&dhcp->serveraddress, 0, sizeof (dhcp->serveraddress));
memset (dhcp->servername, 0, sizeof (dhcp->servername));
#ifdef ENABLE_ARP
(! options->doipv4ll ||
arp_claim (iface, dhcp->address)))))
{
- memset (&dhcp->address, 0, sizeof (struct in_addr));
- memset (&dhcp->netmask, 0, sizeof (struct in_addr));
- memset (&dhcp->broadcast, 0, sizeof (struct in_addr));
+ memset (&dhcp->address, 0, sizeof (dhcp->address));
+ memset (&dhcp->netmask, 0, sizeof (dhcp->netmask));
+ memset (&dhcp->broadcast, 0, sizeof (dhcp->broadcast));
return (false);
}
if (! iroute)
iroute = iface->previous_routes =
- xmalloc (sizeof (route_t));
+ xmalloc (sizeof (*iroute));
- memcpy (iroute, route, sizeof (route_t));
+ memcpy (iroute, route, sizeof (*iroute));
if (route->next) {
- iroute->next = xmalloc (sizeof (route_t));
+ iroute->next = xmalloc (sizeof (*iroute));
iroute = iroute->next;
}
}
configure (options, state->interface, state->dhcp, false);
free_dhcp (state->dhcp);
- memset (state->dhcp, 0, sizeof (dhcp_t));
+ memset (state->dhcp, 0, sizeof (*state->dhcp));
}
static int wait_for_packet (fd_set *rset, state_t *state,
do_socket (state, SOCKET_CLOSED);
free_dhcp (dhcp);
- memset (dhcp, 0, sizeof (dhcp_t));
+ memset (dhcp, 0, sizeof (*dhcp));
#ifdef ENABLE_INFO
if (! options->test &&
if (options->dolastlease)
return (-1);
free_dhcp (dhcp);
- memset (dhcp, 0, sizeof (dhcp_t));
+ memset (dhcp, 0, sizeof (*dhcp));
} else if (errno == EINTR)
return (0);
}
{
logger (LOG_INFO, "probing for an IPV4LL address");
free_dhcp (dhcp);
- memset (dhcp, 0, sizeof (dhcp_t));
+ memset (dhcp, 0, sizeof (*dhcp));
if (ipv4ll_get_address (iface, dhcp) == -1) {
if (! state->daemonised)
return (-1);
case STATE_BOUND:
case STATE_RENEW_REQUESTED:
if (IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) {
- memset (&dhcp->address, 0, sizeof (struct in_addr));
+ memset (&dhcp->address, 0, sizeof (dhcp->address));
state->state = STATE_INIT;
state->xid = 0;
break;
break;
case STATE_REBINDING:
logger (LOG_ERR, "lost lease, attemping to rebind");
- memset (&dhcp->address, 0, sizeof (struct in_addr));
+ memset (&dhcp->address, 0, sizeof (dhcp->address));
do_socket (state, SOCKET_OPEN);
if (state->xid == 0)
state->xid = (uint32_t) random ();
state->timeout = 0;
state->xid = 0;
free_dhcp (dhcp);
- memset (dhcp, 0, sizeof (dhcp_t));
+ memset (dhcp, 0, sizeof (*dhcp));
/* If we constantly get NAKS then we should slowly back off */
if (state->nakoff > 0) {
do_socket (state, SOCKET_CLOSED);
free_dhcp (dhcp);
- memset (dhcp, 0, sizeof (dhcp_t));
+ memset (dhcp, 0, sizeof (*dhcp));
state->xid = 0;
state->timeout = 0;
state->state = STATE_INIT;
the first one fails for any reason, we can use the next. */
memset (&message, 0, sizeof (struct dhcpmessage_t));
- new_dhcp = xmalloc (sizeof (dhcp_t));
+ new_dhcp = xmalloc (sizeof (*new_dhcp));
do {
if (get_packet (iface, (unsigned char *) &message,
}
logger (LOG_DEBUG, "got a packet with xid 0x%x", message.xid);
- memset (new_dhcp, 0, sizeof (dhcp_t));
+ memset (new_dhcp, 0, sizeof (*new_dhcp));
type = parse_dhcpmessage (new_dhcp, &message);
if (type == -1) {
logger (LOG_ERR, "failed to parse packet");
if (! iface)
goto eexit;
- state = xzalloc (sizeof (state_t));
- state->dhcp = xzalloc (sizeof (dhcp_t));
+ state = xzalloc (sizeof (*state));
+ state->dhcp = xzalloc (sizeof (*state->dhcp));
state->pidfd = pidfd;
state->interface = iface;
salen = sizeof (struct sockaddr);
memset (&su.sa, 0, salen);
su.sin.sin_family = AF_INET;
- memcpy (&su.sin.sin_addr, &dhcp->address, sizeof (struct in_addr));
+ memcpy (&su.sin.sin_addr, &dhcp->address, sizeof (su.sin.sin_addr));
if ((result = getnameinfo (&su.sa, salen, addr, NI_MAXHOST,
NULL, 0, NI_NAMEREQD)) != 0) {
iface->previous_address,
iface->previous_netmask);
memset (&iface->previous_address,
- 0, sizeof (struct in_addr));
+ 0, sizeof (iface->previous_address));
memset (&iface->previous_netmask,
- 0, sizeof (struct in_addr));
+ 0, sizeof (iface->previous_netmask));
}
}
if (remember >= 0) {
if (! new_routes) {
- new_routes = xmalloc (sizeof (route_t));
+ new_routes = xmalloc (sizeof (*new_routes));
new_route = new_routes;
} else {
- new_route->next = xmalloc (sizeof (route_t));
+ new_route->next = xmalloc (sizeof (*new_route));
new_route = new_route->next;
}
- memcpy (new_route, route, sizeof (route_t));
+ memcpy (new_route, route, sizeof (*new_route));
new_route -> next = NULL;
}
#ifdef THERE_IS_NO_FORK
if (remember >= 0) {
if (! new_routes) {
- new_routes = xmalloc (sizeof (route_t));
+ new_routes = xmalloc (sizeof (*new_routes));
new_route = new_routes;
} else {
- new_route->next = xmalloc (sizeof (route_t));
+ new_route->next = xmalloc (sizeof (*new_route));
new_route = new_route->next;
}
new_route->destination.s_addr = dest.s_addr;
iface->previous_netmask.s_addr != dhcp->netmask.s_addr)
{
memcpy (&iface->previous_address,
- &dhcp->address, sizeof (struct in_addr));
+ &dhcp->address, sizeof (iface->previous_address));
memcpy (&iface->previous_netmask,
- &dhcp->netmask, sizeof (struct in_addr));
+ &dhcp->netmask, sizeof (iface->previous_netmask));
exec_script (options->script, iface->infofile, "new");
} else
exec_script (options->script, iface->infofile, "up");
if (type == DHCP_RELEASE)
to.s_addr = dhcp->serveraddress.s_addr;
- message = xzalloc (sizeof (dhcpmessage_t));
+ message = xzalloc (sizeof (*message));
m = (unsigned char *) message;
p = (unsigned char *) &message->options;
message_length = p - m;
- packet = xzalloc (sizeof (struct udp_dhcp_packet));
+ packet = xzalloc (sizeof (*packet));
make_dhcp_packet (packet, (unsigned char *) message, message_length,
from, to);
free (message);
if (len < 5)
return NULL;
- first = xzalloc (sizeof (route_t));
+ first = xzalloc (sizeof (*first));
route = first;
while (q - p < len) {
- memset (route, 0, sizeof (route_t));
+ memset (route, 0, sizeof (*route));
cidr = *q++;
if (cidr > 32) {
/* We have another route */
if (q - p < len) {
- route->next = xzalloc (sizeof (route_t));
+ route->next = xzalloc (sizeof (*route));
route = route->next;
}
}
for (i = 0; i < length; i += 8) {
if (routes) {
- routes->next = xzalloc (sizeof (route_t));
+ routes->next = xzalloc (sizeof (*routes));
routes = routes->next;
} else
- head = routes = xzalloc (sizeof (route_t));
+ head = routes = xzalloc (sizeof (*head));
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 = xzalloc (sizeof (route_t));
+ routes->next = xzalloc (sizeof (*routes));
routes = routes->next;
} else
- head = routes = xzalloc (sizeof (route_t));
+ head = routes = xzalloc (sizeof (*head));
memcpy (&routes->gateway.s_addr, data + i, 4);
}
openlog (PACKAGE, LOG_PID, LOG_LOCAL0);
- options = xmalloc (sizeof (options_t));
- memset (options, 0, sizeof (options_t));
+ options = xzalloc (sizeof (*options));
options->script = (char *) DEFAULT_SCRIPT;
snprintf (options->classid, CLASS_ID_MAX_LEN, "%s %s",
PACKAGE, VERSION);
}
/* See if we can create a route */
- route = xzalloc (sizeof (route_t));
+ route = xzalloc (sizeof (*route));
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 = xzalloc (sizeof (route_t));
+ route_t *route = xzalloc (sizeof (*route));
if (parse_address (&route->gateway, value, "GATEWAYS")) {
if (dhcp->routes) {
route_t *r = dhcp->routes;
}
ocets = (cidr + 7) / 8;
- memset (addr, 0, sizeof (struct in_addr));
+ memset (addr, 0, sizeof (*addr));
if (ocets > 0) {
memset (&addr->s_addr, 255, (size_t) ocets - 1);
memset ((unsigned char *) &addr->s_addr + (ocets - 1),
/* Not all implementations return the needed buffer size for
* SIOGIFCONF so we loop like so for all until it works */
- memset (&ifc, 0, sizeof (struct ifconf));
+ memset (&ifc, 0, sizeof (ifc));
for (;;) {
ifc.ifc_len = len;
ifc.ifc_buf = xmalloc ((size_t) len);
if (hwaddr && hwlen && ifr->ifr_addr.sa_family == AF_LINK) {
struct sockaddr_dl sdl;
- memcpy (&sdl, &ifr->ifr_addr,
- sizeof (struct sockaddr_dl));
+ memcpy (&sdl, &ifr->ifr_addr, sizeof (sdl));
*hwlen = sdl.sdl_alen;
memcpy (hwaddr, sdl.sdl_data + sdl.sdl_nlen,
(size_t) sdl.sdl_alen);
#endif
if (ifr->ifr_addr.sa_family == AF_INET) {
- memcpy (&address, &ifr->ifr_addr,
- sizeof (struct sockaddr_in));
+ memcpy (&address, &ifr->ifr_addr, sizeof (address));
if (flush) {
struct sockaddr_in netmask;
continue;
}
memcpy (&netmask, &ifr->ifr_addr,
- sizeof (struct sockaddr_in));
+ sizeof (netmask));
if (del_address (ifname,
address.sin_addr,
if (! ifname)
return NULL;
- memset (&ifr, 0, sizeof (struct ifreq));
+ memset (&ifr, 0, sizeof (ifr));
strlcpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if ((s = socket (AF_INET, SOCK_DGRAM, 0)) == -1) {
}
}
- iface = xzalloc (sizeof (interface_t));
+ iface = xzalloc (sizeof (*iface));
strlcpy (iface->name, ifname, IF_NAMESIZE);
#ifdef ENABLE_INFO
snprintf (iface->infofile, PATH_MAX, INFOFILE, ifname);
return (-1);
}
- memset (&ifr, 0, sizeof (struct ifreq));
+ memset (&ifr, 0, sizeof (ifr));
strlcpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
r = ioctl (s, SIOCGIFMTU, &ifr);
close (s);
return (-1);
}
- memset (&ifr, 0, sizeof (struct ifreq));
+ memset (&ifr, 0, sizeof (ifr));
logger (LOG_DEBUG, "setting MTU to %d", mtu);
strlcpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
ifr.ifr_mtu = mtu;
union { struct sockaddr *sa; struct sockaddr_in *sin; } _s; \
_s.sa = &_var; \
_s.sin->sin_family = AF_INET; \
- _s.sin->sin_len = sizeof (struct sockaddr_in); \
- memcpy (&_s.sin->sin_addr, &_addr, sizeof (struct in_addr)); \
+ _s.sin->sin_len = sizeof (*_s.sin); \
+ memcpy (&_s.sin->sin_addr, &_addr, sizeof (_s.sin->sin_addr)); \
}
ADDADDR (ifa.ifra_addr, address);
return -1;
}
- memset (&rtm, 0, sizeof (struct rtm));
+ memset (&rtm, 0, sizeof (rtm));
rtm.hdr.rtm_version = RTM_VERSION;
rtm.hdr.rtm_seq = ++seq;
return -1;
}
- memset (&nl, 0, sizeof (struct sockaddr_nl));
+ memset (&nl, 0, sizeof (nl));
nl.nl_family = AF_NETLINK;
if (bind (s, (struct sockaddr *) &nl, sizeof (nl)) == -1) {
logger (LOG_ERR, "bind: %s", strerror (errno));
return -1;
}
- memset (&iov, 0, sizeof (struct iovec));
+ memset (&iov, 0, sizeof (iov));
iov.iov_base = hdr;
iov.iov_len = hdr->nlmsg_len;
- memset (&msg, 0, sizeof (struct msghdr));
+ memset (&msg, 0, sizeof (msg));
msg.msg_name = &nl;
msg.msg_namelen = sizeof (nl);
msg.msg_iov = &iov;
static int add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type,
uint32_t data)
{
- int len = RTA_LENGTH (sizeof (uint32_t));
+ int len = RTA_LENGTH (sizeof (data));
struct rtattr *rta;
if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen) {
rta = NLMSG_TAIL (n);
rta->rta_type = type;
rta->rta_len = len;
- memcpy (RTA_DATA (rta), &data, sizeof (uint32_t));
+ memcpy (RTA_DATA (rta), &data, sizeof (data));
n->nlmsg_len = NLMSG_ALIGN (n->nlmsg_len) + len;
return 0;
if (!ifname)
return -1;
- nlm = xzalloc (sizeof (struct nlma));
+ nlm = xzalloc (sizeof (*nlm));
nlm->hdr.nlmsg_len = NLMSG_LENGTH (sizeof (struct ifaddrmsg));
nlm->hdr.nlmsg_flags = NLM_F_REQUEST;
if (! del)
nlm->ifa.ifa_prefixlen = inet_ntocidr (netmask);
/* This creates the aliased interface */
- add_attr_l (&nlm->hdr, sizeof (struct nlma), IFA_LABEL,
+ add_attr_l (&nlm->hdr, sizeof (*nlm), IFA_LABEL,
ifname, strlen (ifname) + 1);
- add_attr_l (&nlm->hdr, sizeof (struct nlma), IFA_LOCAL,
+ add_attr_l (&nlm->hdr, sizeof (*nlm), IFA_LOCAL,
&address.s_addr, sizeof (address.s_addr));
if (! del)
- add_attr_l (&nlm->hdr, sizeof (struct nlma), IFA_BROADCAST,
+ add_attr_l (&nlm->hdr, sizeof (*nlm), IFA_BROADCAST,
&broadcast.s_addr, sizeof (broadcast.s_addr));
retval = send_netlink (&nlm->hdr);
return -1;
}
- nlm = xzalloc (sizeof (struct nlmr));
+ nlm = xzalloc (sizeof (*nlm));
nlm->hdr.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtmsg));
if (change)
nlm->hdr.nlmsg_flags = NLM_F_REPLACE;
}
nlm->rt.rtm_dst_len = inet_ntocidr (netmask);
- add_attr_l (&nlm->hdr, sizeof (struct nlmr), RTA_DST,
+ add_attr_l (&nlm->hdr, sizeof (*nlm), RTA_DST,
&destination.s_addr, sizeof (destination.s_addr));
if (netmask.s_addr != INADDR_BROADCAST &&
destination.s_addr != gateway.s_addr)
- add_attr_l (&nlm->hdr, sizeof (struct nlmr), RTA_GATEWAY,
+ add_attr_l (&nlm->hdr, sizeof (*nlm), RTA_GATEWAY,
&gateway.s_addr, sizeof (gateway.s_addr));
- add_attr_32 (&nlm->hdr, sizeof (struct nlmr), RTA_OIF, ifindex);
- add_attr_32 (&nlm->hdr, sizeof (struct nlmr), RTA_PRIORITY, metric);
+ add_attr_32 (&nlm->hdr, sizeof (*nlm), RTA_OIF, ifindex);
+ add_attr_32 (&nlm->hdr, sizeof (*nlm), RTA_PRIORITY, metric);
retval = send_netlink (&nlm->hdr);
free (nlm);
fcntl (signal_pipe[i], F_SETFD, flags | FD_CLOEXEC) == -1)
logger (LOG_ERR ,"fcntl: %s", strerror (errno));
- memset (&sa, 0, sizeof (struct sigaction));
+ memset (&sa, 0, sizeof (sa));
sa.sa_handler = signal_handler;
sigemptyset (&sa.sa_mask);
for (i = 0; i < sizeof (handle_sigs) / sizeof (handle_sigs[0]); i++)
udp->uh_sport = htons (DHCP_CLIENT_PORT);
udp->uh_dport = htons (DHCP_SERVER_PORT);
- udp->uh_ulen = htons (sizeof (struct udphdr) + length);
+ udp->uh_ulen = htons (sizeof (*udp) + length);
ip->ip_len = udp->uh_ulen;
- udp->uh_sum = checksum ((unsigned char *) packet,
- sizeof (struct udp_dhcp_packet));
+ udp->uh_sum = checksum ((unsigned char *) packet, sizeof (*packet));
ip->ip_v = IPVERSION;
ip->ip_hl = 5;
ip->ip_id = 0;
ip->ip_tos = IPTOS_LOWDELAY;
- ip->ip_len = htons (sizeof (struct ip) + sizeof (struct udphdr) +
- length);
+ ip->ip_len = htons (sizeof (*ip) + sizeof (*udp) + length);
ip->ip_id = 0;
ip->ip_off = htons (IP_DF); /* Don't fragment */
ip->ip_ttl = IPDEFTTL;
- ip->ip_sum = checksum ((unsigned char *) ip, sizeof (struct ip));
+ ip->ip_sum = checksum ((unsigned char *) ip, sizeof (*ip));
}
static int valid_dhcp_packet (unsigned char *data)
d.data = data;
d.packet->ip.ip_sum = 0;
if (ipsum != checksum ((unsigned char *) &d.packet->ip,
- sizeof (struct ip)))
+ sizeof (d.packet->ip)))
{
logger (LOG_DEBUG, "bad IP header checksum, ignoring");
retval = -1;
goto eexit;
}
- memcpy (&source, &d.packet->ip.ip_src, sizeof (struct in_addr));
- memcpy (&dest, &d.packet->ip.ip_dst, sizeof (struct in_addr));
- memset (&d.packet->ip, 0, sizeof (struct ip));
+ memcpy (&source, &d.packet->ip.ip_src, sizeof (source));
+ memcpy (&dest, &d.packet->ip.ip_dst, sizeof (dest));
+ memset (&d.packet->ip, 0, sizeof (d.packet->ip));
d.packet->udp.uh_sum = 0;
d.packet->ip.ip_p = IPPROTO_UDP;
- memcpy (&d.packet->ip.ip_src, &source, sizeof (struct in_addr));
- memcpy (&d.packet->ip.ip_dst, &dest, sizeof (struct in_addr));
+ memcpy (&d.packet->ip.ip_src, &source, sizeof (source));
+ memcpy (&d.packet->ip.ip_dst, &dest, sizeof (dest));
d.packet->ip.ip_len = d.packet->udp.uh_ulen;
if (udpsum && udpsum != checksum (d.data, bytes)) {
logger (LOG_ERR, "bad UDP checksum, ignoring");
return -1;
}
- memset (&ifr, 0, sizeof (struct ifreq));
+ memset (&ifr, 0, sizeof (ifr));
strlcpy (ifr.ifr_name, iface->name, sizeof (ifr.ifr_name));
if (ioctl (fd, BIOCSETIF, &ifr) == -1) {
logger (LOG_ERR,
if (iface->family == ARPHRD_ETHER) {
struct ether_header hw;
- memset (&hw, 0, sizeof (struct ether_header));
+ memset (&hw, 0, sizeof (hw));
memset (&hw.ether_dhost, 0xff, ETHER_ADDR_LEN);
hw.ether_type = htons (type);
iov[0].iov_base = &hw;
- iov[0].iov_len = sizeof (struct ether_header);
+ iov[0].iov_len = sizeof (hw);
} else {
logger (LOG_ERR, "unsupported interace type %d", iface->family);
return -1;
break;
hdr.buffer = bpf.buffer + bpf.packet->bh_hdrlen;
- payload = hdr.buffer + sizeof (struct ether_header);
+ payload = hdr.buffer + sizeof (*hdr.hw);
/* If it's an ARP reply, then just send it back */
if (hdr.hw->ether_type == htons (ETHERTYPE_ARP)) {
len = bpf.packet->bh_caplen -
- sizeof (struct ether_header);
+ sizeof (*hdr.hw);
memcpy (data, payload, len);
have_data = true;
} else {
return (-1);
}
- memset (&su, 0, sizeof (struct sockaddr_storage));
+ memset (&su, 0, sizeof (su));
su.sll.sll_family = PF_PACKET;
su.sll.sll_protocol = htons (protocol);
if (! (su.sll.sll_ifindex = if_nametoindex (iface->name))) {
}
/* Install the DHCP filter */
+ memset (&pf, 0, sizeof (pf));
if (protocol == ETHERTYPE_ARP) {
pf.filter = arp_bpf_filter;
pf.len = sizeof (arp_bpf_filter) / sizeof (arp_bpf_filter[0]);
pf.len = sizeof (dhcp_bpf_filter) / sizeof (dhcp_bpf_filter[0]);
}
if (setsockopt (fd, SOL_SOCKET, SO_ATTACH_FILTER,
- &pf, sizeof (struct sock_fprog)) != 0)
+ &pf, sizeof (pf)) != 0)
{
logger (LOG_ERR, "SO_ATTACH_FILTER: %s", strerror (errno));
close (fd);
return (-1);
}
- if (bind (fd, &su.sa, sizeof (struct sockaddr_storage)) == -1)
+ if (bind (fd, &su.sa, sizeof (su)) == -1)
{
logger (LOG_ERR, "bind: %s", strerror (errno));
close (fd);
if (! iface)
return (-1);
- memset (&su, 0, sizeof (struct sockaddr_storage));
+ memset (&su, 0, sizeof (su));
su.sll.sll_family = AF_PACKET;
su.sll.sll_protocol = htons (type);
memset (&su.sll.sll_addr, 0xff, iface->hwlen);
if ((retval = sendto (iface->fd, data, len, 0, &su.sa,
- sizeof (struct sockaddr_storage))) == -1)
+ sizeof (su))) == -1)
logger (LOG_ERR, "sendto: %s", strerror (errno));
return (retval);