Browse files

Convert packet fields to host endian

  • Loading branch information...
1 parent 292ff82 commit e09ad5c5c6a55fc00873a37fa7a481df6cbfaa48 @msantos committed Mar 21, 2010
Showing with 11 additions and 11 deletions.
  1. +3 −3 rst_icmp.c
  2. +8 −8 rst_tcp.c
View
6 rst_icmp.c
@@ -300,7 +300,7 @@ rst_icmp_send(pkt_t *rst)
LIBNET_ERR(libnet_build_ipv4(
LIBNET_IPV4_H + icmp_len, /* payload size */
IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
- ih->ip_id+1, /* IP ID */
+ ntohs(ih->ip_id)+1, /* IP ID */
0, /* Frag */
64, /* TTL */
IPPROTO_ICMP, /* Protocol */
@@ -316,9 +316,9 @@ rst_icmp_send(pkt_t *rst)
state = ((libnet_write(rst->l) == -1) ? "x" : "I");
(void)fprintf(stdout, "[%s] SRC = %15s:%-6u DST = %15s:%-6u len = %d/%d\n", state,
libnet_addr2name4(PAIR(pair, ih->ip_src.s_addr, ih->ip_dst.s_addr), LIBNET_DONT_RESOLVE),
- PAIR(pair, th->th_sport, th->th_dport),
+ PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)),
libnet_addr2name4(PAIR(pair, ih->ip_dst.s_addr, ih->ip_src.s_addr), LIBNET_DONT_RESOLVE),
- PAIR(pair, th->th_dport, th->th_sport), LIBNET_IPV4_H + (u_int32_t)icmp_len, ih->ip_len);
+ PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)), LIBNET_IPV4_H + (u_int32_t)icmp_len, ntohs(ih->ip_len));
(void)fflush(stdout);
View
16 rst_tcp.c
@@ -63,12 +63,12 @@ rst_tcp_send(pkt_t *rst)
/* Send out a pair of RST's to source and to destination */
for (pair = 0; pair < 2; pair++) {
LIBNET_ERR(libnet_build_tcp(
- PAIR(pair, th->th_sport, th->th_dport), /* Source port */
- PAIR(pair, th->th_dport, th->th_sport), /* Destination port */
- PAIR(pair, th->th_seq, th->th_ack), /* Sequence number */
- PAIR(pair, th->th_ack, ( (th->th_ack == 0) ? (th->th_seq + ih->ip_len) : th->th_seq)), /* Acknowledgement number */
+ PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)), /* Source port */
+ PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)), /* Destination port */
+ PAIR(pair, ntohl(th->th_seq), ntohl(th->th_ack)), /* Sequence number */
+ PAIR(pair, ntohl(th->th_ack), ( (th->th_ack == 0) ? (ntohl(th->th_seq) + ntohs(ih->ip_len)) : ntohl(th->th_seq))), /* Acknowledgement number */
TH_RST,
- th->th_win, /* XXX believe the packets window size? */
+ ntohs(th->th_win), /* XXX believe the packets window size? */
0, /* auto checksum */
0, /* XXX urg pointer */
LIBNET_TCP_H, /* total packet length */
@@ -81,7 +81,7 @@ rst_tcp_send(pkt_t *rst)
LIBNET_ERR(libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_TCP_H, /* no payload */
0, /* TOS */
- ih->ip_id, /* IP ID */
+ ntohs(ih->ip_id), /* IP ID */
0, /* Frag */
ih->ip_ttl, /* XXX TTL, from the packet? */
IPPROTO_TCP, /* Protocol */
@@ -97,9 +97,9 @@ rst_tcp_send(pkt_t *rst)
state = ( (libnet_write(rst->l) == -1) ? "x" : "R");
(void)fprintf(stdout, "[%s] SRC = %s:%u DST = %s:%u\n", state,
libnet_addr2name4(PAIR(pair, ih->ip_src.s_addr, ih->ip_dst.s_addr), LIBNET_DONT_RESOLVE),
- PAIR(pair, th->th_sport, th->th_dport),
+ PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)),
libnet_addr2name4(PAIR(pair, ih->ip_dst.s_addr, ih->ip_src.s_addr), LIBNET_DONT_RESOLVE),
- PAIR(pair, th->th_dport, th->th_sport));
+ PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)));
(void)fflush(stdout);

0 comments on commit e09ad5c

Please sign in to comment.