test-dhcp6-client.c revision 813e3a6ffcd094696001716480bbd68008cc54c8
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright (C) 2014 Intel Corporation. All rights reserved.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering***/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdbool.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdio.h>
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering#include "macro.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "sd-event.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "event-util.h"
af49ca27ffd790d78dbbb465b978266dfd5c93daLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "sd-dhcp6-client.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "dhcp6-protocol.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic struct ether_addr mac_addr = {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering};
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poetteringstatic bool verbose = false;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poetteringstatic int test_client_basic(sd_event *e) {
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering sd_dhcp6_client *client;
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (verbose)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering printf("* %s\n", __FUNCTION__);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering assert_se(sd_dhcp6_client_new(&client) >= 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(client);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert_se(sd_dhcp6_client_set_index(client, 15) == 0);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert_se(sd_dhcp6_client_set_index(client, -42) == -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert_se(sd_dhcp6_client_set_index(client, -1) == 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp6_client_set_index(client, 42) >= 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp6_client_set_mac(client, &mac_addr) >= 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp6_client_set_callback(client, NULL, NULL) >= 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp6_client_detach_event(client) >= 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(!sd_dhcp6_client_unref(client));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
6073b6f26ab9fc6bf335faa7073ec443eef093fdTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint main(int argc, char *argv[]) {
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering _cleanup_event_unref_ sd_event *e;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering assert_se(sd_event_new(&e) >= 0);
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering log_set_max_level(LOG_DEBUG);
af49ca27ffd790d78dbbb465b978266dfd5c93daLennart Poettering log_parse_environment();
af49ca27ffd790d78dbbb465b978266dfd5c93daLennart Poettering log_open();
ad6c04756115809d615dede330213d73edf732a8Lennart Poettering
8a516214c4412e8a40544bd725a6d499a30cbbbfLennart Poettering test_client_basic(e);
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering}
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering