From: Strake <strake888@gmail.com>
To: musl@lists.openwall.com
Subject: Re: [patch] add ether_(aton, ntoa)
Date: Tue, 7 May 2013 22:29:07 -0500 [thread overview]
Message-ID: <CAL3m8eCzkmiawCYZ9xSfhzFbMBDb=QOc6AGYphHoQkVjxtLZzg@mail.gmail.com> (raw)
In-Reply-To: <20130505164030.GT20323@brightrain.aerifal.cx>
On 05/05/2013, Rich Felker <dalias@aerifal.cx> wrote:
> On Sun, May 05, 2013 at 06:24:19PM +0200, Szabolcs Nagy wrote:
>> but even if the representation and alignment is the same
>> an object with effective type (const char*) cannot be
>> accessed through a (char*) lvalue expression within strtoul
>>
>> so the aliasing rules are violated as well
>> (a compiler may reorder the loads from x and the stores
>> to *(char**)&x arbitarily)
>
> Indeed this is the real issue, but it's fairly hard to hit. If the
> compiler can only see the code in the caller and not inside strtoul,
> it can't do any reordering, because it must assume the callee could
> convert the pointer back to the right type and perform legal writes
> through it. The aliasing violation only has pratical consequences if
> you assume optimization can take place across translation units, e.g.
> LTO. In any case, it's policy not to do this kind of aliasing
> violation, especially when the identical result can easily be achieved
> using a temp variable of the right type.
All very esoteric. This is properly the compiler's worry, not mine.
Alas, lossage finds safety in standardization. But what would I know?
I'm not a committee.
From 3f301831e3e42ce23d5d3c0f3721232d66b93114 Mon Sep 17 00:00:00 2001
From: Strake <strake888@gmail.com>
Date: Sun, 14 Apr 2013 12:09:30 -0500
Subject: [PATCH] add ether_(aton, ntoa)
---
include/netinet/ether.h | 14 ++++++++++++++
src/network/ether_aton.c | 30 ++++++++++++++++++++++++++++++
src/network/ether_ntoa.c | 17 +++++++++++++++++
3 files changed, 61 insertions(+)
create mode 100644 include/netinet/ether.h
create mode 100644 src/network/ether_aton.c
create mode 100644 src/network/ether_ntoa.c
diff --git a/include/netinet/ether.h b/include/netinet/ether.h
new file mode 100644
index 0000000..c5179d5
--- /dev/null
+++ b/include/netinet/ether.h
@@ -0,0 +1,14 @@
+#ifndef _NETINET_ETHER_H
+#define _NETINET_ETHER_H
+
+#include <netinet/if_ether.h>
+
+char *ether_ntoa (const struct ether_addr *);
+
+struct ether_addr *ether_aton (const char *);
+
+char *ether_ntoa_r (const struct ether_addr *, char *);
+
+struct ether_addr *ether_aton_r (const char *, struct ether_addr *);
+
+#endif
diff --git a/src/network/ether_aton.c b/src/network/ether_aton.c
new file mode 100644
index 0000000..55f56ec
--- /dev/null
+++ b/src/network/ether_aton.c
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/ether.h>
+
+static struct ether_addr a;
+
+struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a) {
+ struct ether_addr a;
+ for (int ii = 0; ii < 6; ii++) {
+ unsigned long int n;
+ if (ii != 0) {
+ if (x[0] != ':') return 0; /* bad format */
+ else x++;
+ }
+ {
+ char *y;
+ n = strtoul (x, &y, 16);
+ x = y;
+ }
+ if (n > 0xFF) return 0; /* bad byte */
+ a.ether_addr_octet[ii] = n;
+ }
+ if (x[0] != 0) return 0; /* bad format */
+ memmove (p_a, &a, sizeof (struct ether_addr));
+ return p_a;
+}
+
+struct ether_addr *ether_aton (const char *x) {
+ return ether_aton_r (x, &a);
+}
diff --git a/src/network/ether_ntoa.c b/src/network/ether_ntoa.c
new file mode 100644
index 0000000..bcc773a
--- /dev/null
+++ b/src/network/ether_ntoa.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <netinet/ether.h>
+
+static char x[18];
+
+char *ether_ntoa_r (const struct ether_addr *p_a, char *x) {
+ char *y;
+ y = x;
+ for (int ii = 0; ii < 6; ii++) {
+ x += sprintf (x, ii == 0 ? "%.2X" : ":%.2X", p_a -> ether_addr_octet[ii]);
+ }
+ return y;
+}
+
+char *ether_ntoa (const struct ether_addr *p_a) {
+ return ether_ntoa_r (p_a, x);
+}
--
1.7.11.1
next prev parent reply other threads:[~2013-05-08 3:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-14 21:27 Strake
2013-04-15 1:40 ` Rich Felker
2013-04-15 4:10 ` Strake
2013-04-20 1:49 ` Rich Felker
2013-05-05 14:02 ` Strake
2013-05-05 16:24 ` Szabolcs Nagy
2013-05-05 16:40 ` Rich Felker
2013-05-08 3:29 ` Strake [this message]
2013-04-29 2:07 ` Rich Felker
2013-05-05 14:11 ` Strake
2013-05-05 15:15 ` Rich Felker
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='CAL3m8eCzkmiawCYZ9xSfhzFbMBDb=QOc6AGYphHoQkVjxtLZzg@mail.gmail.com' \
--to=strake888@gmail.com \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).