aboutsummaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorAlexey Kardashevskiy <aik@ozlabs.ru>2016-01-22 11:46:39 +1100
committerAlexey Kardashevskiy <aik@ozlabs.ru>2016-01-29 17:11:38 +1100
commit896e31da2cc260bf5311a89b63683def20329c5b (patch)
tree4c06027fb49f8befbefe459cfe322926074bfb5c /clients
parentdc0ecd1477fcabd247b17c99c9558cae40daa04b (diff)
downloadSLOF-896e31da2cc260bf5311a89b63683def20329c5b.zip
SLOF-896e31da2cc260bf5311a89b63683def20329c5b.tar.gz
SLOF-896e31da2cc260bf5311a89b63683def20329c5b.tar.bz2
dhcp: Remove duplicated strtoip()
There is another implementation in netapps/args.c which is used by netboot.c and ping.c so switch to it. Suggested-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'clients')
-rw-r--r--clients/net-snk/app/netlib/dhcp.c50
1 files changed, 2 insertions, 48 deletions
diff --git a/clients/net-snk/app/netlib/dhcp.c b/clients/net-snk/app/netlib/dhcp.c
index 169da93..28aa488 100644
--- a/clients/net-snk/app/netlib/dhcp.c
+++ b/clients/net-snk/app/netlib/dhcp.c
@@ -48,6 +48,7 @@
#include <ipv4.h>
#include <udp.h>
#include <dns.h>
+#include <netapps/args.h>
#include <stdio.h>
#include <string.h>
@@ -157,9 +158,6 @@ static void dhcp_send_discover(int fd);
static void dhcp_send_request(int fd);
-static uint8_t strtoip(int8_t * str, uint32_t * ip);
-
-
/***************************** LOCAL VARIABLES ***************************/
static uint8_t ether_packet[ETH_MTU_SIZE];
@@ -214,7 +212,7 @@ int32_t dhcpv4(char *ret_buffer, filename_ip_t *fn_ip)
}
else {
// TFTP server defined by its name
- if (!strtoip(dhcp_tftp_name, &dhcp_tftp_ip)) {
+ if (!strtoip(dhcp_tftp_name, (uint8_t *)&dhcp_tftp_ip)) {
if (!dns_get_ip(fd, dhcp_tftp_name, (uint8_t *)&dhcp_tftp_ip, 4)) {
// DNS error - can't obtain TFTP-server name
// Use TFTP-ip from siaddr field, if presented
@@ -955,47 +953,3 @@ int8_t handle_dhcp(int fd, uint8_t * packet, int32_t packetsize)
return 0;
}
-
-/**
- * DHCP: Converts "255.255.255.255" -> 32-bit long IP
- *
- * @param str string to be converted
- * @param ip in case of SUCCESS - 32-bit long IP
- in case of FAULT - zero
- * @return TRUE - IP converted successfully;
- * FALSE - error condition occurs (e.g. bad format)
- */
-static uint8_t strtoip(int8_t * str, uint32_t * ip)
-{
- int8_t ** ptr = &str;
- int16_t i = 0, res, len;
- char octet[256];
-
- * ip = 0;
-
- while (**ptr != 0) {
- if (i > 3 || !isdigit(**ptr))
- return 0;
- if (strstr((char *) * ptr, ".") != NULL) {
- len = (int16_t) ((int8_t *) strstr((char *) * ptr, ".") -
- (int8_t *) (* ptr));
- strncpy(octet, (char *) * ptr, len); octet[len] = 0;
- * ptr += len;
- }
- else {
- strcpy(octet, (char *) * ptr);
- * ptr += strlen(octet);
- }
- res = strtol(octet, NULL, 10);
- if ((res > 255) || (res < 0))
- return 0;
- * ip = ((* ip) << 8) + res;
- i++;
- if (** ptr == '.')
- (*ptr)++;
- }
-
- if (i != 4)
- return 0;
- return 1;
-}