#define ar_sha(ap) (((unsigned char *) ((ap) + 1)) + 0)
#define ar_spa(ap) (((unsigned char *) ((ap) + 1)) + (ap)->ar_hln)
#define ar_tha(ap) (((unsigned char *) ((ap) + 1)) + \
- (ap)->ar_hln + (ap)->ar_pln)
+ (ap)->ar_hln + (ap)->ar_pln)
#define ar_tpa(ap) (((unsigned char *) ((ap) + 1)) + \
- 2 * (ap)->ar_hln + (ap)->ar_pln)
+ 2 * (ap)->ar_hln + (ap)->ar_pln)
#endif
#ifndef arphdr_len
#define arphdr_len2(ar_hln, ar_pln) (sizeof (struct arphdr) + \
- 2 * (ar_hln) + 2 * (ar_pln))
+ 2 * (ar_hln) + 2 * (ar_pln))
#define arphdr_len(ap) (arphdr_len2 ((ap)->ar_hln, (ap)->ar_pln))
#endif
#ifdef ENABLE_ARP
static int send_arp (const interface_t *iface, int op, struct in_addr sip,
- const unsigned char *taddr, struct in_addr tip)
+ const unsigned char *taddr, struct in_addr tip)
{
struct arphdr *arp;
int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr));
memcpy (ar_tpa (arp), &tip, arp->ar_pln);
retval = send_packet (iface, ETHERTYPE_ARP,
- (unsigned char *) arp, arphdr_len (arp));
+ (unsigned char *) arp, arphdr_len (arp));
free (arp);
return (retval);
}
}
if (! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr)) &&
- ! IN_LINKLOCAL (ntohl (address.s_addr)))
- logger (LOG_INFO, "checking %s is available on attached networks",
- inet_ntoa (address));
+ ! IN_LINKLOCAL (ntohl (address.s_addr)))
+ logger (LOG_INFO,
+ "checking %s is available on attached networks",
+ inet_ntoa (address));
if (! open_socket (iface, true))
return (-1);
tv.tv_usec = timeout;
maxfd = signal_fd_set (&rset, iface->fd);
- if ((s = select (maxfd + 1, &rset, NULL, NULL, &tv)) == -1) {
+ s = select (maxfd + 1, &rset, NULL, NULL, &tv);
+ if (s == -1) {
if (errno == EINTR) {
if (signal_exists (NULL) == -1) {
errno = 0;
} else
break;
}
-
- logger (LOG_ERR, "select: `%s'", strerror (errno));
+
+ logger (LOG_ERR, "select: `%s'",
+ strerror (errno));
break;
}
}
if (nprobes < NPROBES) {
nprobes ++;
timeout = PROBE_INTERVAL;
- logger (LOG_DEBUG, "sending ARP probe #%d", nprobes);
+ logger (LOG_DEBUG, "sending ARP probe #%d",
+ nprobes);
if (send_arp (iface, ARPOP_REQUEST,
- null_address, NULL, address) == -1)
+ null_address, NULL,
+ address) == -1)
break;
/* IEEE1394 cannot set ARP target address
} else if (nclaims < NCLAIMS) {
nclaims ++;
timeout = CLAIM_INTERVAL;
- logger (LOG_DEBUG, "sending ARP claim #%d", nclaims);
+ logger (LOG_DEBUG, "sending ARP claim #%d",
+ nclaims);
if (send_arp (iface, ARPOP_REQUEST,
- address, iface->hwaddr, address) == -1)
+ address, iface->hwaddr,
+ address) == -1)
break;
} else {
/* No replies, so done */
memset (reply, 0, iface->buffer_length);
if ((bytes = get_packet (iface, (unsigned char *) reply,
- buffer,
- &buflen, &bufpos)) == -1)
+ buffer,
+ &buflen, &bufpos)) == -1)
break;
/* Only these types are recognised */
if (reply->ar_pln != sizeof (struct in_addr))
continue;
if ((unsigned) bytes < sizeof (reply) +
- 2 * (4 + reply->ar_hln))
+ 2 * (4 + reply->ar_hln))
continue;
rp.c = (unsigned char *) ar_spa (reply);
rh.c = (unsigned char *) ar_sha (reply);
- /* Ensure the ARP reply is for the address we asked for */
+ /* Ensure the ARP reply is for the our address */
if (rp.a->s_addr != address.s_addr)
continue;
- /* Some systems send a reply back from our hwaddress - weird */
+ /* Some systems send a reply back from our hwaddress,
+ * which is weird */
if (reply->ar_hln == iface->hwlen &&
- memcmp (rh.c, iface->hwaddr, iface->hwlen) == 0)
+ memcmp (rh.c, iface->hwaddr, iface->hwlen) == 0)
continue;
logger (LOG_ERR, "ARPOP_REPLY received from %s (%s)",
- inet_ntoa (*rp.a),
- hwaddr_ntoa (rh.c, reply->ar_hln));
+ inet_ntoa (*rp.a),
+ hwaddr_ntoa (rh.c, reply->ar_hln));
retval = -1;
goto eexit;
}
fd = open ("/dev/urandom", 0);
if (fd == -1 || read (fd, &seed, sizeof (seed)) == -1) {
- logger (LOG_WARNING, "Could not load seed from /dev/urandom: %s",
- strerror (errno));
+ logger (LOG_WARNING, "Could not read from /dev/urandom: %s",
+ strerror (errno));
seed = time (0);
}
if (fd >= 0)
if (ftruncate (fd, 0) == -1) {
logger (LOG_ERR, "ftruncate: %s", strerror (errno));
} else {
+ ssize_t len;
snprintf (spid, sizeof (spid), "%u", pid);
- if (pwrite (fd, spid, strlen (spid), 0) != (ssize_t) strlen (spid))
+ len = pwrite (fd, spid, strlen (spid), 0);
+ if (len != (ssize_t) strlen (spid))
logger (LOG_ERR, "pwrite: %s", strerror (errno));
}
}
if (! p) {
errno = ENOENT;
- return -1;
+ return (-1);
}
path = strdup (p);
}
}
free (path);
- return retval;
+ return (retval);
}
/* IMPORTANT: Ensure that the last parameter is NULL when calling */
if ((pid = vfork ()) == 0) {
if (execvp (cmd, argv) && errno != ENOENT)
logger (LOG_ERR, "error executing \"%s\": %s",
- cmd, strerror (errno));
+ cmd, strerror (errno));
_exit (0);
} else if (pid == -1) {
logger (LOG_ERR, "vfork: %s", strerror (errno));
}
static void exec_script (const char *script, const char *infofile,
- const char *arg)
+ const char *arg)
{
struct stat buf;
resolvconf = xmalloc (sizeof (char) * len);
snprintf (resolvconf, len, "resolvconf -a %s", ifname);
if ((f = popen (resolvconf , "w")))
- logger (LOG_DEBUG, "sending DNS information to resolvconf");
+ logger (LOG_DEBUG,
+ "sending DNS information to resolvconf");
else if (errno == EEXIST)
logger (LOG_ERR, "popen: %s", strerror (errno));
#endif
}
+static bool in_addresses (const address_t *addresses, struct in_addr addr)
+{
+ const address_t *address;
+
+ for (address = addresses; address; address = address->next)
+ if (address->address.s_addr == addr.s_addr)
+ return (true);
+
+ return (false);
+}
+
+static bool in_routes (const route_t *routes, route_t *route)
+{
+ const route_t *r;
+
+ for (r = routes; r; r=r->next)
+ if (r->destination.s_addr == route->destination.s_addr &&
+ r->netmask.s_addr == route->netmask.s_addr &&
+ r->gateway.s_addr == route->gateway.s_addr)
+ return (true);
+
+ return (false);
+}
+
#ifdef ENABLE_NTP
static int _make_ntp (const char *file, const char *ifname, const dhcp_t *dhcp)
{
We do this because ntp has to be restarted to work with a changed config */
if (! (f = fopen (file, "r"))) {
if (errno != ENOENT) {
- logger (LOG_ERR, "fopen `%s': %s", file, strerror (errno));
- return -1;
+ logger (LOG_ERR, "fopen `%s': %s",
+ file, strerror (errno));
+ return (-1);
}
} else {
- while ((line = getline (f))) {
+ while (tomatch != 0 && (line = getline (f))) {
+ struct in_addr addr;
+
a = line;
token = strsep (&a, " ");
- if (! token || strcmp (token, "server") != 0) {
- free (line);
- continue;
- }
+ if (! token || strcmp (token, "server") != 0)
+ goto next;
- if ((token = strsep (&a, " \n")) == NULL) {
- free (line);
- continue;
- }
+ if ((token = strsep (&a, " \n")) == NULL)
+ goto next;
- for (address = dhcp->ntpservers; address; address = address->next)
- if (strcmp (token, inet_ntoa (address->address)) == 0) {
- tomatch--;
- break;
- }
+ if (inet_aton (token, &addr) == 0 &&
+ in_addresses (dhcp->ntpservers, addr))
+ tomatch--;
- if (tomatch == 0) {
- free (line);
- break;
- }
+next:
+ free (line);
}
fclose (f);
- /* File has the same name servers that we do, so no need to restart ntp */
+ /* File has the same name servers that we do,
+ * so no need to restart ntp */
if (tomatch == 0) {
- logger (LOG_DEBUG, "%s already configured, skipping", file);
- return 0;
+ logger (LOG_DEBUG, "%s already configured, skipping",
+ file);
+ return (0);
}
}
logger (LOG_DEBUG, "writing %s", file);
if (! (f = fopen (file, "w"))) {
logger (LOG_ERR, "fopen `%s': %s", file, strerror (errno));
- return -1;
+ return (-1);
}
fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname);
}
fclose (f);
- return 1;
+ return (1);
}
static int make_ntp (const char *ifname, const dhcp_t *dhcp)
#ifdef NTPCHECK
if (system (NTPCHECK) == 0)
#endif
- retval += exec_cmd (NTPSERVICE, NTPRESTARTARGS, (char *) NULL);
+ retval += exec_cmd (NTPSERVICE, NTPRESTARTARGS,
+ (char *) NULL);
}
#endif
#if defined (NTPSERVICE) && defined (OPENNTPSERVICE)
if (restart_openntp &&
- (strcmp (NTPSERVICE, OPENNTPSERVICE) != 0 || ! restart_ntp))
+ (strcmp (NTPSERVICE, OPENNTPSERVICE) != 0 || ! restart_ntp))
{
#ifdef OPENNTPCHECK
if (system (OPENNTPCHECK) == 0)
#endif
- retval += exec_cmd (OPENNTPSERVICE, OPENNTPRESTARTARGS, (char *) NULL);
+ retval += exec_cmd (OPENNTPSERVICE,
+ OPENNTPRESTARTARGS, (char *) NULL);
}
#elif defined (OPENNTPSERVICE) && ! defined (NTPSERVICE)
if (restart_openntp) {
#ifdef OPENNTPCHECK
if (system (OPENNTPCHECK) == 0)
#endif
- retval += exec_cmd (OPENNTPSERVICE, OPENNTPRESTARTARGS, (char *) NULL);
+ retval += exec_cmd (OPENNTPSERVICE,
+ OPENNTPRESTARTARGS, (char *) NULL);
+ }
#endif
- return retval;
+ return (retval);
}
#endif
logger (LOG_DEBUG, "writing "NISFILE);
if (! (f = fopen(NISFILE, "w"))) {
logger (LOG_ERR, "fopen `%s': %s", NISFILE, strerror (errno));
- return -1;
+ return (-1);
}
prefix = xmalloc (sizeof (char) * PREFIXSIZE);
setdomainname (dhcp->nisdomain, strlen (dhcp->nisdomain));
if (dhcp->nisservers)
- snprintf (prefix, PREFIXSIZE, "domain %s server", dhcp->nisdomain);
+ snprintf (prefix, PREFIXSIZE, "domain %s server",
+ dhcp->nisdomain);
else
fprintf (f, "domain %s broadcast\n", dhcp->nisdomain);
}
if (system (NISCHECK) == 0)
#endif
exec_cmd (NISSERVICE, NISRESTARTARGS, (char *) NULL);
- return 0;
+ return (0);
}
#endif
+static char *lookuphostname (char *hostname, const dhcp_t *dhcp,
+ const options_t *options)
+{
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ } su;
+ socklen_t salen;
+ char *addr;
+ struct addrinfo hints;
+ struct addrinfo *res;
+ int result;
+ char *p;
+
+ logger (LOG_DEBUG, "Looking up hostname via DNS");
+ addr = xmalloc (sizeof (char) * NI_MAXHOST);
+ 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));
+
+ if ((result = getnameinfo (&su.sa, salen, addr, NI_MAXHOST,
+ NULL, 0, NI_NAMEREQD)) != 0) {
+ logger (LOG_ERR,
+ "Failed to lookup hostname via DNS: %s",
+ gai_strerror (result));
+ free (addr);
+ return (NULL);
+ }
+
+ /* Check for a malicious PTR record */
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_flags = AI_NUMERICHOST;
+ result = getaddrinfo (addr, "0", &hints, &res);
+ freeaddrinfo (res);
+ if (result == 0)
+ logger (LOG_ERR, "malicious PTR record detected");
+ if (result == 0 || ! *addr) {
+ free (addr);
+ return (NULL);
+ }
+
+ p = strchr (addr, '.');
+ if (p) {
+ switch (options->dohostname) {
+ case 1: /* -H */
+ case 4: /* -HHHH */
+ break;
+ case 2: /* -HH */
+ case 5: /* -HHHHH */
+ /* Strip out the domain if it matches */
+ p++;
+ if (*p && dhcp->dnssearch) {
+ char *s = xstrdup (dhcp->dnssearch);
+ char *sp = s;
+ char *t;
+
+ while ((t = strsep (&sp, " ")))
+ if (strcmp (t, p) == 0) {
+ *--p = '\0';
+ break;
+ }
+ free (s);
+ } else if (dhcp->dnsdomain) {
+ if (strcmp (dhcp->dnsdomain, p) == 0)
+ *--p = '\0';
+ }
+ break;
+ case 3: /* -HHH */
+ case 6: /* -HHHHHH */
+ /* Just strip the domain */
+ *p = '\0';
+ break;
+ default: /* Too many H! */
+ break;
+ }
+ }
+
+ strlcpy (hostname, addr, MAXHOSTNAMELEN);
+ free (addr);
+ return (hostname);
+}
+
int configure (const options_t *options, interface_t *iface,
- const dhcp_t *dhcp, bool up)
+ const dhcp_t *dhcp, bool up)
{
route_t *route = NULL;
route_t *new_routes = NULL;
route_t *new_route = NULL;
- route_t *old_route = NULL;
char *newhostname = NULL;
char *curhostname = NULL;
int remember;
bool haslinklocal = false;
#endif
#ifdef THERE_IS_NO_FORK
+ int skip = 0;
size_t skiplen;
char *skipp;
#endif
/* Remove old routes
Always do this as the interface may have >1 address not added by us
so the routes we added may still exist */
- if (iface->previous_routes) {
- for (route = iface->previous_routes; route; route = route->next)
- if (route->destination.s_addr || options->dogateway) {
- int have = 0;
- if (up)
- for (new_route = dhcp->routes; new_route; new_route = new_route->next)
- if (new_route->destination.s_addr == route->destination.s_addr
- && new_route->netmask.s_addr == route->netmask.s_addr
- && new_route->gateway.s_addr == route->gateway.s_addr)
- {
- have = 1;
- break;
- }
- if (! have)
- del_route (iface->name, route->destination, route->netmask,
- route->gateway, options->metric);
- }
- }
+ for (route = iface->previous_routes; route; route = route->next)
+ if ((route->destination.s_addr || options->dogateway) &&
+ (! up || ! in_routes (dhcp->routes, route)))
+ del_route (iface->name, route->destination,
+ route->netmask, route->gateway,
+ options->metric);
/* If we aren't up, then reset the interface as much as we can */
if (! up) {
/* Only reset things if we had set them before */
if (iface->previous_address.s_addr != 0) {
if (! options->keep_address) {
- del_address (iface->name, iface->previous_address,
- iface->previous_netmask);
- memset (&iface->previous_address, 0, sizeof (struct in_addr));
- memset (&iface->previous_netmask, 0, sizeof (struct in_addr));
+ del_address (iface->name,
+ iface->previous_address,
+ iface->previous_netmask);
+ memset (&iface->previous_address,
+ 0, sizeof (struct in_addr));
+ memset (&iface->previous_netmask,
+ 0, sizeof (struct in_addr));
}
}
restore_resolv (iface->name);
- /* we currently don't have a resolvconf style programs for ntp/nis */
-
exec_script (options->script, iface->infofile, "down");
return (0);
}
/* Set the MTU requested.
- If the DHCP server no longer sends one OR it's invalid then we restore
- the original MTU */
+ If the DHCP server no longer sends one OR it's invalid then
+ we restore the original MTU */
if (options->domtu) {
unsigned short mtu = iface->mtu;
if (dhcp->mtu)
/* This also changes netmask */
if (! options->doinform || ! has_address (iface->name, dhcp->address))
if (add_address (iface->name, dhcp->address, dhcp->netmask,
- dhcp->broadcast) == -1 && errno != EEXIST)
+ dhcp->broadcast) == -1 && errno != EEXIST)
return (false);
-
+
/* Now delete the old address if different */
- if (iface->previous_address.s_addr != dhcp->address.s_addr) {
- if (iface->previous_address.s_addr != 0 && ! options->keep_address)
- del_address (iface->name, iface->previous_address, iface->previous_netmask);
- }
+ if (iface->previous_address.s_addr != dhcp->address.s_addr &&
+ iface->previous_address.s_addr != 0 &&
+ ! options->keep_address)
+ del_address (iface->name,
+ iface->previous_address, iface->previous_netmask);
#ifdef __linux__
/* On linux, we need to change the subnet route to have our metric. */
- if (iface->previous_address.s_addr != dhcp->address.s_addr
- && options->metric > 0 && dhcp->netmask.s_addr != INADDR_BROADCAST)
+ if (iface->previous_address.s_addr != dhcp->address.s_addr &&
+ options->metric > 0 &&
+ dhcp->netmask.s_addr != INADDR_BROADCAST)
{
struct in_addr td;
struct in_addr tg;
#endif
/* Remember added routes */
- if (dhcp->routes) {
-#ifdef THERE_IS_NO_FORK
- int skip = 0;
-#endif
-
- for (route = dhcp->routes; route; route = route->next) {
+ for (route = dhcp->routes; route; route = route->next) {
#ifdef ENABLE_IPV4LL
- /* Check if we have already got a link locale route dished
- * out by the DHCP server */
- if (route->destination.s_addr == htonl (LINKLOCAL_ADDR) &&
- route->netmask.s_addr == htonl (LINKLOCAL_MASK))
- haslinklocal = true;
+ /* Check if we have already got a link locale route dished
+ * out by the DHCP server */
+ if (route->destination.s_addr == htonl (LINKLOCAL_ADDR) &&
+ route->netmask.s_addr == htonl (LINKLOCAL_MASK))
+ haslinklocal = true;
#endif
- /* Don't set default routes if not asked to */
- if (route->destination.s_addr == 0 && route->netmask.s_addr == 0
- && ! options->dogateway)
- continue;
-
- remember = add_route (iface->name, route->destination,
- route->netmask, route->gateway,
- options->metric);
- /* If we failed to add the route, we may have already added it
- ourselves. If so, remember it again. */
- if (remember < 0)
- for (old_route = iface->previous_routes; old_route;
- old_route = old_route->next)
- if (old_route->destination.s_addr == route->destination.s_addr
- && old_route->netmask.s_addr == route->netmask.s_addr
- && old_route->gateway.s_addr == route->gateway.s_addr)
- {
- remember = 1;
- break;
- }
-
- 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;
- }
- memcpy (new_route, route, sizeof (route_t));
- new_route -> next = NULL;
+ /* Don't set default routes if not asked to */
+ if (route->destination.s_addr == 0 &&
+ route->netmask.s_addr == 0 &&
+ ! options->dogateway)
+ continue;
+
+ remember = add_route (iface->name, route->destination,
+ route->netmask, route->gateway,
+ options->metric);
+ /* If we failed to add the route, we may have already added it
+ ourselves. If so, remember it again. */
+ if (remember < 0 && in_routes (iface->previous_routes, route))
+ remember = 1;
+
+ 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;
}
+ memcpy (new_route, route, sizeof (route_t));
+ new_route -> next = NULL;
+ }
#ifdef THERE_IS_NO_FORK
- /* If we have daemonised yet we need to record which routes
- * we failed to add so we can skip them */
- else if (! options->daemonised) {
- /* We can never have more than 255 / 4 routes, so 3 chars is
- * plently */
- if (*skipp)
- *skipp++ = ',';
- skipp += snprintf (skipp, dhcpcd_skiproutes + skiplen - skipp,
- "%d", skip);
- }
- skip++;
-#endif
+ /* If we have daemonised yet we need to record which routes
+ * we failed to add so we can skip them */
+ else if (! options->daemonised) {
+ /* We can never have more than 255 / 4 routes,
+ * so 3 chars is plently */
+ if (*skipp)
+ *skipp++ = ',';
+ skipp += snprintf (skipp,
+ dhcpcd_skiproutes + skiplen - skipp,
+ "%d", skip);
}
+ skip++;
+#endif
}
#ifdef THERE_IS_NO_FORK
/* Ensure we always add the link local route if we got a private
* address and isn't link local itself */
if (options->doipv4ll &&
- ! haslinklocal &&
- IN_PRIVATE (ntohl (dhcp->address.s_addr)))
+ ! haslinklocal &&
+ IN_PRIVATE (ntohl (dhcp->address.s_addr)))
{
struct in_addr dest;
struct in_addr mask;
mask.s_addr = htonl (LINKLOCAL_MASK);
gate.s_addr = 0;
remember = add_route (iface->name, dest, mask, gate,
- options->metric);
+ options->metric);
if (remember >= 0) {
if (! new_routes) {
curhostname = xmalloc (sizeof (char) * MAXHOSTNAMELEN);
*curhostname = '\0';
- newhostname = xmalloc (sizeof (char) * MAXHOSTNAMELEN);
- *newhostname = '\0';
-
- /* Now we have made a resolv.conf we can obtain a hostname if we need it */
- if (options->dohostname && (! dhcp->hostname || options->dohostname > 3)) {
- union {
- struct sockaddr sa;
- struct sockaddr_in sin;
- } su;
- socklen_t salen;
- char *addr;
- struct addrinfo hints, *res;
- int result;
-
- addr = xmalloc (sizeof (char) * NI_MAXHOST);
- 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));
-
- logger (LOG_DEBUG, "Looking up hostname via DNS");
- if ((result = getnameinfo (&su.sa, salen, addr, NI_MAXHOST,
- NULL, 0, NI_NAMEREQD)) != 0)
- logger (LOG_ERR, "Failed to lookup hostname via DNS: %s", gai_strerror (result));
- else {
- /* Check for a malicious PTR record */
- memset (&hints, 0, sizeof (hints));
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_flags = AI_NUMERICHOST;
- if (getaddrinfo (addr, "0", &hints, &res) == 0) {
- freeaddrinfo (res);
- addr[0] = '\0';
- logger (LOG_ERR, "malicious PTR record detected");
- } else if (*addr) {
- char *p = strchr (addr, '.');
- if (p) {
- switch (options->dohostname) {
- case 1: /* -H */
- case 4: /* -HHHH */
- break;
- case 2: /* -HH */
- case 5: /* -HHHHH */
- /* Strip out the domain if it matches */
- p++;
- if (*p && dhcp->dnssearch) {
- char *s = xstrdup (dhcp->dnssearch);
- char *sp = s;
- char *t;
-
- while ((t = strsep (&sp, " ")))
- if (strcmp (t, p) == 0) {
- *--p = '\0';
- break;
- }
- free (s);
- } else if (dhcp->dnsdomain) {
- if (strcmp (dhcp->dnsdomain, p) == 0)
- *--p = '\0';
- }
- break;
- case 3: /* -HHH */
- case 6: /* -HHHHHH */
- /* Just strip the domain */
- *p = '\0';
- break;
- default: /* Too many H! */
- break;
- }
- }
- strlcpy (newhostname, addr, MAXHOSTNAMELEN);
- }
- }
- free (addr);
- }
gethostname (curhostname, MAXHOSTNAMELEN);
-
- if (options->dohostname
- || strlen (curhostname) == 0
- || strcmp (curhostname, "(none)") == 0
- || strcmp (curhostname, "localhost") == 0)
+ if (options->dohostname ||
+ strlen (curhostname) == 0 ||
+ strcmp (curhostname, "(none)") == 0 ||
+ strcmp (curhostname, "localhost") == 0)
{
+ newhostname = xmalloc (sizeof (char) * MAXHOSTNAMELEN);
+
if (dhcp->hostname)
strlcpy (newhostname, dhcp->hostname, MAXHOSTNAMELEN);
+ else
+ *newhostname = '\0';
+
+ /* Now we have made a resolv.conf we can obtain a hostname
+ * if we need it */
+ if (! *newhostname && options->dohostname > 3)
+ lookuphostname (newhostname, dhcp, options);
if (*newhostname) {
- logger (LOG_INFO, "setting hostname to `%s'", newhostname);
+ logger (LOG_INFO, "setting hostname to `%s'",
+ newhostname);
sethostname (newhostname, strlen (newhostname));
}
+
+ free (newhostname);
}
-
+
free (curhostname);
- free (newhostname);
#ifdef ENABLE_INFO
if (! dhcp->frominfo)
#endif
if (iface->previous_address.s_addr != dhcp->address.s_addr ||
- iface->previous_netmask.s_addr != dhcp->netmask.s_addr)
+ iface->previous_netmask.s_addr != dhcp->netmask.s_addr)
{
memcpy (&iface->previous_address,
- &dhcp->address, sizeof (struct in_addr));
+ &dhcp->address, sizeof (struct in_addr));
memcpy (&iface->previous_netmask,
- &dhcp->netmask, sizeof (struct in_addr));
+ &dhcp->netmask, sizeof (struct in_addr));
exec_script (options->script, iface->infofile, "new");
} else
exec_script (options->script, iface->infofile, "up");
errno = 0;
n = strtol (s, &t, 0);
if ((errno != 0 && n == 0) || s == t ||
- (errno == ERANGE && (n == LONG_MAX || n == LONG_MIN)))
+ (errno == ERANGE && (n == LONG_MAX || n == LONG_MIN)))
{
logger (LOG_ERR, "`%s' out of range", s);
exit (EXIT_FAILURE);
static void usage (void)
{
printf ("usage: "PACKAGE" [-adknpEGHMNRSTY] [-c script] [-h hostname] [-i classID]\n"
- " [-l leasetime] [-m metric] [-r ipaddress] [-s ipaddress]\n"
- " [-t timeout] [-u userclass] [-F none | ptr | both]\n"
- " [-I clientID] <interface>\n");
+ " [-l leasetime] [-m metric] [-r ipaddress] [-s ipaddress]\n"
+ " [-t timeout] [-u userclass] [-F none | ptr | both]\n"
+ " [-I clientID] <interface>\n");
}
int main(int argc, char **argv)
options = xmalloc (sizeof (options_t));
memset (options, 0, sizeof (options_t));
options->script = (char *) DEFAULT_SCRIPT;
- snprintf (options->classid, CLASS_ID_MAX_LEN, "%s %s", PACKAGE, VERSION);
+ snprintf (options->classid, CLASS_ID_MAX_LEN, "%s %s",
+ PACKAGE, VERSION);
options->classid_len = strlen (options->classid);
options->doarp = true;
gethostname (options->hostname, sizeof (options->hostname));
if (strcmp (options->hostname, "(none)") == 0 ||
- strcmp (options->hostname, "localhost") == 0)
+ strcmp (options->hostname, "localhost") == 0)
memset (options->hostname, 0, sizeof (options->hostname));
/* Don't set any optional arguments here so we retain POSIX
* compatibility with getopt */
while ((opt = getopt_long(argc, argv, EXTRA_OPTS
- "c:dh:i:kl:m:npr:s:t:u:xAEF:GHI:LMNRSTY",
- longopts, &option_index)) != -1)
+ "c:dh:i:kl:m:npr:s:t:u:xAEF:GHI:LMNRSTY",
+ longopts, &option_index)) != -1)
{
switch (opt) {
case 0:
if (longopts[option_index].flag)
break;
- logger (LOG_ERR, "option `%s' should set a flag",
- longopts[option_index].name);
+ logger (LOG_ERR,
+ "option `%s' should set a flag",
+ longopts[option_index].name);
exit (EXIT_FAILURE);
break;
case 'c':
#endif
case 'h':
if (! optarg)
- memset (options->hostname, 0, sizeof (options->hostname));
+ memset (options->hostname, 0,
+ sizeof (options->hostname));
else if (strlen (optarg) > MAXHOSTNAMELEN) {
- logger (LOG_ERR, "`%s' too long for HostName string, max is %d",
- optarg, MAXHOSTNAMELEN);
+ logger (LOG_ERR,
+ "`%s' too long for HostName string, max is %d",
+ optarg, MAXHOSTNAMELEN);
exit (EXIT_FAILURE);
} else
- strlcpy (options->hostname, optarg, sizeof (options->hostname));
+ strlcpy (options->hostname, optarg,
+ sizeof (options->hostname));
break;
case 'i':
if (! optarg) {
- memset (options->classid, 0, sizeof (options->classid));
+ memset (options->classid, 0,
+ sizeof (options->classid));
options->classid_len = 0;
} else if (strlen (optarg) > CLASS_ID_MAX_LEN) {
- logger (LOG_ERR, "`%s' too long for ClassID string, max is %d",
- optarg, CLASS_ID_MAX_LEN);
+ logger (LOG_ERR,
+ "`%s' too long for ClassID string, max is %d",
+ optarg, CLASS_ID_MAX_LEN);
exit (EXIT_FAILURE);
} else
options->classid_len = strlcpy (options->classid, optarg,
- sizeof (options->classid));
+ sizeof (options->classid));
break;
case 'k':
sig = SIGHUP;
case 'l':
options->leasetime = atoint (optarg);
if (options->leasetime <= 0) {
- logger (LOG_ERR, "leasetime must be a positive value");
+ logger (LOG_ERR,
+ "leasetime must be a positive value");
exit (EXIT_FAILURE);
}
break;
* address */
*slash++ = '\0';
if (sscanf (slash, "%d", &cidr) != 1 ||
- inet_cidrtoaddr (cidr, &options->request_netmask) != 0) {
+ inet_cidrtoaddr (cidr, &options->request_netmask) != 0) {
logger (LOG_ERR, "`%s' is not a valid CIDR", slash);
exit (EXIT_FAILURE);
}
if (! options->doinform)
options->dorequest = true;
if (strlen (optarg) > 0 &&
- ! inet_aton (optarg, &options->request_address))
+ ! inet_aton (optarg, &options->request_address))
{
logger (LOG_ERR, "`%s' is not a valid IP address", optarg);
exit (EXIT_FAILURE);
offset += (int) options->userclass[offset] + 1;
if (offset + 1 + strlen (optarg) > USERCLASS_MAX_LEN) {
logger (LOG_ERR, "userclass overrun, max is %d",
- USERCLASS_MAX_LEN);
+ USERCLASS_MAX_LEN);
exit (EXIT_FAILURE);
}
userclasses++;
break;
case 'A':
#ifndef ENABLE_ARP
- logger (LOG_ERR, "arp support not compiled into dhcpcd");
+ logger (LOG_ERR,
+ "arp not compiled into dhcpcd");
exit (EXIT_FAILURE);
#endif
options->doarp = false;
break;
case 'E':
#ifndef ENABLE_INFO
- logger (LOG_ERR, "info support not compiled into dhcpcd");
+ logger (LOG_ERR,
+ "info not compiled into dhcpcd");
exit (EXIT_FAILURE);
#endif
options->dolastlease = true;
if (optarg) {
if (strlen (optarg) > CLIENT_ID_MAX_LEN) {
logger (LOG_ERR, "`%s' is too long for ClientID, max is %d",
- optarg, CLIENT_ID_MAX_LEN);
+ optarg, CLIENT_ID_MAX_LEN);
exit (EXIT_FAILURE);
}
options->clientid_len = strlcpy (options->clientid, optarg,
- sizeof (options->clientid));
+ sizeof (options->clientid));
/* empty string disabled duid */
if (options->clientid_len == 0)
options->clientid_len = -1;
printf (""PACKAGE" "VERSION"\n");
printf ("Compile time options:"
#ifdef ENABLE_ARP
- " ARP"
+ " ARP"
#endif
#ifdef ENABLE_DUID
- " DUID"
+ " DUID"
#endif
#ifdef ENABLE_INFO
- " INFO"
+ " INFO"
#endif
#ifdef ENABLE_INFO_COMPAT
- " INFO_COMPAT"
+ " INFO_COMPAT"
#endif
#ifdef ENABLE_IPV4LL
- " IPV4LL"
+ " IPV4LL"
#endif
#ifdef ENABLE_NIS
- " NIS"
+ " NIS"
#endif
#ifdef ENABLE_NTP
- " NTP"
+ " NTP"
#endif
#ifdef SERVICE
- " " SERVICE
+ " " SERVICE
#endif
#ifdef ENABLE_RESOLVCONF
- " RESOLVCONF"
+ " RESOLVCONF"
#endif
#ifdef THERE_IS_NO_FORK
- " THERE_IS_NO_FORK"
+ " THERE_IS_NO_FORK"
#endif
- "\n");
+ "\n");
}
if (dohelp)
dhcpcd_argc = argc;
if (! realpath (argv[0], dhcpcd)) {
logger (LOG_ERR, "unable to resolve the path `%s': %s",
- argv[0], strerror (errno));
+ argv[0], strerror (errno));
goto abort;
}
#endif
if (optind < argc) {
if (strlen (argv[optind]) > IF_NAMESIZE) {
- logger (LOG_ERR, "`%s' is too long for an interface name (max=%d)",
- argv[optind], IF_NAMESIZE);
+ logger (LOG_ERR,
+ "`%s' too long for an interface name (max=%d)",
+ argv[optind], IF_NAMESIZE);
goto abort;
}
strlcpy (options->interface, argv[optind],
- sizeof (options->interface));
+ sizeof (options->interface));
} else {
/* If only version was requested then exit now */
if (doversion || dohelp) {
options->fqdn = FQDN_DISABLE;
if (options->request_address.s_addr == 0 && options->doinform) {
- if ((options->request_address.s_addr = get_address (options->interface)) != 0)
+ if ((options->request_address.s_addr =
+ get_address (options->interface)) != 0)
options->keep_address = true;
}
if (IN_LINKLOCAL (ntohl (options->request_address.s_addr))) {
- logger (LOG_ERR, "you are not allowed to request a link local address");
+ logger (LOG_ERR,
+ "you are not allowed to request a link local address");
goto abort;
}
if (geteuid ()) {
- logger (LOG_ERR, "you need to be root to run "PACKAGE);
+ logger (LOG_ERR, "you need to be root to run " PACKAGE);
goto abort;
}
snprintf (prefix, IF_NAMESIZE, "%s: ", options->interface);
setlogprefix (prefix);
snprintf (options->pidfile, sizeof (options->pidfile), PIDFILE,
- options->interface);
+ options->interface);
free (prefix);
chdir ("/");
umask (022);
-
+
if (mkdir (INFODIR, S_IRUSR | S_IWUSR |S_IXUSR | S_IRGRP | S_IXGRP
- | S_IROTH | S_IXOTH) && errno != EEXIST)
+ | S_IROTH | S_IXOTH) && errno != EEXIST)
{
- logger (LOG_ERR, "mkdir(\"%s\",0): %s\n", INFODIR, strerror (errno));
+ logger (LOG_ERR,
+ "mkdir(\"%s\",0): %s\n", INFODIR, strerror (errno));
goto abort;
}
if (mkdir (ETCDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP
- | S_IROTH | S_IXOTH) && errno != EEXIST)
+ | S_IROTH | S_IXOTH) && errno != EEXIST)
{
- logger (LOG_ERR, "mkdir(\"%s\",0): %s\n", ETCDIR, strerror (errno));
+ logger (LOG_ERR,
+ "mkdir(\"%s\",0): %s\n", ETCDIR, strerror (errno));
goto abort;
}
if (options->test) {
if (options->dorequest || options->doinform) {
- logger (LOG_ERR, "cannot test with --inform or --request");
+ logger (LOG_ERR,
+ "cannot test with --inform or --request");
goto abort;
}
}
if (sig != 0) {
- logger (LOG_ERR, "cannot test with --release or --renew");
+ logger (LOG_ERR,
+ "cannot test with --release or --renew");
goto abort;
}
}
int killed = -1;
pid = read_pid (options->pidfile);
if (pid != 0)
- logger (LOG_INFO, "sending signal %d to pid %d", sig, pid);
+ logger (LOG_INFO, "sending signal %d to pid %d",
+ sig, pid);
if (! pid || (killed = kill (pid, sig)))
- logger (sig == SIGALRM ? LOG_INFO : LOG_ERR, ""PACKAGE" not running");
+ logger (sig == SIGALRM ? LOG_INFO : LOG_ERR,
+ ""PACKAGE" not running");
if (pid != 0 && (sig != SIGALRM || killed != 0))
unlink (options->pidfile);
}
if (! options->test && ! options->daemonised) {
- if ((pid = read_pid (options->pidfile)) > 0 && kill (pid, 0) == 0) {
- logger (LOG_ERR, ""PACKAGE" already running on pid %d (%s)",
- pid, options->pidfile);
+ if ((pid = read_pid (options->pidfile)) > 0 &&
+ kill (pid, 0) == 0)
+ {
+ logger (LOG_ERR, ""PACKAGE
+ " already running on pid %d (%s)",
+ pid, options->pidfile);
goto abort;
}
- pidfd = open (options->pidfile, O_WRONLY | O_CREAT | O_NONBLOCK, 0660);
+ pidfd = open (options->pidfile,
+ O_WRONLY | O_CREAT | O_NONBLOCK, 0660);
if (pidfd == -1) {
- logger (LOG_ERR, "open `%s': %s", options->pidfile, strerror (errno));
+ logger (LOG_ERR, "open `%s': %s",
+ options->pidfile, strerror (errno));
goto abort;
}
- /* Lock the file so that only one instance of dhcpcd runs on an interface */
+ /* Lock the file so that only one instance of dhcpcd runs
+ * on an interface */
if (flock (pidfd, LOCK_EX | LOCK_NB) == -1) {
- logger (LOG_ERR, "flock `%s': %s", options->pidfile, strerror (errno));
+ logger (LOG_ERR, "flock `%s': %s",
+ options->pidfile, strerror (errno));
goto abort;
}
/* dhcpcd.sh should not interhit this fd */
if ((i = fcntl (pidfd, F_GETFD, 0)) == -1 ||
- fcntl (pidfd, F_SETFD, i | FD_CLOEXEC) == -1)
+ fcntl (pidfd, F_SETFD, i | FD_CLOEXEC) == -1)
logger (LOG_ERR, "fcntl: %s", strerror (errno));
writepid (pidfd, getpid ());
#endif
logger (LOG_INFO, "exiting");
-
+
exit (retval);
}
/* Finally, add the MAC address of the interface */
memcpy (p, iface->hwaddr, iface->hwlen);
p += iface->hwlen;
-
+
iface->duid_length = p - iface->duid;
if (! (fp = fopen (DUIDFILE, "w")))
return (new);
}
-static void print_clean (FILE *f, const char *name, const char *value) {
+
+static void print_addresses (FILE *f, const address_t *addresses)
+{
+ const address_t *addr;
+
+ for (addr = addresses; addr; addr = addr->next) {
+ fprintf (f, "%s", inet_ntoa (addr->address));
+ if (addr->next)
+ fprintf (f, " ");
+ }
+}
+
+static void print_clean (FILE *f, const char *name, const char *value)
+{
char *clean;
if (! value)
}
bool write_info(const interface_t *iface, const dhcp_t *dhcp,
- const options_t *options, bool overwrite)
+ const options_t *options, bool overwrite)
{
FILE *f;
route_t *route;
- address_t *address;
struct stat sb;
if (options->test)
logger (LOG_DEBUG, "writing %s", iface->infofile);
if ((f = fopen (iface->infofile, "w")) == NULL) {
- logger (LOG_ERR, "fopen `%s': %s", iface->infofile, strerror (errno));
+ logger (LOG_ERR, "fopen `%s': %s",
+ iface->infofile, strerror (errno));
return (false);
}
}
if (dhcp->dnsservers) {
fprintf (f, "DNSSERVERS='");
- for (address = dhcp->dnsservers; address; address = address->next) {
- fprintf (f, "%s", inet_ntoa (address->address));
- if (address->next)
- fprintf (f, " ");
- }
+ print_addresses (f, dhcp->dnsservers);
fprintf (f, "'\n");
}
if (dhcp->ntpservers) {
fprintf (f, "NTPSERVERS='");
- for (address = dhcp->ntpservers; address; address = address->next) {
- fprintf (f, "%s", inet_ntoa (address->address));
- if (address->next)
- fprintf (f, " ");
- }
+ print_addresses (f, dhcp->ntpservers);
fprintf (f, "'\n");
}
print_clean (f, "NISDOMAIN", dhcp->nisdomain);
if (dhcp->nisservers) {
fprintf (f, "NISSERVERS='");
- for (address = dhcp->nisservers; address; address = address->next) {
- fprintf (f, "%s", inet_ntoa (address->address));
- if (address->next)
- fprintf (f, " ");
- }
+ print_addresses (f, dhcp->nisservers);
fprintf (f, "'\n");
}
p = duid = xmalloc (iface->duid_length + 6);
*p++ = 255;
- /* IAID is 4 bytes, so if the interface name is 4 bytes then use it */
+ /* IAID is 4 bytes, so if the interface name is 4 bytes
+ * then use it */
if (strlen (iface->name) == 4) {
memcpy (p, iface->name, 4);
} else {
#endif
else
fprintf (f, "CLIENTID='%.2X:%s'\n", iface->family,
- hwaddr_ntoa (iface->hwaddr, iface->hwlen));
- fprintf (f, "DHCPCHADDR='%s'\n", hwaddr_ntoa (iface->hwaddr, iface->hwlen));
+ hwaddr_ntoa (iface->hwaddr, iface->hwlen));
+ fprintf (f, "DHCPCHADDR='%s'\n", hwaddr_ntoa (iface->hwaddr,
+ iface->hwlen));
#ifdef ENABLE_INFO_COMPAT
/* Support the old .info settings if we need to */
fprintf (f, "\n# dhcpcd-1.x and 2.x compatible variables\n");
if (dhcp->dnsservers) {
+ address_t *addr;
+
fprintf (f, "DNS='");
- for (address = dhcp->dnsservers; address; address = address->next) {
- fprintf (f, "%s", inet_ntoa (address->address));
- if (address->next)
+ for (addr = dhcp->dnsservers; addr; addr = addr->next) {
+ fprintf (f, "%s", inet_ntoa (addr->address));
+ if (addr->next)
fprintf (f, ",");
}
fprintf (f, "'\n");
}
static bool parse_address (struct in_addr *addr,
- const char *value, const char *var)
+ const char *value, const char *var)
{
if (inet_aton (value, addr) == 0) {
logger (LOG_ERR, "%s `%s': %s", var, value,
- strerror (errno));
+ strerror (errno));
return (false);
}
return (true);
}
static bool parse_uint (unsigned int *i,
- const char *value, const char *var)
+ const char *value, const char *var)
{
if (sscanf (value, "%u", i) != 1) {
logger (LOG_ERR, "%s `%s': not a valid number",
- var, value);
+ var, value);
return (false);
}
return (true);
}
static bool parse_ushort (unsigned short *s,
- const char *value, const char *var)
+ const char *value, const char *var)
{
if (sscanf (value, "%hu", s) != 1) {
logger (LOG_ERR, "%s `%s': not a valid number",
- var, value);
+ var, value);
return (false);
}
return (true);
if (stat (iface->infofile, &sb) != 0) {
logger (LOG_ERR, "lease information file `%s' does not exist",
- iface->infofile);
+ iface->infofile);
return (false);
}
if (! (fp = fopen (iface->infofile, "r"))) {
- logger (LOG_ERR, "fopen `%s': %s", iface->infofile, strerror (errno));
+ logger (LOG_ERR, "fopen `%s': %s",
+ iface->infofile, strerror (errno));
return (false);
}
/* Skip comments */
if (*var == '#')
goto next;
-
+
/* If we don't have an equals sign then skip it */
if (! (p = strchr (var, '=')))
goto next;
if (! dest || ! net || ! gate) {
logger (LOG_ERR, "read_info ROUTES `%s,%s,%s': invalid route",
- dest, net, gate);
+ dest, net, gate);
goto next;
}
memset (route, 0, sizeof (route_t));
if (inet_aton (dest, &route->destination) == 0) {
logger (LOG_ERR, "read_info ROUTES `%s': not a valid destination address",
- dest);
+ dest);
free (route);
goto next;
}
if (inet_aton (dest, &route->netmask) == 0) {
logger (LOG_ERR, "read_info ROUTES `%s': not a valid netmask address",
- net);
+ net);
free (route);
goto next;
}
if (inet_aton (dest, &route->gateway) == 0) {
logger (LOG_ERR, "read_info ROUTES `%s': not a valid gateway address",
- gate);
+ gate);
free (route);
goto next;
}
if (ocets > 0) {
memset (&addr->s_addr, 255, ocets - 1);
memset ((unsigned char *) &addr->s_addr + (ocets - 1),
- (256 - (1 << (32 - cidr) % 8)), 1);
+ (256 - (1 << (32 - cidr) % 8)), 1);
}
return (0);
*p ++= ':';
p += snprintf (p, 3, "%.2x", hwaddr[i]);
}
-
+
*p ++= '\0';
return (buffer);
}
static int _do_interface (const char *ifname,
- unsigned char *hwaddr, int *hwlen,
- struct in_addr *addr,
- bool flush, bool get)
+ unsigned char *hwaddr, int *hwlen,
+ struct in_addr *addr,
+ bool flush, bool get)
{
int s;
struct ifconf ifc;
ifc.ifc_buf = xmalloc (len);
if (ioctl (s, SIOCGIFCONF, &ifc) == -1) {
if (errno != EINVAL || lastlen != 0) {
- logger (LOG_ERR, "ioctl SIOCGIFCONF: %s", strerror (errno));
+ logger (LOG_ERR, "ioctl SIOCGIFCONF: %s",
+ strerror (errno));
close (s);
free (ifc.ifc_buf);
return -1;
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 (struct sockaddr_dl));
*hwlen = sdl.sdl_alen;
- memcpy (hwaddr, sdl.sdl_data + sdl.sdl_nlen, sdl.sdl_alen);
+ memcpy (hwaddr, sdl.sdl_data + sdl.sdl_nlen,
+ sdl.sdl_alen);
retval = 1;
break;
}
#endif
if (ifr->ifr_addr.sa_family == AF_INET) {
- memcpy (&address, &ifr->ifr_addr, sizeof (struct sockaddr_in));
+ memcpy (&address, &ifr->ifr_addr,
+ sizeof (struct sockaddr_in));
if (flush) {
struct sockaddr_in netmask;
if (ioctl (s, SIOCGIFNETMASK, ifr) == -1) {
- logger (LOG_ERR, "ioctl SIOCGIFNETMASK: %s",
- strerror (errno));
+ logger (LOG_ERR,
+ "ioctl SIOCGIFNETMASK: %s",
+ strerror (errno));
continue;
}
- memcpy (&netmask, &ifr->ifr_addr, sizeof (struct sockaddr_in));
+ memcpy (&netmask, &ifr->ifr_addr,
+ sizeof (struct sockaddr_in));
if (del_address (ifname,
- address.sin_addr, netmask.sin_addr) == -1)
+ address.sin_addr,
+ netmask.sin_addr) == -1)
retval = -1;
} else if (get) {
addr->s_addr = address.sin_addr.s_addr;
hwlen = INFINIBAND_ADDR_LEN;
break;
default:
- logger (LOG_ERR, "interface is not Ethernet, FireWire, InfiniBand or Token Ring");
+ logger (LOG_ERR,
+ "interface is not Ethernet, FireWire, " \
+ "InfiniBand or Token Ring");
goto exit;
}
}
if (ifr.ifr_mtu < MTU_MIN) {
- logger (LOG_DEBUG, "MTU of %d is too low, setting to %d", ifr.ifr_mtu, MTU_MIN);
+ logger (LOG_DEBUG, "MTU of %d is too low, setting to %d",
+ ifr.ifr_mtu, MTU_MIN);
ifr.ifr_mtu = MTU_MIN;
strlcpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ioctl (s, SIOCSIFMTU, &ifr) == -1) {
- logger (LOG_ERR, "ioctl SIOCSIFMTU,: %s", strerror (errno));
+ logger (LOG_ERR, "ioctl SIOCSIFMTU,: %s",
+ strerror (errno));
goto exit;
}
}
if (! (ifr.ifr_flags & IFF_UP) || ! (ifr.ifr_flags & IFF_RUNNING)) {
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (ioctl (s, SIOCSIFFLAGS, &ifr) == -1) {
- logger (LOG_ERR, "ioctl SIOCSIFFLAGS: %s", strerror (errno));
+ logger (LOG_ERR, "ioctl SIOCSIFFLAGS: %s",
+ strerror (errno));
goto exit;
}
}
iface->mtu = iface->previous_mtu = mtu;
logger (LOG_INFO, "hardware address = %s",
- hwaddr_ntoa (iface->hwaddr, iface->hwlen));
+ hwaddr_ntoa (iface->hwaddr, iface->hwlen));
/* 0 is a valid fd, so init to -1 */
iface->fd = -1;
return (r == 0 ? 0 : -1);
}
-static void log_route(
- struct in_addr destination,
- struct in_addr netmask,
- struct in_addr gateway,
- int metric,
- int change, int del)
+static void log_route (struct in_addr destination,
+ struct in_addr netmask,
+ struct in_addr gateway,
+ int metric,
+ int change, int del)
{
char *dstd = xstrdup (inet_ntoa (destination));
#endif
if (gateway.s_addr == destination.s_addr ||
- gateway.s_addr == INADDR_ANY)
+ gateway.s_addr == INADDR_ANY)
logger (LOG_INFO, "%s route to %s/%d" METRIC,
- change ? "changing" : del ? "removing" : "adding",
- dstd, inet_ntocidr (netmask)
+ change ? "changing" : del ? "removing" : "adding",
+ dstd, inet_ntocidr (netmask)
#ifdef __linux__
- , metric
+ , metric
#endif
- );
+ );
else if (destination.s_addr == INADDR_ANY)
logger (LOG_INFO, "%s default route via %s" METRIC,
- change ? "changing" : del ? "removing" : "adding",
- inet_ntoa (gateway)
+ change ? "changing" : del ? "removing" : "adding",
+ inet_ntoa (gateway)
#ifdef __linux__
- , metric
+ , metric
#endif
- );
+ );
else
logger (LOG_INFO, "%s route to %s/%d via %s" METRIC,
- change ? "changing" : del ? "removing" : "adding",
- dstd, inet_ntocidr (netmask), inet_ntoa (gateway)
+ change ? "changing" : del ? "removing" : "adding",
+ dstd, inet_ntocidr (netmask), inet_ntoa (gateway)
#ifdef __linux__
- , metric
+ , metric
#endif
- );
+ );
free (dstd);
}
/* Darwin doesn't define this for some very odd reason */
#ifndef SA_SIZE
# define SA_SIZE(sa) \
- ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
- sizeof(long) : \
- 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
+ ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
+ sizeof(long) : \
+ 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
#endif
static int do_address (const char *ifname, struct in_addr address,
- struct in_addr netmask, struct in_addr broadcast, int del)
+ struct in_addr netmask, struct in_addr broadcast,
+ int del)
{
int s;
struct ifaliasreq ifa;
strlcpy (ifa.ifra_name, ifname, sizeof (ifa.ifra_name));
#define ADDADDR(_var, _addr) { \
- 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)); \
- }
+ 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)); \
+}
ADDADDR (ifa.ifra_addr, address);
ADDADDR (ifa.ifra_mask, netmask);
- if (! del)
- ADDADDR (ifa.ifra_broadaddr, broadcast);
+if (! del)
+ ADDADDR (ifa.ifra_broadaddr, broadcast);
#undef ADDADDR
if (ioctl (s, del ? SIOCDIFADDR : SIOCAIFADDR, &ifa) == -1) {
- logger (LOG_ERR, "ioctl %s: %s", del ? "SIOCDIFADDR" : "SIOCAIFADDR",
- strerror (errno));
+ logger (LOG_ERR, "ioctl %s: %s",
+ del ? "SIOCDIFADDR" : "SIOCAIFADDR",
+ strerror (errno));
close (s);
return -1;
}
- close (s);
- return 0;
+close (s);
+return 0;
}
static int do_route (const char *ifname,
- struct in_addr destination,
- struct in_addr netmask,
- struct in_addr gateway,
- int metric,
- int change, int del)
+ struct in_addr destination,
+ struct in_addr netmask,
+ struct in_addr gateway,
+ int metric,
+ int change, int del)
{
int s;
struct rtm
struct sockaddr_dl sdl;
struct sockaddr_storage ss;
} su;
-
+
int l;
if (! ifname)
ADDADDR (destination);
if (netmask.s_addr == INADDR_BROADCAST ||
- gateway.s_addr == INADDR_ANY)
+ gateway.s_addr == INADDR_ANY)
{
/* Make us a link layer socket */
unsigned char *hwaddr;
memcpy (&su.sdl.sdl_data, ifname, su.sdl.sdl_nlen);
su.sdl.sdl_alen = hwlen;
memcpy (((unsigned char *) &su.sdl.sdl_data) + su.sdl.sdl_nlen,
- hwaddr, su.sdl.sdl_alen);
+ hwaddr, su.sdl.sdl_alen);
l = SA_SIZE (&(su.sa));
memcpy (bp, &su, l);
if (bytes == -1) {
if (errno != EINTR)
- logger (LOG_ERR, "recvmsg: %s", strerror (errno));
+ logger (LOG_ERR, "recvmsg: %s",
+ strerror (errno));
continue;
}
}
if (msg.msg_namelen != sizeof (nl)) {
- logger (LOG_ERR, "netlink: sender address length mismatch");
+ logger (LOG_ERR,
+ "netlink: sender address length mismatch");
goto eexit;
}
/* Ensure it's our message */
if (nl.nl_pid != 0 ||
- (pid_t) h.nlm->nlmsg_pid != mypid ||
- h.nlm->nlmsg_seq != seq)
+ (pid_t) h.nlm->nlmsg_pid != mypid ||
+ h.nlm->nlmsg_seq != seq)
{
/* Next Message */
bytes -= NLMSG_ALIGN (len);
h.buffer += NLMSG_ALIGN (len);
continue;
}
-
+
/* We get an NLMSG_ERROR back with a code of zero for success */
if (h.nlm->nlmsg_type != NLMSG_ERROR) {
- logger (LOG_ERR, "netlink: unexpected reply %d", h.nlm->nlmsg_type);
+ logger (LOG_ERR, "netlink: unexpected reply %d",
+ h.nlm->nlmsg_type);
goto eexit;
}
errno = -err->error;
/* Don't report on something already existing */
if (errno != EEXIST)
- logger (LOG_ERR, "netlink: %s", strerror (errno));
+ logger (LOG_ERR, "netlink: %s",
+ strerror (errno));
goto eexit;
}
}
((struct rtattr *) (((ptrdiff_t) (nmsg)) + NLMSG_ALIGN ((nmsg)->nlmsg_len)))
static int add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type,
- const void *data, int alen)
+ const void *data, int alen)
{
int len = RTA_LENGTH(alen);
struct rtattr *rta;
if (NLMSG_ALIGN (n->nlmsg_len) + RTA_ALIGN (len) > maxlen) {
- logger (LOG_ERR, "add_attr_l: message exceeded bound of %d\n", maxlen);
+ logger (LOG_ERR, "add_attr_l: message exceeded bound of %d\n",
+ maxlen);
return -1;
}
}
static int add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type,
- uint32_t data)
+ uint32_t data)
{
int len = RTA_LENGTH (sizeof (uint32_t));
struct rtattr *rta;
if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen) {
- logger (LOG_ERR, "add_attr32: message exceeded bound of %d\n", maxlen);
+ logger (LOG_ERR, "add_attr32: message exceeded bound of %d\n",
+ maxlen);
return -1;
}
};
static int do_address(const char *ifname,
- struct in_addr address, struct in_addr netmask,
- struct in_addr broadcast, int del)
+ struct in_addr address, struct in_addr netmask,
+ struct in_addr broadcast, int del)
{
struct nlma *nlm;
int retval;
nlm->hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE;
nlm->hdr.nlmsg_type = del ? RTM_DELADDR : RTM_NEWADDR;
if (! (nlm->ifa.ifa_index = if_nametoindex (ifname))) {
- logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
- ifname);
+ logger (LOG_ERR, "if_nametoindex: no index for interface `%s'",
+ ifname);
free (nlm);
return -1;
}
/* This creates the aliased interface */
add_attr_l (&nlm->hdr, sizeof (struct nlma), IFA_LABEL,
- ifname, strlen (ifname) + 1);
+ ifname, strlen (ifname) + 1);
add_attr_l (&nlm->hdr, sizeof (struct nlma), IFA_LOCAL,
- &address.s_addr, sizeof (address.s_addr));
+ &address.s_addr, sizeof (address.s_addr));
if (! del)
add_attr_l (&nlm->hdr, sizeof (struct nlma), IFA_BROADCAST,
- &broadcast.s_addr, sizeof (broadcast.s_addr));
+ &broadcast.s_addr, sizeof (broadcast.s_addr));
retval = send_netlink (&nlm->hdr);
free (nlm);
}
static int do_route (const char *ifname,
- struct in_addr destination,
- struct in_addr netmask,
- struct in_addr gateway,
- int metric, int change, int del)
+ struct in_addr destination,
+ struct in_addr netmask,
+ struct in_addr gateway,
+ int metric, int change, int del)
{
struct nlmr *nlm;
unsigned int ifindex;
log_route (destination, netmask, gateway, metric, change, del);
if (! (ifindex = if_nametoindex (ifname))) {
- logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
- ifname);
+ logger (LOG_ERR, "if_nametoindex: no index for interface `%s'",
+ ifname);
return -1;
}
nlm->hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
nlm->rt.rtm_protocol = RTPROT_BOOT;
if (netmask.s_addr == INADDR_BROADCAST ||
- gateway.s_addr == INADDR_ANY)
+ gateway.s_addr == INADDR_ANY)
nlm->rt.rtm_scope = RT_SCOPE_LINK;
else
nlm->rt.rtm_scope = RT_SCOPE_UNIVERSE;
nlm->rt.rtm_dst_len = inet_ntocidr (netmask);
add_attr_l (&nlm->hdr, sizeof (struct nlmr), RTA_DST,
- &destination.s_addr, sizeof (destination.s_addr));
+ &destination.s_addr, sizeof (destination.s_addr));
if (netmask.s_addr != INADDR_BROADCAST &&
- destination.s_addr != gateway.s_addr)
+ destination.s_addr != gateway.s_addr)
add_attr_l (&nlm->hdr, sizeof (struct nlmr), RTA_GATEWAY,
- &gateway.s_addr, sizeof (gateway.s_addr));
+ &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);
}
#else
-#error "Platform not supported!"
-#error "We currently support BPF and Linux sockets."
-#error "Other platforms may work using BPF. If yours does, please let me know"
-#error "so I can add it to our list."
+# error "Platform not supported!"
+# error "We currently support BPF and Linux sockets."
+# error "Other platforms may work using BPF. If yours does, please let me know"
+# error "so I can add it to our list."
#endif
-
int add_address (const char *ifname, struct in_addr address,
- struct in_addr netmask, struct in_addr broadcast)
+ struct in_addr netmask, struct in_addr broadcast)
{
logger (LOG_INFO, "adding IP address %s/%d",
- inet_ntoa (address), inet_ntocidr (netmask));
+ inet_ntoa (address), inet_ntocidr (netmask));
return (do_address (ifname, address, netmask, broadcast, 0));
}
int del_address (const char *ifname,
- struct in_addr address, struct in_addr netmask)
+ struct in_addr address, struct in_addr netmask)
{
struct in_addr t;
logger (LOG_INFO, "removing IP address %s/%d",
- inet_ntoa (address), inet_ntocidr (netmask));
+ inet_ntoa (address), inet_ntocidr (netmask));
memset (&t, 0, sizeof (t));
return (do_address (ifname, address, netmask, t, 1));
}
int add_route (const char *ifname, struct in_addr destination,
- struct in_addr netmask, struct in_addr gateway, int metric)
+ struct in_addr netmask, struct in_addr gateway, int metric)
{
return (do_route (ifname, destination, netmask, gateway, metric, 0, 0));
}
int change_route (const char *ifname, struct in_addr destination,
- struct in_addr netmask, struct in_addr gateway, int metric)
+ struct in_addr netmask, struct in_addr gateway, int metric)
{
return (do_route (ifname, destination, netmask, gateway, metric, 1, 0));
}
int del_route (const char *ifname, struct in_addr destination,
- struct in_addr netmask, struct in_addr gateway, int metric)
+ struct in_addr netmask, struct in_addr gateway, int metric)
{
return (do_route (ifname, destination, netmask, gateway, metric, 0, 1));
}
while (1) {
addr.s_addr = htonl (LINKLOCAL_ADDR |
- ((abs (random ()) % 0xFD00) + 0x0100));
+ ((abs (random ()) % 0xFD00) + 0x0100));
errno = 0;
if (! arp_claim (iface, addr))
break;
unsigned int i = 0;
/* Silently ignore this signal and wait for it. This stops zombies.
- We do this here instead of client.c so that we don't spam the log file
- with "waiting on select messages" */
+ We do this here instead of client.c so that we don't spam the log
+ file with "waiting on select messages" */
if (sig == SIGCHLD) {
wait (0);
return;
FD_SET (signal_pipe[0], rset);
if (fd >= 0)
FD_SET (fd, rset);
- return signal_pipe[0] > fd ? signal_pipe[0] : fd;
+ return (signal_pipe[0] > fd ? signal_pipe[0] : fd);
}
/* Check if we have a signal or not */
int signal_exists (const fd_set *rset)
{
if (signals[0] || (rset && FD_ISSET (signal_pipe[0], rset)))
- return 0;
- return -1;
+ return (0);
+ return (-1);
}
/* Read a signal from the signal pipe. Returns 0 if there is
FD_CLR (signal_pipe[0], rset);
}
- return sig;
+ return (sig);
}
/* Call this before doing anything else. Sets up the socket pair
/* Stop any scripts from inheriting us */
for (i = 0; i < 2; i++)
if ((flags = fcntl (signal_pipe[i], F_GETFD, 0)) == -1 ||
- fcntl (signal_pipe[i], F_SETFD, flags | FD_CLOEXEC) == -1)
+ fcntl (signal_pipe[i], F_SETFD, flags | FD_CLOEXEC) == -1)
logger (LOG_ERR ,"fcntl: %s", strerror (errno));
signal (SIGHUP, signal_handler);
}
void make_dhcp_packet(struct udp_dhcp_packet *packet,
- const unsigned char *data, int length,
- struct in_addr source, struct in_addr dest)
+ const unsigned char *data, int length,
+ struct in_addr source, struct in_addr dest)
{
struct ip *ip = &packet->ip;
struct udphdr *udp = &packet->udp;
udp->uh_ulen = htons (sizeof (struct udphdr) + length);
ip->ip_len = udp->uh_ulen;
udp->uh_sum = checksum ((unsigned char *) packet,
- sizeof (struct udp_dhcp_packet));
+ sizeof (struct udp_dhcp_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);
+ length);
ip->ip_id = 0;
ip->ip_off = 0;
ip->ip_ttl = IPDEFTTL;
d.data = data;
d.packet->ip.ip_sum = 0;
if (ipsum != checksum ((unsigned char *) &d.packet->ip,
- sizeof (struct ip)))
+ sizeof (struct ip)))
{
logger (LOG_DEBUG, "bad IP header checksum, ignoring");
retval = -1;
}
if ((flags = fcntl (fd, F_GETFD, 0)) == -1
- || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
{
logger (LOG_ERR, "fcntl: %s", strerror (errno));
close (fd);
memset (&ifr, 0, sizeof (struct ifreq));
strlcpy (ifr.ifr_name, iface->name, sizeof (ifr.ifr_name));
if (ioctl (fd, BIOCSETIF, &ifr) == -1) {
- logger (LOG_ERR, "cannot attach interface `%s' to bpf device `%s': %s",
- iface->name, device, strerror (errno));
+ logger (LOG_ERR,
+ "cannot attach interface `%s' to bpf device `%s': %s",
+ iface->name, device, strerror (errno));
close (fd);
return -1;
}
}
int send_packet (const interface_t *iface, int type,
- const unsigned char *data, int len)
+ const unsigned char *data, int len)
{
int retval = -1;
struct iovec iov[2];
/* BPF requires that we read the entire buffer.
So we pass the buffer in the API so we can loop on >1 dhcp packet. */
int get_packet (const interface_t *iface, unsigned char *data,
- unsigned char *buffer, int *buffer_len, int *buffer_pos)
+ unsigned char *buffer, int *buffer_len, int *buffer_pos)
{
union
{
/* Ensure that the entire packet is in our buffer */
if (*buffer_pos + bpf.packet->bh_hdrlen + bpf.packet->bh_caplen
- > (unsigned) *buffer_len)
+ > (unsigned) *buffer_len)
break;
hdr.buffer = bpf.buffer + bpf.packet->bh_hdrlen;
/* 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);
+ len = bpf.packet->bh_caplen -
+ sizeof (struct ether_header);
memcpy (data, payload, len);
} else {
if (valid_dhcp_packet (payload) >= 0) {
struct udp_dhcp_packet *packet;
} pay;
pay.buffer = payload;
- len = ntohs (pay.packet->ip.ip_len) - sizeof (struct ip) -
+ len = ntohs (pay.packet->ip.ip_len) -
+ sizeof (struct ip) -
sizeof (struct udphdr);
memcpy (data, &pay.packet->dhcp, len);
}
}
/* Update the buffer_pos pointer */
- bpf.buffer +=
- BPF_WORDALIGN (bpf.packet->bh_hdrlen + bpf.packet->bh_caplen);
+ bpf.buffer += BPF_WORDALIGN (bpf.packet->bh_hdrlen +
+ bpf.packet->bh_caplen);
if (bpf.buffer - buffer < *buffer_len)
*buffer_pos = bpf.buffer - buffer;
else
}
if ((flags = fcntl (fd, F_GETFD, 0)) == -1
- || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
{
logger (LOG_ERR, "fcntl: %s", strerror (errno));
close (fd);
else
su.sll.sll_protocol = htons (ETH_P_IP);
if (! (su.sll.sll_ifindex = if_nametoindex (iface->name))) {
- logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
- iface->name);
+ logger (LOG_ERR,
+ "if_nametoindex: no index for interface `%s'",
+ iface->name);
close (fd);
return -1;
}
}
int send_packet (const interface_t *iface, const int type,
- const unsigned char *data, const int len)
+ const unsigned char *data, const int len)
{
union sockunion {
struct sockaddr sa;
su.sll.sll_family = AF_PACKET;
su.sll.sll_protocol = htons (type);
if (! (su.sll.sll_ifindex = if_nametoindex (iface->name))) {
- logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
- iface->name);
+ logger (LOG_ERR, "if_nametoindex: no index for interface `%s'",
+ iface->name);
return -1;
}
su.sll.sll_halen = iface->hwlen;
memset(&su.sll.sll_addr, 0xff, iface->hwlen);
if ((retval = sendto (iface->fd, data, len, 0, &su.sa,
- sizeof (struct sockaddr_storage))) == -1)
+ sizeof (struct sockaddr_storage))) == -1)
logger (LOG_ERR, "sendto: %s", strerror (errno));
return retval;
/* Linux has no need for the buffer as we can read as much as we want.
We only have the buffer listed to keep the same API. */
int get_packet (const interface_t *iface, unsigned char *data,
- unsigned char *buffer, int *buffer_len, int *buffer_pos)
+ unsigned char *buffer, int *buffer_len, int *buffer_pos)
{
long bytes;
union
bytes = ntohs (pay.packet->ip.ip_len);
/* This is like our BPF filter above */
- if (pay.packet->ip.ip_p != IPPROTO_UDP || pay.packet->ip.ip_v != IPVERSION ||
- pay.packet->ip.ip_hl != sizeof (pay.packet->ip) >> 2 ||
- pay.packet->udp.uh_dport != htons (DHCP_CLIENT_PORT) ||
- bytes > (int) sizeof (struct udp_dhcp_packet) ||
- ntohs (pay.packet->udp.uh_ulen)
- != (uint16_t) (bytes - sizeof (pay.packet->ip)))
+ if (pay.packet->ip.ip_p != IPPROTO_UDP ||
+ pay.packet->ip.ip_v != IPVERSION ||
+ pay.packet->ip.ip_hl != sizeof (pay.packet->ip) >> 2 ||
+ pay.packet->udp.uh_dport != htons (DHCP_CLIENT_PORT) ||
+ bytes > (int) sizeof (struct udp_dhcp_packet) ||
+ ntohs (pay.packet->udp.uh_ulen)
+ != (uint16_t) (bytes - sizeof (pay.packet->ip)))
{
return -1;
}
return -1;
memcpy(data, &pay.packet->dhcp,
- bytes - (sizeof (pay.packet->ip) + sizeof (pay.packet->udp)));
+ bytes - (sizeof (pay.packet->ip) + sizeof (pay.packet->udp)));
return bytes - (sizeof (pay.packet->ip) + sizeof (pay.packet->udp));
}
#include "interface.h"
void make_dhcp_packet(struct udp_dhcp_packet *packet,
- const unsigned char *data, int length,
- struct in_addr source, struct in_addr dest);
+ const unsigned char *data, int length,
+ struct in_addr source, struct in_addr dest);
int open_socket (interface_t *iface, bool arp);
int send_packet (const interface_t *iface, int type,
- const unsigned char *data, int len);
+ const unsigned char *data, int len);
int get_packet (const interface_t *iface, unsigned char *data,
- unsigned char *buffer, int *buffer_len, int *buffer_pos);
+ unsigned char *buffer, int *buffer_len, int *buffer_pos);
#endif