<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">This is how I fixed it. I did similar things for EXTRACT_32BITS and EXTRACT_64BITS.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">static inline u_int16_t<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">EXTRACT_16BITS(const void *p)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">#if defined(__arm__) && defined(__rtems__)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> if(((uint32_t)p % 2) != 0) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> u_int16_t value;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> u_int8_t *ptr = (u_int8_t *)&value;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> ptr[0] = ((const u_int8_t *)p)[0];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> ptr[1] = ((const u_int8_t *)p)[1];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> p = &value;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">#endif /* __rtems__ */<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> return ((u_int16_t)ntohs(*(const u_int16_t *)(p)));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Kevin Kirspel<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Electrical Engineer - Sr. Staff<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Idexx Roswell<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">235 Hembree Park Drive<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Roswell GA 30076<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Tel: (770)-510-4444 ext. 81642<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Direct: (770)-688-1642<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Fax: (770)-510-4445<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Joel Sherrill [mailto:joel@rtems.org]
<br>
<b>Sent:</b> Saturday, July 01, 2017 11:39 AM<br>
<b>To:</b> Gedare Bloom <gedare@rtems.org><br>
<b>Cc:</b> rtems-devel@rtems.org <devel@rtems.org>; Kirspel, Kevin <Kevin-Kirspel@idexx.com><br>
<b>Subject:</b> Re: LIBBSD TCPDUMP<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Jul 1, 2017 10:34 AM, "Gedare Bloom" <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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->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>
><o:p></o:p></p>
</div>
<p class="MsoNormal">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.<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Can't you also just pull it out a byte at a time, form the net version and then ntohs()?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">That's what I coded recently in some marahalling code.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal"><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">(770)-510-4444 ext. 81642</a><br>
><br>
> Direct: <a href="tel:%28770%29-688-1642">(770)-688-1642</a><br>
><br>
> Fax: <a href="tel:%28770%29-510-4445">(770)-510-4445</a><br>
><br>
><br>
><br>
><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.rtems.org_mailman_listinfo_devel&d=DwMFaQ&c=2do6VJGs3LvEOe4OFFM1bA&r=HDiJ93ANMEQ32G5JGdpyUxbdebuwKHBbeiHMr3RbR74&m=DfsZaORruX70gPrZk3-vjldOIsh4IFQ9ZRHVCZMKJ_o&s=Xx_hsbQ3vmD8L038yTJmDbvtePgAQkCJ7YBI_A6FR-Y&e=" target="_blank">
http://lists.rtems.org/mailman/listinfo/devel</a><br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.rtems.org_mailman_listinfo_devel&d=DwMFaQ&c=2do6VJGs3LvEOe4OFFM1bA&r=HDiJ93ANMEQ32G5JGdpyUxbdebuwKHBbeiHMr3RbR74&m=DfsZaORruX70gPrZk3-vjldOIsh4IFQ9ZRHVCZMKJ_o&s=Xx_hsbQ3vmD8L038yTJmDbvtePgAQkCJ7YBI_A6FR-Y&e=" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>