[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221208131348.7B7166045E@lion.mk-sys.cz>
Date: Thu, 8 Dec 2022 14:13:48 +0100 (CET)
From: Michal Kubecek <mkubecek@...e.cz>
To: netdev@...r.kernel.org
Subject: [PATCH ethtool] misc: header includes cleanup
An attempt to build with -std=c99 or -std=c11 revealed few problems with
system header includes.
- strcasecmp() and strncasecmp() need <strings.h>
- ioctl() needs <linux/ioctl.h>
- struct ifreq needs <linux/if.h> (unless _USE_MISC is defined)
- fileno() needs _POSIX_C_SOURCE
- strdup() needs _POSIX_C_SOURCE >= _200809L
- inet_aton() would require _DEFAULT_SOURCE
Add missing includes and define _POSIX_C_SOURCE=200809L. Replace
inet_aton() with inet_pton(); the latter has slightly different
semantics (it does not support addresses like "1.2.3" or "1.2") but the
function is only called in code which is not actually used.
Signed-off-by: Michal Kubecek <mkubecek@...e.cz>
---
Makefile.am | 2 +-
ethtool.c | 4 +++-
internal.h | 2 +-
netlink/fec.c | 1 +
4 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index fcc912edd7e4..663f40a07b7d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-AM_CFLAGS = -Wall -Wextra
+AM_CFLAGS = -Wall -Wextra -D_POSIX_C_SOURCE=200809L
AM_CPPFLAGS = -I$(top_srcdir)/uapi
LDADD = -lm
diff --git a/ethtool.c b/ethtool.c
index 3207e49137c4..526be4cfb523 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -31,6 +31,7 @@
#include "internal.h"
#include <string.h>
+#include <strings.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
@@ -46,6 +47,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <linux/ioctl.h>
#include <linux/sockios.h>
#include <linux/netlink.h>
@@ -301,7 +303,7 @@ static void parse_generic_cmdline(struct cmd_context *ctx,
case CMDL_IP4: {
u32 *p = info[idx].wanted_val;
struct in_addr in;
- if (!inet_aton(argp[i], &in))
+ if (!inet_pton(AF_INET, argp[i], &in))
exit_bad_args();
*p = in.s_addr;
break;
diff --git a/internal.h b/internal.h
index dd7d6ac70ad4..b80f77afa4c0 100644
--- a/internal.h
+++ b/internal.h
@@ -21,7 +21,7 @@
#include <unistd.h>
#include <endian.h>
#include <sys/ioctl.h>
-#include <net/if.h>
+#include <linux/if.h>
#include "json_writer.h"
#include "json_print.h"
diff --git a/netlink/fec.c b/netlink/fec.c
index 695724eff896..6027dc05b992 100644
--- a/netlink/fec.c
+++ b/netlink/fec.c
@@ -9,6 +9,7 @@
#include <ctype.h>
#include <inttypes.h>
#include <string.h>
+#include <strings.h>
#include <stdio.h>
#include "../internal.h"
--
2.38.1
Powered by blists - more mailing lists