Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Convert packet fields to host endian

  • Loading branch information...
commit e09ad5c5c6a55fc00873a37fa7a481df6cbfaa48 1 parent 292ff82
Michael Santos authored

Showing 2 changed files with 11 additions and 11 deletions. Show diff stats Hide diff stats

  1. +3 3 rst_icmp.c
  2. +8 8 rst_tcp.c
6 rst_icmp.c
@@ -300,7 +300,7 @@ rst_icmp_send(pkt_t *rst)
300 300 LIBNET_ERR(libnet_build_ipv4(
301 301 LIBNET_IPV4_H + icmp_len, /* payload size */
302 302 IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
303   - ih->ip_id+1, /* IP ID */
  303 + ntohs(ih->ip_id)+1, /* IP ID */
304 304 0, /* Frag */
305 305 64, /* TTL */
306 306 IPPROTO_ICMP, /* Protocol */
@@ -316,9 +316,9 @@ rst_icmp_send(pkt_t *rst)
316 316 state = ((libnet_write(rst->l) == -1) ? "x" : "I");
317 317 (void)fprintf(stdout, "[%s] SRC = %15s:%-6u DST = %15s:%-6u len = %d/%d\n", state,
318 318 libnet_addr2name4(PAIR(pair, ih->ip_src.s_addr, ih->ip_dst.s_addr), LIBNET_DONT_RESOLVE),
319   - PAIR(pair, th->th_sport, th->th_dport),
  319 + PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)),
320 320 libnet_addr2name4(PAIR(pair, ih->ip_dst.s_addr, ih->ip_src.s_addr), LIBNET_DONT_RESOLVE),
321   - PAIR(pair, th->th_dport, th->th_sport), LIBNET_IPV4_H + (u_int32_t)icmp_len, ih->ip_len);
  321 + PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)), LIBNET_IPV4_H + (u_int32_t)icmp_len, ntohs(ih->ip_len));
322 322
323 323 (void)fflush(stdout);
324 324
16 rst_tcp.c
@@ -63,12 +63,12 @@ rst_tcp_send(pkt_t *rst)
63 63 /* Send out a pair of RST's to source and to destination */
64 64 for (pair = 0; pair < 2; pair++) {
65 65 LIBNET_ERR(libnet_build_tcp(
66   - PAIR(pair, th->th_sport, th->th_dport), /* Source port */
67   - PAIR(pair, th->th_dport, th->th_sport), /* Destination port */
68   - PAIR(pair, th->th_seq, th->th_ack), /* Sequence number */
69   - PAIR(pair, th->th_ack, ( (th->th_ack == 0) ? (th->th_seq + ih->ip_len) : th->th_seq)), /* Acknowledgement number */
  66 + PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)), /* Source port */
  67 + PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)), /* Destination port */
  68 + PAIR(pair, ntohl(th->th_seq), ntohl(th->th_ack)), /* Sequence number */
  69 + PAIR(pair, ntohl(th->th_ack), ( (th->th_ack == 0) ? (ntohl(th->th_seq) + ntohs(ih->ip_len)) : ntohl(th->th_seq))), /* Acknowledgement number */
70 70 TH_RST,
71   - th->th_win, /* XXX believe the packets window size? */
  71 + ntohs(th->th_win), /* XXX believe the packets window size? */
72 72 0, /* auto checksum */
73 73 0, /* XXX urg pointer */
74 74 LIBNET_TCP_H, /* total packet length */
@@ -81,7 +81,7 @@ rst_tcp_send(pkt_t *rst)
81 81 LIBNET_ERR(libnet_build_ipv4(
82 82 LIBNET_IPV4_H + LIBNET_TCP_H, /* no payload */
83 83 0, /* TOS */
84   - ih->ip_id, /* IP ID */
  84 + ntohs(ih->ip_id), /* IP ID */
85 85 0, /* Frag */
86 86 ih->ip_ttl, /* XXX TTL, from the packet? */
87 87 IPPROTO_TCP, /* Protocol */
@@ -97,9 +97,9 @@ rst_tcp_send(pkt_t *rst)
97 97 state = ( (libnet_write(rst->l) == -1) ? "x" : "R");
98 98 (void)fprintf(stdout, "[%s] SRC = %s:%u DST = %s:%u\n", state,
99 99 libnet_addr2name4(PAIR(pair, ih->ip_src.s_addr, ih->ip_dst.s_addr), LIBNET_DONT_RESOLVE),
100   - PAIR(pair, th->th_sport, th->th_dport),
  100 + PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)),
101 101 libnet_addr2name4(PAIR(pair, ih->ip_dst.s_addr, ih->ip_src.s_addr), LIBNET_DONT_RESOLVE),
102   - PAIR(pair, th->th_dport, th->th_sport));
  102 + PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)));
103 103
104 104 (void)fflush(stdout);
105 105

0 comments on commit e09ad5c

Please sign in to comment.
Something went wrong with that request. Please try again.