X-Git-Url: http://git.meshlink.io/?p=catta;a=blobdiff_plain;f=src%2Fnetlink.c;h=91df6723bd0d7ecb113c8effbe7afc15c11893a9;hp=e2f0cebdab61e1a945bc7a18fd9b384337bcbf3b;hb=2c550daf4ac6a6aab7f21047c037b4dd53c57fa6;hpb=37d19f15523b6fe4d1fef2329abe421221b3d4b3 diff --git a/src/netlink.c b/src/netlink.c index e2f0ceb..91df672 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -1,18 +1,18 @@ /*** - This file is part of avahi. + This file is part of catta. - avahi is free software; you can redistribute it and/or modify it + catta is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - avahi is distributed in the hope that it will be useful, but WITHOUT + catta is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with avahi; if not, write to the Free Software + License along with catta; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -27,23 +27,23 @@ #include #include -#include +#include #include "netlink.h" -#include +#include -struct AvahiNetlink { +struct CattaNetlink { int fd; unsigned seq; - AvahiNetlinkCallback callback; + CattaNetlinkCallback callback; void* userdata; uint8_t* buffer; size_t buffer_length; - const AvahiPoll *poll_api; - AvahiWatch *watch; + const CattaPoll *poll_api; + CattaWatch *watch; }; -int avahi_netlink_work(AvahiNetlink *nl, int block) { +int catta_netlink_work(CattaNetlink *nl, int block) { ssize_t bytes; struct msghdr smsg; struct cmsghdr *cmsg; @@ -69,14 +69,14 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { if (errno == EAGAIN || errno == EINTR) return 0; - avahi_log_error(__FILE__": recvmsg() failed: %s", strerror(errno)); + catta_log_error(__FILE__": recvmsg() failed: %s", strerror(errno)); return -1; } cmsg = CMSG_FIRSTHDR(&smsg); if (!cmsg || cmsg->cmsg_type != SCM_CREDENTIALS) { - avahi_log_warn("No sender credentials received, ignoring data."); + catta_log_warn("No sender credentials received, ignoring data."); return -1; } @@ -91,7 +91,7 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) { if (!NLMSG_OK(p, (size_t) bytes)) { - avahi_log_warn(__FILE__": packet truncated"); + catta_log_warn(__FILE__": packet truncated"); return -1; } @@ -101,47 +101,47 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { return 0; } -static void socket_event(AvahiWatch *w, int fd, AVAHI_GCC_UNUSED AvahiWatchEvent event, void *userdata) { - AvahiNetlink *nl = userdata; +static void socket_event(CattaWatch *w, int fd, CATTA_GCC_UNUSED CattaWatchEvent event, void *userdata) { + CattaNetlink *nl = userdata; assert(w); assert(nl); assert(fd == nl->fd); - avahi_netlink_work(nl, 0); + catta_netlink_work(nl, 0); } -AvahiNetlink *avahi_netlink_new(const AvahiPoll *poll_api, uint32_t groups, void (*cb) (AvahiNetlink *nl, struct nlmsghdr *n, void* userdata), void* userdata) { +CattaNetlink *catta_netlink_new(const CattaPoll *poll_api, uint32_t groups, void (*cb) (CattaNetlink *nl, struct nlmsghdr *n, void* userdata), void* userdata) { int fd = -1; const int on = 1; struct sockaddr_nl addr; - AvahiNetlink *nl = NULL; + CattaNetlink *nl = NULL; assert(poll_api); assert(cb); if ((fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0) { - avahi_log_error(__FILE__": socket(PF_NETLINK): %s", strerror(errno)); + catta_log_error(__FILE__": socket(PF_NETLINK): %s", strerror(errno)); return NULL; } memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; addr.nl_groups = groups; - addr.nl_pid = 0; // use 0 instead of getpid() to allow multiple instances of avahi in one process + addr.nl_pid = 0; // use 0 instead of getpid() to allow multiple instances of catta in one process if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - avahi_log_error(__FILE__": bind(): %s", strerror(errno)); + catta_log_error(__FILE__": bind(): %s", strerror(errno)); goto fail; } if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) { - avahi_log_error(__FILE__": SO_PASSCRED: %s", strerror(errno)); + catta_log_error(__FILE__": SO_PASSCRED: %s", strerror(errno)); goto fail; } - if (!(nl = avahi_new(AvahiNetlink, 1))) { - avahi_log_error(__FILE__": avahi_new() failed."); + if (!(nl = catta_new(CattaNetlink, 1))) { + catta_log_error(__FILE__": catta_new() failed."); goto fail; } @@ -151,13 +151,13 @@ AvahiNetlink *avahi_netlink_new(const AvahiPoll *poll_api, uint32_t groups, void nl->callback = cb; nl->userdata = userdata; - if (!(nl->buffer = avahi_new(uint8_t, nl->buffer_length = 64*1024))) { - avahi_log_error(__FILE__": avahi_new() failed."); + if (!(nl->buffer = catta_new(uint8_t, nl->buffer_length = 64*1024))) { + catta_log_error(__FILE__": catta_new() failed."); goto fail; } - if (!(nl->watch = poll_api->watch_new(poll_api, fd, AVAHI_WATCH_IN, socket_event, nl))) { - avahi_log_error(__FILE__": Failed to create watch."); + if (!(nl->watch = poll_api->watch_new(poll_api, fd, CATTA_WATCH_IN, socket_event, nl))) { + catta_log_error(__FILE__": Failed to create watch."); goto fail; } @@ -169,14 +169,14 @@ fail: close(fd); if (nl) { - avahi_free(nl->buffer); - avahi_free(nl); + catta_free(nl->buffer); + catta_free(nl); } return NULL; } -void avahi_netlink_free(AvahiNetlink *nl) { +void catta_netlink_free(CattaNetlink *nl) { assert(nl); if (nl->watch) @@ -185,11 +185,11 @@ void avahi_netlink_free(AvahiNetlink *nl) { if (nl->fd >= 0) close(nl->fd); - avahi_free(nl->buffer); - avahi_free(nl); + catta_free(nl->buffer); + catta_free(nl); } -int avahi_netlink_send(AvahiNetlink *nl, struct nlmsghdr *m, unsigned *ret_seq) { +int catta_netlink_send(CattaNetlink *nl, struct nlmsghdr *m, unsigned *ret_seq) { assert(nl); assert(m); @@ -197,7 +197,7 @@ int avahi_netlink_send(AvahiNetlink *nl, struct nlmsghdr *m, unsigned *ret_seq) m->nlmsg_flags |= NLM_F_ACK; if (send(nl->fd, m, m->nlmsg_len, 0) < 0) { - avahi_log_error(__FILE__": send(): %s", strerror(errno)); + catta_log_error(__FILE__": send(): %s", strerror(errno)); return -1; }