errno = sverr;
return (psmb_result_t){PSMB_ERROR};
}
+ /* TODO: set non-blocking */
return (psmb_result_t){PSMB_OK};
}
return (psmb_result_t){PSMB_OK};
}
-psmb_result_t psmb_subscribe(psmb_ctx_t *ctx, char *channel) {
+psmb_result_t psmb_subscribe(psmb_ctx_t *ctx, char *channel)
+{
return psmb_sub_unsub(ctx, channel, IPV6_ADD_MEMBERSHIP);
}
-psmb_result_t psmb_unsubscribe(psmb_ctx_t *ctx, char *channel) {
+psmb_result_t psmb_unsubscribe(psmb_ctx_t *ctx, char *channel)
+{
return psmb_sub_unsub(ctx, channel, IPV6_DROP_MEMBERSHIP);
}
+psmb_result_t psmb_ev_rd(psmb_ctx_t *ctx)
+{
+ char buf[MAXBUFLEN];
+ char cmsgbuf[MAXBUFLEN];
+ struct iovec iov[1];
+ iov[0].iov_base=buf;
+ iov[0].iov_len=sizeof(buf);
+ struct cmsghdr *cmsg;
+ struct msghdr message;
+ message.msg_name=&their_addr;
+message.msg_namelen=sizeof(their_addr);
+message.msg_iov=iov;
+message.msg_iovlen=1;
+message.msg_control=cmsgbuf;
+message.msg_controllen=MAXBUFLEN;
+
+ if ((numbytes = recvmsg(sockfd, &message, 0)) == -1) {
+ /* error */ ;
+ }
+ for (cmsg = CMSG_FIRSTHDR(&message); cmsg != NULL; cmsg = CMSG_NXTHDR(&message, cmsg)) {
+ if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_PKTINFO)
+ continue;
+ struct in_pktinfo *pi = CMSG_DATA(cmsg);
+ addr = pi->ipi_spec_dst.s_addr;
+ }
+
+
+ return (psmb_result_t){PSMB_OK};
+}
+
+psmb_result_t psmb_ev_wr(psmb_ctx_t *ctx)
+{
+ sock_opt_addr.s_addr = addr;
+ setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_IF, &sock_opt_addr, sizeof(sock_opt_addr));
+ sendto(sockfd, buffer, len, 0, (struct sockaddr *)&destination, sizeof destination);
+
+ return (psmb_result_t){PSMB_OK};
+}
+
+psmb_result_t psmb_ev_ex(psmb_ctx_t *ctx)
+{
+ return (psmb_result_t){PSMB_OK};
+}
+
+psmb_result_t psmb_publish(psmb_ctx_t *ctx, char *channel,
+ void *data, size_t size)
+{
+ return (psmb_result_t){PSMB_OK};
+}
+
+psmb_result_t psmb_get_message(psmb_ctx_t *ctx, char **channel,
+ void **data, size_t *size)
+{
+ return (psmb_result_t){PSMB_OK};
+}
+
bool psmb_success(psmb_result_t result)
{
return !(result.code & PSMB_ERROR);