summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2011-11-30 19:02:30 -0800
committerGuy Harris <guy@alum.mit.edu>2011-11-30 19:02:57 -0800
commit0471082f20bcc02196bd85f665f7f34c71ba8845 (patch)
tree92a925f5a65d98467e3aa6d2b1617673f1a18f44
parent59a971d93df078875f26430e9bddc4165b23697f (diff)
downloadlibpcap-0471082f20bcc02196bd85f665f7f34c71ba8845.tar.gz
Fix the code generated for "ip protochain".
-rw-r--r--gencode.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/gencode.c b/gencode.c
index ff90fbb8..b771dfa7 100644
--- a/gencode.c
+++ b/gencode.c
@@ -5814,12 +5814,9 @@ gen_protochain(v, proto, dir)
/*
* in short,
- * A = P[X];
- * X = X + (P[X + 1] + 1) * 8;
+ * A = P[X + packet head];
+ * X = X + (P[X + packet head + 1] + 1) * 8;
*/
- /* A = X */
- s[i] = new_stmt(BPF_MISC|BPF_TXA);
- i++;
/* A = P[X + packet head] */
s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B);
s[i]->s.k = off_macpl + off_nl;
@@ -5828,19 +5825,9 @@ gen_protochain(v, proto, dir)
s[i] = new_stmt(BPF_ST);
s[i]->s.k = reg2;
i++;
- /* A = X */
- s[i] = new_stmt(BPF_MISC|BPF_TXA);
- i++;
- /* A += 1 */
- s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K);
- s[i]->s.k = 1;
- i++;
- /* X = A */
- s[i] = new_stmt(BPF_MISC|BPF_TAX);
- i++;
- /* A = P[X + packet head]; */
+ /* A = P[X + packet head + 1]; */
s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B);
- s[i]->s.k = off_macpl + off_nl;
+ s[i]->s.k = off_macpl + off_nl + 1;
i++;
/* A += 1 */
s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K);
@@ -5850,6 +5837,10 @@ gen_protochain(v, proto, dir)
s[i] = new_stmt(BPF_ALU|BPF_MUL|BPF_K);
s[i]->s.k = 8;
i++;
+ /* A += X */
+ s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_X);
+ s[i]->s.k = 0;
+ i++;
/* X = A; */
s[i] = new_stmt(BPF_MISC|BPF_TAX);
i++;