Netdev List
 help / color / mirror / Atom feed
* [PATCH ethtool] misc: header includes cleanup
@ 2022-12-08 13:13 Michal Kubecek
  2022-12-16 10:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Kubecek @ 2022-12-08 13:13 UTC (permalink / raw)
  To: netdev

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@suse.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-16 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 13:13 [PATCH ethtool] misc: header includes cleanup Michal Kubecek
2022-12-16 10:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox