diff mbox series

[ethtool] misc: header includes cleanup

Message ID 20221208131348.7B7166045E@lion.mk-sys.cz (mailing list archive)
State Accepted
Commit 1fa60003a8b8fa25d783867967860656f593822e
Delegated to: Michal Kubecek
Headers show
Series [ethtool] misc: header includes cleanup | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch, async

Commit Message

Michal Kubecek Dec. 8, 2022, 1:13 p.m. UTC
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(-)

Comments

patchwork-bot+netdevbpf@kernel.org Dec. 16, 2022, 10 a.m. UTC | #1
Hello:

This patch was applied to ethtool/ethtool.git (master)
by Michal Kubecek <mkubecek@suse.cz>:

On Thu,  8 Dec 2022 14:13:48 +0100 (CET) you wrote:
> 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
> 
> [...]

Here is the summary with links:
  - [ethtool] misc: header includes cleanup
    https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=1fa60003a8b8

You are awesome, thank you!
diff mbox series

Patch

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"