Netdev List
 help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: netdev@vger.kernel.org
Subject: [PATCH ethtool] misc: header includes cleanup
Date: Thu,  8 Dec 2022 14:13:48 +0100 (CET)	[thread overview]
Message-ID: <20221208131348.7B7166045E@lion.mk-sys.cz> (raw)

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


             reply	other threads:[~2022-12-08 13:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 13:13 Michal Kubecek [this message]
2022-12-16 10:00 ` [PATCH ethtool] misc: header includes cleanup patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221208131348.7B7166045E@lion.mk-sys.cz \
    --to=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox