summaryrefslogtreecommitdiffstats
path: root/tinyNET/test/test_dhcp.h
blob: ee6e7670d10148b2c5b903e12b01feecf2ff482a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* Copyright (C) 2014 Mamadou DIOP.
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO 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 General Public License
* along with DOUBANGO.
*
*/
#ifndef TNET_TEST_DHCP_H
#define TNET_TEST_DHCP_H



void test_dhcp_discover(tnet_dhcp_ctx_t *ctx)
{
}

void test_dhcp_offer(tnet_dhcp_ctx_t *ctx)
{
}

void test_dhcp_request(tnet_dhcp_ctx_t *ctx)
{
}

void test_dhcp_inform(tnet_dhcp_ctx_t *ctx)
{
    tnet_dhcp_params_t *params = tsk_null;
    tnet_dhcp_reply_t *reply = tsk_null;

    params = tnet_dhcp_params_create();
    tnet_dhcp_params_add_code(params, dhcp_code_SIP_Servers_DHCP_Option); /* SIP Servers */
    tnet_dhcp_params_add_code(params, dhcp_code_Domain_Server); /* DNS Server */

    reply = tnet_dhcp_query_inform(ctx, params);

    if(reply && !TNET_DHCP_MESSAGE_IS_REPLY(reply)) {
        TSK_DEBUG_ERROR("DHCP request is not expected in response to a request.");
        goto bail;
    }

    if(reply) {
        switch(reply->type) {
        case dhcp_type_ack: {
            tsk_list_item_t *item;
            TSK_DEBUG_INFO("DHCP response type ==> ACK.");

            tsk_list_foreach(item, reply->options) {
                const tnet_dhcp_option_t *option = item->data;

                /* SIP SERVERS */
                if(option->code == dhcp_code_SIP_Servers_DHCP_Option) {
                    tsk_list_item_t *item2;
                    const tnet_dhcp_option_sip_t *option_sip4 = (const tnet_dhcp_option_sip_t*)option;;
                    tsk_list_foreach(item2, option_sip4->servers) {
                        const tsk_string_t *str = item2->data;
                        TSK_DEBUG_INFO("DHCP-SIP_SERVER ==>%s", str->value);
                    }
                }

                /* DNS SERVERS */
                if(option->code == dhcp_code_Domain_Server) {
                    tsk_list_item_t *item2;
                    const tnet_dhcp_option_dns_t *option_dns = (const tnet_dhcp_option_dns_t*)option;;
                    tsk_list_foreach(item2, option_dns->servers) {
                        const tsk_string_t *str = item2->data;
                        TSK_DEBUG_INFO("DHCP-DNS_SERVER ==>%s", str->value);
                    }
                }
            }
            break;
        }

        default: {
            break;
        }
        }
    }
    else {
        TSK_DEBUG_ERROR("DHCP reply is NULL.");
        goto bail;
    }

bail:
    TSK_OBJECT_SAFE_FREE(reply);
    TSK_OBJECT_SAFE_FREE(params);

    //tsk_thread_sleep(1000);
}

void test_dhcp()
{
    tnet_dhcp_ctx_t *ctx = tnet_dhcp_ctx_create();
    test_dhcp_inform(ctx);

    TSK_OBJECT_SAFE_FREE(ctx);
}

#endif /* TNET_TEST_DHCP_H */
OpenPOWER on IntegriCloud