Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.protocols.tcp-ip    |    TCP and IP network protocols.    |    14,669 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 14,376 of 14,669    |
|    TDH1978 to All    |
|    IPv4 header and memory alignment...    |
|    11 Mar 19 18:57:42    |
   
   From: thedeerhunter1978@movie.uni   
      
   This question is in regards to the iphdr struct that can be found in   
   /usr/include/linux/ip.h and /usr/include/netinet/ip.h. In some   
   open-source projects, I have seen this header mapped onto packet data,   
   to extract individual IPv4 header fields, like so:   
      
      
    struct iphdr   
    {   
    unsigned int ihl:4;   
    unsigned int version:4;   
    uint8_t tos;   
    uint16_t tot_len;   
    uint16_t id;   
    uint16_t frag_off;   
    uint8_t ttl;   
    uint8_t protocol;   
    uint16_t check;   
    uint32_t saddr;   
    uint32_t daddr;   
    };   
      
      
    struct iphdr* hdr = (struct iphdr*) packet_data;   
       
    uint32_t ipv4_src_addr = hdr->saddr;   
    uint32_t ipv4_dst_addr = hdr->daddr;   
       
       
   Is this safe? Given that the packet data could start at any memory   
   location, what guarantee is there that the 32-bit 'saddr' and 'daddr'   
   fields are properly aligned in memory at 32-bit boundaries?   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca