X-Git-Url: http://www.average.org/gitweb/?p=psmb.git;a=blobdiff_plain;f=src%2Fpsmb_socket.c;h=538b87c9c766e6159240d05d5ce36757f3c9ac07;hp=a3c718a9902334f9804cb6fa8338e3b1f9816961;hb=a8e5ec1ed734952452dde1fba33cc7be206cb28b;hpb=80f280e926ad1dfbd32edc8a8d2cd9a3f339f7b7 diff --git a/src/psmb_socket.c b/src/psmb_socket.c index a3c718a..538b87c 100644 --- a/src/psmb_socket.c +++ b/src/psmb_socket.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -102,7 +103,7 @@ psmb_result_t psmb_open(psmb_ctx_t *ctx) errno = EBUSY; return (psmb_result_t){PSMB_ERROR}; } - ctx->fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IPV6); + ctx->fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (ctx->fd == -1) { int sverr = errno; LOG(ctx, LOG_ERR, "socket: %m"); @@ -118,7 +119,7 @@ psmb_result_t psmb_open(psmb_ctx_t *ctx) errno = sverr; return (psmb_result_t){PSMB_ERROR}; } - if (setsockopt(ctx->fd, IPPROTO_IPV6, IPV6_PKTINFO, + if (setsockopt(ctx->fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on)) < 0) { int sverr = errno; LOG(ctx, LOG_ERR, "setsockopt(..., IPV6_PKTINFO, ...): %m"); @@ -128,7 +129,7 @@ psmb_result_t psmb_open(psmb_ctx_t *ctx) return (psmb_result_t){PSMB_ERROR}; } if (bind(ctx->fd, (struct sockaddr *)&addr, - sizeof(struct sockaddr)) == -1) { + sizeof(struct sockaddr_in6)) == -1) { int sverr = errno; LOG(ctx, LOG_ERR, "bind(): %m"); close(ctx->fd); @@ -138,3 +139,15 @@ psmb_result_t psmb_open(psmb_ctx_t *ctx) } return (psmb_result_t){PSMB_OK}; } + +void psmb_destroy(psmb_ctx_t *ctx) +{ + if (ctx->fd == -1) { + LOG(ctx, LOG_ERR, "psmb_ctx is not open"); + } else { + if (close(ctx->fd) == -1) + LOG(ctx, LOG_ERR, "close(): %m"); + } + /* clean up the rest */ + (*ctx->free)(ctx); +}