Skip to content

Commit

Permalink
Convert packet fields to host endian
Browse files Browse the repository at this point in the history
  • Loading branch information
msantos committed Mar 21, 2010
1 parent 292ff82 commit e09ad5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions rst_icmp.c
Expand Up @@ -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 */
Expand All @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions rst_tcp.c
Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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);

Expand Down

0 comments on commit e09ad5c

Please sign in to comment.