Skip to content

Commit d3a27c3

Browse files
committed
DAG: Use more named constants in pcap-dag.c.
1 parent 5b2f9df commit d3a27c3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pcap-dag.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ dag_erf_ext_header_count(const uint8_t *erf, size_t len)
192192
return 0;
193193

194194
/* check if we have any extension headers */
195-
if ( (erf[8] & 0x80) == 0x00 )
195+
if (! (erf[8] & ERF_TYPE_MORE_EXT))
196196
return 0;
197197

198198
/* loop over the extension headers */
@@ -206,15 +206,15 @@ dag_erf_ext_header_count(const uint8_t *erf, size_t len)
206206
hdr_type = erf[(16 + (hdr_num * 8))];
207207
hdr_num++;
208208

209-
} while ( hdr_type & 0x80 );
209+
} while (hdr_type & ERF_TYPE_MORE_EXT);
210210

211211
return hdr_num;
212212
}
213213

214214
/*
215215
* Read at most max_packets from the capture stream and call the callback
216-
* for each of them. Returns the number of packets handled, -1 if an
217-
* error occurred, or -2 if we were told to break out of the loop.
216+
* for each of them. Returns the number of packets handled, PCAP_ERROR if an
217+
* error occurred, or PCAP_ERROR_BREAK if we were told to break out of the loop.
218218
*/
219219
static int
220220
dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
@@ -234,11 +234,11 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
234234
if (p->break_loop) {
235235
/*
236236
* Yes - clear the flag that indicates that
237-
* it has, and return -2 to indicate that
237+
* it has, and return PCAP_ERROR_BREAK to indicate that
238238
* we were told to break out of the loop.
239239
*/
240240
p->break_loop = 0;
241-
return -2;
241+
return PCAP_ERROR_BREAK;
242242
}
243243

244244
/* dag_advance_stream() will block (unless nonblock is called)
@@ -253,7 +253,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
253253
* is then responsible for efficiency.
254254
*/
255255
if ( NULL == (pd->dag_mem_top = dag_advance_stream(p->fd, pd->dag_stream, &(pd->dag_mem_bottom))) ) {
256-
return -1;
256+
return PCAP_ERROR;
257257
}
258258

259259
if (nonblocking && (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
@@ -295,19 +295,19 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
295295
if (p->break_loop) {
296296
/*
297297
* Yes - clear the flag that indicates that
298-
* it has, and return -2 to indicate that
298+
* it has, and return PCAP_ERROR_BREAK to indicate that
299299
* we were told to break out of the loop.
300300
*/
301301
p->break_loop = 0;
302-
return -2;
302+
return PCAP_ERROR_BREAK;
303303
}
304304

305305
rlen = ntohs(header->rlen);
306306
if (rlen < dag_record_size)
307307
{
308308
pcapint_strlcpy(p->errbuf, "dag_read: record too small",
309309
PCAP_ERRBUF_SIZE);
310-
return -1;
310+
return PCAP_ERROR;
311311
}
312312
pd->dag_mem_bottom += rlen;
313313

@@ -329,7 +329,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
329329
}
330330
}
331331

332-
if ((header->type & 0x7f) == ERF_TYPE_PAD) {
332+
if ((header->type & ERF_TYPE_MASK) == ERF_TYPE_PAD) {
333333
continue;
334334
}
335335

@@ -1277,7 +1277,7 @@ dag_get_datalink(pcap_t *p)
12771277
if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
12781278
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
12791279
errno, "malloc");
1280-
return (-1);
1280+
return PCAP_ERROR;
12811281
}
12821282

12831283
p->linktype = 0;
@@ -1286,7 +1286,7 @@ dag_get_datalink(pcap_t *p)
12861286
if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
12871287
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
12881288
errno, "dag_get_stream_erf_types");
1289-
return (-1);
1289+
return PCAP_ERROR;
12901290
}
12911291

12921292
while (types[index]) {

0 commit comments

Comments
 (0)