<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jul 1, 2017 10:34 AM, "Gedare Bloom" <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On Sat, Jul 1, 2017 at 10:01 AM, Kirspel, Kevin <<a href="mailto:Kevin-Kirspel@idexx.com">Kevin-Kirspel@idexx.com</a>> wrote:<br>
> I get a crash when running the tcpdump command in LIBBSD.  It is due to the<br>
> following structure<br>
><br>
><br>
><br>
> struct stp_bpdu_ {<br>
><br>
>     u_int8_t protocol_id[2];<br>
><br>
>     u_int8_t protocol_version;<br>
><br>
>     u_int8_t bpdu_type;<br>
><br>
>     u_int8_t flags;<br>
><br>
>     u_int8_t root_id[8];<br>
><br>
>     u_int8_t root_path_cost[4];<br>
><br>
>    u_int8_t bridge_id[8];<br>
><br>
>     u_int8_t port_id[2];<br>
><br>
>     u_int8_t message_age[2];<br>
><br>
>     u_int8_t max_age[2];<br>
><br>
>     u_int8_t hello_time[2];<br>
><br>
>     u_int8_t forward_delay[2];<br>
><br>
>     u_int8_t v1_length;<br>
><br>
> };<br>
><br>
><br>
><br>
> In the code, there is an access to the port_id field as follows:<br>
> EXTRACT_16BITS(&stp_bpdu-><wbr>port_id).  EXTRACT_16BITS calls ntohs() .  Since<br>
> the address of “&stp_bpdu->port_id” is at an odd word (16 bit) boundary, an<br>
> exception is generated.  What is the correct way to fix this?  I was going<br>
> to update EXTRACT_16BITS to check for an odd boundary and fix it up before<br>
> calling ntohs().<br>
><br>
<br>
</div>That would probably be a more portable fix than allowing unaligned<br>
accesses. I think the alignment should be made to the CPU_ALIGNMENT<br>
macro.<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Can't you also just pull it out a byte at a time, form the net version and then ntohs()?</div><div dir="auto"><br></div><div dir="auto">That's what I coded recently in some marahalling code.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="quoted-text"><br>
<br>
><br>
><br>
> Kevin Kirspel<br>
><br>
> Electrical Engineer - Sr. Staff<br>
><br>
> Idexx Roswell<br>
><br>
> 235 Hembree Park Drive<br>
><br>
> Roswell GA 30076<br>
><br>
> Tel: <a href="tel:%28770%29-510-4444%20ext.%2081642" value="+17705104444">(770)-510-4444 ext. 81642</a><br>
><br>
> Direct: <a href="tel:%28770%29-688-1642" value="+17706881642">(770)-688-1642</a><br>
><br>
> Fax: <a href="tel:%28770%29-510-4445" value="+17705104445">(770)-510-4445</a><br>
><br>
><br>
><br>
><br>
</div><div class="elided-text">> ______________________________<wbr>_________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a><br>
______________________________<wbr>_________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a></div></blockquote></div><br></div></div></div>