void *(*realloc)(void *ptr, size_t size))
{
psmb_ctx_t *ctx = (*malloc)(sizeof(psmb_ctx_t));
- if (!ctx)
+ if (!ctx) {
+ int sverr = errno;
+ LOG(ctx, LOG_ERR, "failed to allocate psmb_ctx: %m");
+ errno = sverr;
return NULL;
+ }
*ctx = (psmb_ctx_t){
.fd = -1,
.malloc = malloc, .free = free, .realloc = realloc,
ctx->log_priv = log_priv;
return (psmb_result_t){PSMB_OK};
} else {
+ LOG(ctx, LOG_ERR, "psmb_set_...() used after psmb_open()");
errno = EBUSY;
return (psmb_result_t){PSMB_ERROR};
}
ctx->pmtu = pmtu;
return (psmb_result_t){PSMB_OK};
} else {
+ LOG(ctx, LOG_ERR, "psmb_set_...() used after psmb_open()");
errno = EBUSY;
return (psmb_result_t){PSMB_ERROR};
}
ctx->port = port;
return (psmb_result_t){PSMB_OK};
} else {
+ LOG(ctx, LOG_ERR, "psmb_set_...() used after psmb_open()");
errno = EBUSY;
return (psmb_result_t){PSMB_ERROR};
}
ctx->prefixlen = prefixlen;
return (psmb_result_t){PSMB_OK};
} else {
+ LOG(ctx, LOG_ERR, "psmb_set_...() used after psmb_open()");
errno = EBUSY;
return (psmb_result_t){PSMB_ERROR};
}
};
if (ctx->fd != -1) {
+ LOG(ctx, LOG_ERR, "redundant call to psmb_open()");
errno = EBUSY;
return (psmb_result_t){PSMB_ERROR};
}
ctx->fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IPV6);
if (ctx->fd == -1) {
+ int sverr = errno;
+ LOG(ctx, LOG_ERR, "socket: %m");
+ errno = sverr;
return (psmb_result_t){PSMB_ERROR};
}
if (setsockopt(ctx->fd, SOL_SOCKET, SO_REUSEADDR,
&on, sizeof(on)) < 0) {
int sverr = errno;
+ LOG(ctx, LOG_ERR, "setsockopt(..., SO_REUSEADDR, ...): %m");
close(ctx->fd);
ctx->fd = -1;
errno = sverr;
if (setsockopt(ctx->fd, IPPROTO_IPV6, IPV6_PKTINFO,
&on, sizeof(on)) < 0) {
int sverr = errno;
+ LOG(ctx, LOG_ERR, "setsockopt(..., IPV6_PKTINFO, ...): %m");
close(ctx->fd);
ctx->fd = -1;
errno = sverr;
if (bind(ctx->fd, (struct sockaddr *)&addr,
sizeof(struct sockaddr)) == -1) {
int sverr = errno;
+ LOG(ctx, LOG_ERR, "bind(): %m");
close(ctx->fd);
ctx->fd = -1;
errno = sverr;