Re: Alignment issues -- are they an issue?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?=

    Re: Alignment issues -- are they an issue?

    On Sep 22, 10:45 am, Nick Keighley <nick_keighley_ nos...@hotmail. com>
    wrote:
    TCP/IP (I'm including UDP in that) headers are arranged so
    that on most sane architectures you don't have alignment issues.

    Only problem is that then entire frame in memory might have strange
    alignment.

    you *are* writing your own UDP stack?

    Yup!

    I have seen code blow up on this. A well written UDP implementation
    should be ok with this. This is why I'm wondering if you are the
    implementor.

    I'm writing a program at the moment which maps a network, telling you
    all the hosts present, and also telling you which routers (if any)
    lead to the internet. I test for an internet connection by sending DNS
    request packets to the MAC address of each of the hosts and seeing if
    I get a reply. I hand-craft these DNS requests by myself, sending them
    to different MAC addresses.

    I go with shift and or. It isn't much more code!
    >
    After we had the alignment trap we put this code in
    >
        p[0] << 8 + p[1]
    >
    which was "interestin g"

    I wonder if it'd be too "distancing " to do the following for now:

    #define GET_S(p) (p[0] << 8 | p[1])

    But of course then I've the issue of multiple evaluation of the macro
    argument.
  • blargg

    #2
    Re: Alignment issues -- are they an issue?

    In article
    <3b59e8bd-7c85-46da-9247-bdde3b5c443a@w2 4g2000prd.googl egroups.com>,
    =?ISO-8859-1?Q?Tom=E1s_=D3 _h=C9ilidhe?= <toe@lavabit.co mwrote:
    On Sep 22, 10:45=A0am, Nick Keighley <nick_keighley_ nos...@hotmail. com>
    wrote:
    [...]
    I go with shift and or. It isn't much more code!

    After we had the alignment trap we put this code in

    p[0] << 8 + p[1]

    which was "interestin g"
    Yes, considering the relative precedence levels of << and + :)
    I wonder if it'd be too "distancing " to do the following for now:
    >
    #define GET_S(p) (p[0] << 8 | p[1])
    >
    But of course then I've the issue of multiple evaluation of the macro
    argument.
    And lack of parenthesis on p, and a dependence on int being more than 16
    bits (otherwise the result of p[0]<<8 could overflow a 16-bit signed int).

    Comment

    • Ian Collins

      #3
      Re: Alignment issues -- are they an issue?

      Tomás Ó hÉilidhe wrote:
      >
      I wonder if it'd be too "distancing " to do the following for now:
      >
      #define GET_S(p) (p[0] << 8 | p[1])
      >
      But of course then I've the issue of multiple evaluation of the macro
      argument.
      Use a function.

      --
      Ian Collins.

      Comment

      Working...