summaryrefslogtreecommitdiffstats
path: root/src/kernel/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/utils.c')
-rw-r--r--src/kernel/utils.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/kernel/utils.c b/src/kernel/utils.c
index 902025f..c40120a 100644
--- a/src/kernel/utils.c
+++ b/src/kernel/utils.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* This file is part of the Distributed Network Block Device 3
*
@@ -26,16 +27,22 @@ unsigned int inet_addr(char *str)
{
int a, b, c, d;
char arr[4];
- sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d);
- arr[0] = a;
- arr[1] = b;
- arr[2] = c;
- arr[3] = d;
- return *(unsigned int *) arr;
+ int ret;
+
+ ret = sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d);
+ if (ret > 0) {
+ arr[0] = a;
+ arr[1] = b;
+ arr[2] = c;
+ arr[3] = d;
+ }
+
+ return *(unsigned int *)arr;
}
void inet_ntoa(struct in_addr addr, char *str)
{
- unsigned char *ptr = (unsigned char *) &addr;
+ unsigned char *ptr = (unsigned char *)&addr;
+
sprintf(str, "%d.%d.%d.%d", ptr[0] & 0xff, ptr[1] & 0xff, ptr[2] & 0xff, ptr[3] & 0xff);
}