Skip to content

Commit

Permalink
Bug #393 force alignment in failing function (#394)
Browse files Browse the repository at this point in the history
* Bug #393 force alignment in failing function

* Bug #393 fix armel etc. build issue
  • Loading branch information
fklassen authored May 16, 2017
1 parent efa2ce4 commit 5d39a75
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dnl $Id$
AC_PREREQ([2.69])

dnl Set version info here!
AC_INIT([tcpreplay],[4.2.5],
AC_INIT([tcpreplay],[4.2.6-beta2],
[https://github.com/appneta/tcpreplay/issues],
[tcpreplay],
[http://tcpreplay.sourceforge.net/])
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
05/10/2017 Version 4.2.6-beta2
- Test fails on sparc64 (#393)

05/02/2017 Version 4.2.5
- Fix issues found by scan-build (#384)
- Improve --portmap help message (#381)
Expand Down
16 changes: 8 additions & 8 deletions src/common/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ get_l2len(const u_char *pktdata, const int datalen, const int datalink)
/**
* \brief returns a ptr to the ipv4 header + data or NULL if it's not IP
*
* we may use an extra buffer for the ip header (and above)
* on stricly aligned systems where the layer 2 header doesn't
* fall on a 4 byte boundry (like a standard ethernet header)
* we may use an extra buffer for the IP header (and above)
* on strictly aligned systems where the layer 2 header doesn't
* fall on a 4 byte boundary (like a standard Ethernet header)
*
* Note: you can cast the result as an ip_hdr_t, but you'll be able
* to access data above the header minus any stripped L2 data
Expand Down Expand Up @@ -247,7 +247,7 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
* back onto the pkt.data + l2len buffer
* we do all this work to prevent byte alignment issues
*/
if (l2_len % 4) {
if (l2_len % sizeof(long)) {
memcpy(*newbuff, (pktdata + l2_len), (datalen - l2_len));
ip_hdr = *newbuff;
} else {
Expand All @@ -270,9 +270,9 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
/**
* \brief returns a ptr to the ipv6 header + data or NULL if it's not IP
*
* we may use an extra buffer for the ip header (and above)
* on stricly aligned systems where the layer 2 header doesn't
* fall on a 4 byte boundry (like a standard ethernet header)
* we may use an extra buffer for the IP header (and above)
* on strictly aligned systems where the layer 2 header doesn't
* fall on a 4 byte boundary (like a standard Ethernet header)
*
* Note: you can cast the result as an ip_hdr_t, but you'll be able
* to access data above the header minus any stripped L2 data
Expand Down Expand Up @@ -309,7 +309,7 @@ get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
* back onto the pkt.data + l2len buffer
* we do all this work to prevent byte alignment issues
*/
if (l2_len % 4) {
if (l2_len % sizeof(long)) {
memcpy(*newbuff, (pktdata + l2_len), (datalen - l2_len));
ip6_hdr = *newbuff;
} else {
Expand Down
29 changes: 24 additions & 5 deletions src/tcpedit/edit_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,11 @@ randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
{
arp_hdr_t *arp_hdr = NULL;
int l2len = 0;
uint32_t *ip, tempip;
uint32_t *ip;
u_char *add_hdr;
#ifdef FORCE_ALIGN
uint32_t iptemp;
#endif

assert(tcpedit);
assert(pkthdr);
Expand All @@ -968,14 +971,30 @@ randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
/* jump to the addresses */
add_hdr = (u_char *)arp_hdr;
add_hdr += sizeof(arp_hdr_t) + arp_hdr->ar_hln;
#ifdef FORCE_ALIGN
/* copy IP to a temporary buffer for processing */
memcpy(&iptemp, add_hdr, sizeof(uint32_t));
ip = &iptemp;
#else
ip = (uint32_t *)add_hdr;
tempip = randomize_ipv4_addr(tcpedit, *ip);
memcpy(ip, &tempip, sizeof(uint32_t));
#endif
*ip = randomize_ipv4_addr(tcpedit, *ip);
#ifdef FORCE_ALIGN
memcpy(add_hdr, &iptemp, sizeof(uint32_t));
#endif

add_hdr += arp_hdr->ar_pln + arp_hdr->ar_hln;
#ifdef FORCE_ALIGN
/* copy IP2 to a temporary buffer for processing */
memcpy(&iptemp, add_hdr, sizeof(uint32_t));
ip = &iptemp;
#else
ip = (uint32_t *)add_hdr;
tempip = randomize_ipv4_addr(tcpedit, *ip);
memcpy(ip, &tempip, sizeof(uint32_t));
#endif
*ip = randomize_ipv4_addr(tcpedit, *ip);
#ifdef FORCE_ALIGN
memcpy(add_hdr, &iptemp, sizeof(uint32_t));
#endif
}

return 1; /* yes we changed the packet */
Expand Down

0 comments on commit 5d39a75

Please sign in to comment.