Skip to content

Commit d62a199

Browse files
committed
hurd: tweak error reporting.
strerror() on GNU/Hurd maps Mach error messages to strings, so we can use pcapint_fmt_errmsg_for_errno() to format messages for them. Add a #define pcapint_fmt_errmsg_for_kern_return_t for pcapint_fmt_errmsg_for_errno, and use the former in cases where the argument is a kern_return_t rather than an errno, to make it a bit clearer that is isn't mistakenly using pcapint_fmt_errmsg_for_errno on something that's not a return from a UN*X call. Fix one case where an errno, rather than a kern_return_t from the Mach message call that failed, was passed to pcapint_fmt_errmsg_for_kern_return_t().
1 parent 6f3fd41 commit d62a199

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pcap-hurd.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ static struct bpf_insn filter[] = {
3939
* believe we are computing wrong here. */
4040
#define FILTER_COUNT (sizeof(filter) / (sizeof(short)))
4141

42+
/*
43+
* strerror() on GNU/Hurd maps Mach error messages to strings,
44+
* so we can use pcapint_fmt_errmsg_for_errno() to format
45+
* messages for them.
46+
*/
47+
#define pcapint_fmt_errmsg_for_kern_return_t pcapint_fmt_errmsg_for_errno
48+
4249
static int
4350
PCAP_WARN_UNUSED_RESULT
4451
pcap_device_set_filter(pcap_t *p, filter_array_t filter_array,
@@ -51,7 +58,7 @@ pcap_device_set_filter(pcap_t *p, filter_array_t filter_array,
5158
filter_array, filter_count);
5259
if (! kr)
5360
return 0;
54-
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno,
61+
pcapint_fmt_errmsg_for_kern_return_t(p->errbuf, PCAP_ERRBUF_SIZE, kr,
5562
"device_set_filter");
5663
return PCAP_ERROR;
5764
}
@@ -141,7 +148,7 @@ pcap_read_hurd(pcap_t *p, int cnt _U_, pcap_handler callback, u_char *user)
141148
if (kr == MACH_RCV_INTERRUPTED)
142149
goto retry;
143150

144-
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, kr,
151+
pcapint_fmt_errmsg_for_kern_return_t(p->errbuf, PCAP_ERRBUF_SIZE, kr,
145152
"mach_msg");
146153
return PCAP_ERROR;
147154
}
@@ -203,7 +210,7 @@ pcap_inject_hurd(pcap_t *p, const void *buf, int size)
203210
(io_buf_ptr_t)buf, size, &count);
204211

205212
if (kr) {
206-
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, kr,
213+
pcapint_fmt_errmsg_for_kern_return_t(p->errbuf, PCAP_ERRBUF_SIZE, kr,
207214
"device_write");
208215
return -1;
209216
}
@@ -264,7 +271,7 @@ pcap_activate_hurd(pcap_t *p)
264271
kr = get_privileged_ports(NULL, &master);
265272

266273
if (kr) {
267-
pcapint_fmt_errmsg_for_errno(p->errbuf,
274+
pcapint_fmt_errmsg_for_kern_return_t(p->errbuf,
268275
PCAP_ERRBUF_SIZE, kr, "get_privileged_ports");
269276
if (kr == EPERM)
270277
ret = PCAP_ERROR_PERM_DENIED;
@@ -278,7 +285,7 @@ pcap_activate_hurd(pcap_t *p)
278285
mach_port_deallocate(mach_task_self(), master);
279286

280287
if (kr) {
281-
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, kr,
288+
pcapint_fmt_errmsg_for_kern_return_t(p->errbuf, PCAP_ERRBUF_SIZE, kr,
282289
"device_open");
283290
if (kr == ED_NO_SUCH_DEVICE) /* not ENODEV */
284291
ret = PCAP_ERROR_NO_SUCH_DEVICE;
@@ -289,7 +296,7 @@ pcap_activate_hurd(pcap_t *p)
289296
&ph->rcv_port);
290297

291298
if (kr) {
292-
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, kr,
299+
pcapint_fmt_errmsg_for_kern_return_t(p->errbuf, PCAP_ERRBUF_SIZE, kr,
293300
"mach_port_allocate");
294301
goto error;
295302
}

0 commit comments

Comments
 (0)