test-acd.c revision 4afd3348c7506dd1d36305b7bcb9feb8952b9d6b
9661674ed58ba62a40e43d1a4b38d5e77c3c6545Knut Anders Hatlen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
551b849ce88d596dc52dda2f78229a932b339c78Lubos Kosco This file is part of systemd.
9661674ed58ba62a40e43d1a4b38d5e77c3c6545Knut Anders Hatlen Copyright (C) 2014 Tom Gundersen <teg@jklm.no>
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye systemd is free software; you can redistribute it and/or modify it
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye under the terms of the GNU Lesser General Public License as published by
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye the Free Software Foundation; either version 2.1 of the License, or
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye (at your option) any later version.
bcae302a5f4b516d2f3c05f657df054e1a0efde7Knut Anders Hatlen systemd is distributed in the hope that it will be useful, but
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye WITHOUT ANY WARRANTY; without even the implied warranty of
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye Lesser General Public License for more details.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye You should have received a copy of the GNU Lesser General Public License
afb218f076cae538126a5f931299a82a114a075aKnut Anders Hatlen along with systemd; If not, see <http://www.gnu.org/licenses/>.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbyestatic void acd_handler(sd_ipv4acd *acd, int event, void *userdata) {
ca37bb3c4127b35d333203398bd983ee730d9da5Jan S Bergstatic int client_run(int ifindex, const struct in_addr *pa, const struct ether_addr *ha, sd_event *e) {
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_ipv4acd_attach_event(acd, e, 0) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_ipv4acd_set_index(acd, ifindex) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_ipv4acd_set_address(acd, pa) >= 0);
4bb936310d8f131aa850821e9254ac14242c7f95Knut Anders Hatlen assert_se(sd_ipv4acd_set_callback(acd, acd_handler, NULL) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbyestatic int test_acd(const char *ifname, const char *address) {
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL, *reply = NULL;
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(in_addr_from_string(AF_INET, address, &pa) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_netlink_attach_event(rtnl, e, 0) >= 0);
8d5c49b3d8edaa0069e4f802cf8bd70af9994c35Knut Anders Hatlen assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, 0) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_netlink_message_append_string(m, IFLA_IFNAME, ifname) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_netlink_call(rtnl, m, 0, &reply) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_rtnl_message_link_get_ifindex(reply, &ifindex) >= 0);
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye assert_se(sd_netlink_message_read_ether_addr(reply, IFLA_ADDRESS, &ha) >= 0);
return EXIT_SUCCESS;
log_open();
return EXIT_FAILURE;