Update BOOTP/DHCP stack by adding SIP Server parser.
This commit is contained in:
parent
b27a5bad62
commit
d4ccf30d46
|
@ -39,6 +39,9 @@
|
|||
|
||||
// Useful link: http://support.microsoft.com/?scid=kb%3Ben-us%3B169289&x=21&y=14
|
||||
// Another one: http://www.iana.org/assignments/bootp-dhcp-parameters/
|
||||
// RFC 3319 Dynamic Host Configuration Protocol (DHCPv6) Options for Session Initiation Protocol (SIP) Servers
|
||||
// RFC 3361 Dynamic Host Configuration Protocol (DHCP-for-IPv4) Option for Session Initiation Protocol (SIP) Servers
|
||||
|
||||
|
||||
/* FIXME: USE retransmission mech (*2*2...)
|
||||
*/
|
||||
|
|
|
@ -54,7 +54,7 @@ TNET_BEGIN_DECLS
|
|||
/**< Destination port(Server) for outgoing DHCP messages as per RFC 2131 subclause 4.1. */
|
||||
#define TNET_DHCP_SERVER_PORT 67
|
||||
|
||||
#define TNET_DHCP_VENDOR_ID_DEFAULT "IM-client/OMA1.0 doubango/v0.0.0"
|
||||
#define TNET_DHCP_VENDOR_ID_DEFAULT "doubango/v0.0.0"
|
||||
#define TNET_DHCP_MAX_CODES 20
|
||||
|
||||
/** Parameter Request List (55)
|
||||
|
|
|
@ -153,6 +153,7 @@ bail:
|
|||
tnet_dhcp_message_t* tnet_dhcp_message_deserialize(const struct tnet_dhcp_ctx_s *ctx, const uint8_t *data, size_t size)
|
||||
{
|
||||
tnet_dhcp_message_t *message = 0;
|
||||
uint8_t *dataPtr, *dataEnd, *dataStart;
|
||||
|
||||
if(!data || !size)
|
||||
{
|
||||
|
@ -169,7 +170,70 @@ tnet_dhcp_message_t* tnet_dhcp_message_deserialize(const struct tnet_dhcp_ctx_s
|
|||
goto bail;
|
||||
}
|
||||
|
||||
dataPtr = (uint8_t*)data;
|
||||
dataStart = dataPtr;
|
||||
dataEnd = (dataStart + size);
|
||||
|
||||
/*== op (1)*/
|
||||
message->op = *(dataPtr++);
|
||||
/*== htype (1) */
|
||||
message->htype = *(dataPtr++);
|
||||
/*== hlen (1) */
|
||||
message->hlen = *(dataPtr++);
|
||||
/*== htype (1) */
|
||||
message->hops = *(dataPtr++);
|
||||
/*== xid (4) */
|
||||
message->xid= ntohl(*((uint32_t*)dataPtr));
|
||||
dataPtr += 4;
|
||||
/*== secs (2) */
|
||||
message->secs = ntohs(*((uint16_t*)dataPtr));
|
||||
dataPtr += 2;
|
||||
/*== flags (2) */
|
||||
message->flags = ntohs(*((uint16_t*)dataPtr));
|
||||
dataPtr += 2;
|
||||
/*== ciaddr (4) */
|
||||
message->ciaddr= ntohl(*((uint32_t*)dataPtr));
|
||||
dataPtr += 4;
|
||||
/*== yiaddr (4) */
|
||||
message->yiaddr= ntohl(*((uint32_t*)dataPtr));
|
||||
dataPtr += 4;
|
||||
/*== siaddr (4) */
|
||||
message->siaddr= ntohl(*((uint32_t*)dataPtr));
|
||||
dataPtr += 4;
|
||||
/*== giaddr (4) */
|
||||
message->giaddr= ntohl(*((uint32_t*)dataPtr));
|
||||
dataPtr += 4;
|
||||
/*== chaddr (16[max]) */
|
||||
memcpy(message->chaddr, dataPtr, message->hlen>16 ? 16 : message->hlen);
|
||||
dataPtr += 16;
|
||||
/*== sname (64) */
|
||||
memcpy(message->sname, dataPtr, 64);
|
||||
dataPtr += 64;
|
||||
/*== file (128) */
|
||||
memcpy(message->file, dataPtr, 128);
|
||||
dataPtr += 128;
|
||||
/*== Magic Cookie (4) */
|
||||
if(ntohl(*((uint32_t*)dataPtr)) != TNET_DHCP_MAGIC_COOKIE){
|
||||
TSK_DEBUG_ERROR("Invalid DHCP magic cookie.");
|
||||
// Do not exit ==> continue parsing.
|
||||
}
|
||||
dataPtr += 4;
|
||||
|
||||
/*== options (variable) */
|
||||
while(dataPtr<dataEnd && *dataPtr!=dhcp_code_End)
|
||||
{
|
||||
tnet_dhcp_option_t* option = tnet_dhcp_option_deserialize(dataPtr, (dataEnd-dataPtr));
|
||||
if(option && option->value){
|
||||
|
||||
if(option->code == dhcp_code_DHCP_Msg_Type){
|
||||
message->type = (tnet_dhcp_message_type_t)*TSK_BUFFER_TO_U8(option->value);
|
||||
}
|
||||
|
||||
dataPtr += option->value->size + 2/*Code Len*/;
|
||||
tsk_list_push_back_data(message->options, (void**)&option);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
bail:
|
||||
return message;
|
||||
|
|
|
@ -28,6 +28,12 @@
|
|||
*/
|
||||
#include "tnet_dhcp_option.h"
|
||||
|
||||
#include "tnet_dhcp_option_sip4.h"
|
||||
|
||||
#include "tnet_types.h"
|
||||
|
||||
#include "tsk_memory.h"
|
||||
#include "tsk_debug.h"
|
||||
|
||||
int tnet_dhcp_option_init(tnet_dhcp_option_t *option, tnet_dhcp_option_code_t code)
|
||||
{
|
||||
|
@ -36,7 +42,7 @@ int tnet_dhcp_option_init(tnet_dhcp_option_t *option, tnet_dhcp_option_code_t co
|
|||
if(!option->initialized)
|
||||
{
|
||||
option->code = code;
|
||||
option->value = TSK_BUFFER_CREATE_NULL();
|
||||
//option->value = TSK_BUFFER_CREATE_NULL();
|
||||
|
||||
option->initialized = 1;
|
||||
return 0;
|
||||
|
@ -68,12 +74,43 @@ tnet_dhcp_option_t* tnet_dhcp_option_deserialize(const void* data, size_t size)
|
|||
uint8_t* dataPtr = ((uint8_t*)data);
|
||||
uint8_t* dataEnd = (dataPtr+size);
|
||||
|
||||
tnet_dhcp_option_code_t code;
|
||||
uint8_t len;
|
||||
|
||||
/* Check validity */
|
||||
if(!dataPtr || !size)
|
||||
if(!dataPtr || size<2/*Code Len*/)
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
|
||||
code = (tnet_dhcp_option_code_t)*dataPtr++;
|
||||
len = *dataPtr++;
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case dhcp_code_SIP_Servers_DHCP_Option:
|
||||
{
|
||||
option = TNET_DHCP_OPTION_SIP4_CREATE(dataPtr, len);
|
||||
break;
|
||||
}
|
||||
|
||||
case dhcp_code_Domain_Server:
|
||||
{
|
||||
option = TNET_DHCP_OPTION_DNS_CREATE(dataPtr, len);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
option = TNET_DHCP_OPTION_CREATE(code);
|
||||
}
|
||||
}
|
||||
|
||||
/* In all case */
|
||||
if(option && !option->value && len){
|
||||
option->value = TSK_BUFFER_CREATE((((uint8_t*)data) + 2/*Code Len*/), len);
|
||||
}
|
||||
|
||||
bail:
|
||||
return option;
|
||||
}
|
||||
|
@ -88,11 +125,18 @@ int tnet_dhcp_option_serialize(const tnet_dhcp_option_t* option, tsk_buffer_t *o
|
|||
/* Code */
|
||||
tsk_buffer_append(output, &(option->code), 1);
|
||||
|
||||
/* Length */
|
||||
tsk_buffer_append(output, &(option->value->size), 1);
|
||||
if(option->value){
|
||||
/* Length */
|
||||
tsk_buffer_append(output, &(option->value->size), 1);
|
||||
|
||||
/* Value */
|
||||
tsk_buffer_append(output, option->value->data, option->value->size);
|
||||
/* Value */
|
||||
tsk_buffer_append(output, option->value->data, option->value->size);
|
||||
}
|
||||
else{
|
||||
/* Length */
|
||||
static uint8_t zero = 0x00;
|
||||
tsk_buffer_append(output, &zero, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,7 +162,7 @@ static void* tnet_dhcp_option_create(void * self, va_list * app)
|
|||
tnet_dhcp_option_t *option = self;
|
||||
if(option)
|
||||
{
|
||||
tnet_dhcp_option_init(option, dhcp_code_null);
|
||||
tnet_dhcp_option_init(option, va_arg(*app, tnet_dhcp_option_code_t));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -150,6 +194,9 @@ const void *tnet_dhcp_option_def_t = &tnet_dhcp_option_def_s;
|
|||
int tnet_dhcp_option_paramslist_add_code(tnet_dhcp_option_paramslist_t* self, tnet_dhcp_option_code_t code)
|
||||
{
|
||||
if(self){
|
||||
if(!TNET_DHCP_OPTION(self)->value){
|
||||
TNET_DHCP_OPTION(self)->value = TSK_BUFFER_CREATE_NULL();
|
||||
}
|
||||
return tsk_buffer_append(TNET_DHCP_OPTION(self)->value, &code, 1);
|
||||
}
|
||||
return -1;
|
||||
|
@ -188,3 +235,79 @@ static const tsk_object_def_t tnet_dhcp_option_paramslist_def_s =
|
|||
0,
|
||||
};
|
||||
const void *tnet_dhcp_option_paramslist_def_t = &tnet_dhcp_option_paramslist_def_s;
|
||||
|
||||
|
||||
/*=============================================
|
||||
* RFC 2132 - 3.8. Domain Name Server Option
|
||||
*==============================================*/
|
||||
//
|
||||
// [[DHCP OPTION - RFC 2132 3.8. Domain Name Server Option]] object definition
|
||||
//
|
||||
static void* tnet_dhcp_option_dns_create(void * self, va_list * app)
|
||||
{
|
||||
tnet_dhcp_option_dns_t *option = self;
|
||||
if(option)
|
||||
{
|
||||
const void* payload = va_arg(*app, const void*);
|
||||
size_t payload_size = va_arg(*app, size_t);
|
||||
|
||||
const uint8_t* payloadPtr = (const uint8_t*)payload;
|
||||
const uint8_t* payloadEnd = (payloadPtr + payload_size);
|
||||
|
||||
/* init base */
|
||||
tnet_dhcp_option_init(TNET_DHCP_OPTION(option), dhcp_code_Domain_Server);
|
||||
|
||||
option->servers = TSK_LIST_CREATE();
|
||||
|
||||
if(payload_size<4 || payload_size%4)
|
||||
{
|
||||
TSK_DEBUG_ERROR("DHCP - The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4.");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t i;
|
||||
char* ip4 = 0;
|
||||
uint32_t address;
|
||||
tsk_string_t* addrstring;
|
||||
|
||||
for(i=0; i<payload_size && (payloadPtr< payloadEnd); i+=4)
|
||||
{
|
||||
/*
|
||||
Code Len Address 1 Address 2
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
| 6 | n | a1 | a2 | a3 | a4 | a1 | a2 | ...
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
*/
|
||||
address = ntohl(*((uint32_t*)payloadPtr));
|
||||
tsk_sprintf(&ip4, "%u.%u.%u.%u", (address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, (address>>0)&0xFF);
|
||||
|
||||
addrstring = TSK_STRING_CREATE(ip4);
|
||||
tsk_list_push_back_data(option->servers, (void*)&addrstring);
|
||||
|
||||
TSK_FREE(ip4);
|
||||
payloadPtr+= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static void* tnet_dhcp_option_dns_destroy(void * self)
|
||||
{
|
||||
tnet_dhcp_option_dns_t *option = self;
|
||||
if(option)
|
||||
{
|
||||
/* deinit base */
|
||||
tnet_dhcp_option_deinit(TNET_DHCP_OPTION(option));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static const tsk_object_def_t tnet_dhcp_option_dns_def_s =
|
||||
{
|
||||
sizeof(tnet_dhcp_option_dns_t),
|
||||
tnet_dhcp_option_dns_create,
|
||||
tnet_dhcp_option_dns_destroy,
|
||||
0,
|
||||
};
|
||||
const void *tnet_dhcp_option_dns_def_t = &tnet_dhcp_option_dns_def_s;
|
|
@ -33,11 +33,13 @@
|
|||
#include "tinyNET_config.h"
|
||||
|
||||
#include "tsk_buffer.h"
|
||||
#include "tsk_string.h"
|
||||
|
||||
TNET_BEGIN_DECLS
|
||||
|
||||
#define TNET_DHCP_OPTION_CREATE() tsk_object_new(tnet_dhcp_option_def_t)
|
||||
#define TNET_DHCP_OPTION_PARAMSLIST_CREATE() tsk_object_new(tnet_dhcp_option_paramslist_def_t)
|
||||
#define TNET_DHCP_OPTION_CREATE(code) tsk_object_new(tnet_dhcp_option_def_t, code)
|
||||
#define TNET_DHCP_OPTION_PARAMSLIST_CREATE() tsk_object_new(tnet_dhcp_option_paramslist_def_t)
|
||||
#define TNET_DHCP_OPTION_DNS_CREATE(payload, payload_size) tsk_object_new(tnet_dhcp_option_dns_def_t, (const void*)payload, (size_t)payload_size)
|
||||
|
||||
#define TNET_DHCP_OPTION(self) ((tnet_dhcp_option_t*)(self))
|
||||
|
||||
|
@ -242,7 +244,7 @@ int tnet_dhcp_option_serializeex(tnet_dhcp_option_code_t code, uint8_t length, c
|
|||
|
||||
|
||||
|
||||
/** Parameter Request List */
|
||||
/** Parameter Request List Option */
|
||||
typedef struct tnet_dhcp_option_paramslist_s
|
||||
{
|
||||
TNET_DECLARE_DHCP_OPTION;
|
||||
|
@ -257,11 +259,26 @@ typedef struct tnet_dhcp_option_paramslist_s
|
|||
tnet_dhcp_option_paramslist_t;
|
||||
int tnet_dhcp_option_paramslist_add_code(tnet_dhcp_option_paramslist_t* self, tnet_dhcp_option_code_t code);
|
||||
|
||||
/** Domain Name Server Option */
|
||||
typedef struct tnet_dhcp_option_dns_s
|
||||
{
|
||||
TNET_DECLARE_DHCP_OPTION;
|
||||
|
||||
/* RFC 2132 - 3.8. Domain Name Server Option
|
||||
Code Len Address 1 Address 2
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
| 6 | n | a1 | a2 | a3 | a4 | a1 | a2 | ...
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
*/
|
||||
tsk_strings_L_t *servers;
|
||||
}
|
||||
tnet_dhcp_option_dns_t;
|
||||
|
||||
|
||||
|
||||
TINYNET_GEXTERN const void *tnet_dns_ns_def_t;
|
||||
TINYNET_GEXTERN const void *tnet_dhcp_option_paramslist_def_t;
|
||||
TINYNET_GEXTERN const void *tnet_dhcp_option_dns_def_t;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**@file tnet_dhcp_option_sip4.c
|
||||
* @brief Dynamic Host Configuration Protocol (DHCP-for-IPv4) Option for
|
||||
* Session Initiation Protocol (SIP) Servers as per RFC 3361.
|
||||
*
|
||||
* @author Mamadou Diop <diopmamadou(at)yahoo.fr>
|
||||
*
|
||||
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
||||
*/
|
||||
#include "tnet_dhcp_option_sip4.h"
|
||||
|
||||
#include "dns/tnet_dns_rr.h"
|
||||
|
||||
#include "tnet_types.h"
|
||||
|
||||
#include "tsk_memory.h"
|
||||
#include "tsk_string.h"
|
||||
|
||||
//
|
||||
// [[DHCP SIP4]] object definition
|
||||
//
|
||||
static void* tnet_dhcp_option_sip4_create(void * self, va_list * app)
|
||||
{
|
||||
tnet_dhcp_option_sip4_t *option = self;
|
||||
if(option)
|
||||
{
|
||||
const void* payload = va_arg(*app, const void*);
|
||||
size_t payload_size = va_arg(*app, size_t);
|
||||
|
||||
const uint8_t* payloadPtr = (const uint8_t*)payload;
|
||||
const uint8_t* payloadEnd = (payloadPtr + payload_size);
|
||||
|
||||
/* init base */
|
||||
tnet_dhcp_option_init(TNET_DHCP_OPTION(option), dhcp_code_SIP_Servers_DHCP_Option);
|
||||
|
||||
option->servers = TSK_LIST_CREATE();
|
||||
|
||||
/* Set values as per RFC 3361. */
|
||||
if(*payloadPtr == 0){ /* enc=0 */
|
||||
/*
|
||||
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
||||
|120|27 | 0 | 7 |'e'|'x'|'a'|'m'|'p'|'l'|'e'| 3 |'c'|'o'|'m'| 0 |
|
||||
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
||||
+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 7
|
||||
|'e'|'x'|'a'|'m'|'p'|'l'|'e'| 3 |'n'|'e'|'t'| 0 | +---+---+---
|
||||
+---+---+---+---+---+---+---+---+---+---+
|
||||
*/
|
||||
size_t offset = 0;
|
||||
char* server = 0;
|
||||
payloadPtr++;
|
||||
while((payloadPtr < payloadEnd) && !tnet_dns_rr_qname_deserialize(payload, (payloadEnd - payloadPtr), &server, &offset))
|
||||
{
|
||||
tsk_string_t* string = TSK_STRING_CREATE(server);
|
||||
tsk_list_push_back_data(option->servers, (void*)&string);
|
||||
TSK_FREE(server);
|
||||
payloadPtr += offset;
|
||||
break;// FIXME ==> check that the while loop is correct
|
||||
}
|
||||
}
|
||||
else{
|
||||
/*
|
||||
Code Len enc Address 1 Address 2
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
| 120 | n | 1 | a1 | a2 | a3 | a4 | a1 | ...
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
*/
|
||||
uint32_t address;
|
||||
tsk_string_t* addrstring;
|
||||
char* ip4 = 0;
|
||||
|
||||
while(payloadPtr < payloadEnd){
|
||||
address = ntohl(*((uint32_t*)++payloadPtr));
|
||||
|
||||
tsk_sprintf(&ip4, "%u.%u.%u.%u", (address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, (address>>0)&0xFF);
|
||||
|
||||
addrstring = TSK_STRING_CREATE(ip4);
|
||||
tsk_list_push_back_data(option->servers, (void*)&addrstring);
|
||||
|
||||
TSK_FREE(ip4);
|
||||
|
||||
payloadPtr+= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static void* tnet_dhcp_option_sip4_destroy(void * self)
|
||||
{
|
||||
tnet_dhcp_option_sip4_t *option = self;
|
||||
if(option)
|
||||
{
|
||||
/* deinit base */
|
||||
tnet_dhcp_option_deinit(TNET_DHCP_OPTION(option));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static const tsk_object_def_t tnet_dhcp_option_sip4_def_s =
|
||||
{
|
||||
sizeof(tnet_dhcp_option_sip4_t),
|
||||
tnet_dhcp_option_sip4_create,
|
||||
tnet_dhcp_option_sip4_destroy,
|
||||
0,
|
||||
};
|
||||
const void *tnet_dhcp_option_sip4_def_t = &tnet_dhcp_option_sip4_def_s;
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**@file tnet_dhcp_option_sip4.h
|
||||
* @brief Dynamic Host Configuration Protocol (DHCP-for-IPv4) Option for
|
||||
* Session Initiation Protocol (SIP) Servers as per RFC 3361.
|
||||
*
|
||||
* @author Mamadou Diop <diopmamadou(at)yahoo.fr>
|
||||
*
|
||||
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
||||
*/
|
||||
|
||||
#ifndef TNET_DHCP_OPTION_SIP4_H
|
||||
#define TNET_DHCP_OPTION_SIP4_H
|
||||
|
||||
#include "tinyNET_config.h"
|
||||
|
||||
#include "tnet_dhcp_option.h"
|
||||
|
||||
#include "tsk_string.h"
|
||||
|
||||
TNET_BEGIN_DECLS
|
||||
|
||||
#define TNET_DHCP_OPTION_SIP4_CREATE(payload, payload_size) tsk_object_new(tnet_dhcp_option_sip4_def_t, (const void*)payload, (size_t)payload_size)
|
||||
|
||||
typedef struct tnet_dhcp_option_sip4_s
|
||||
{
|
||||
TNET_DECLARE_DHCP_OPTION;
|
||||
|
||||
/* RFC 3361 subclause 3.1
|
||||
Code Len enc DNS name of SIP server
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
| 120 | n | 0 | s1 | s2 | s3 | s4 | s5 | ...
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+--
|
||||
*/
|
||||
tsk_strings_L_t *servers;
|
||||
}
|
||||
tnet_dhcp_option_sip4_t;
|
||||
|
||||
TINYNET_GEXTERN const void *tnet_dhcp_option_sip4_def_t;
|
||||
|
||||
TNET_END_DECLS
|
||||
|
||||
#endif /* #define TNET_DHCP_OPTION_SIP4_H */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**@file tnet_dhcp_option_sip6.h
|
||||
* @brief Dynamic Host Configuration Protocol (DHCPv6) Options
|
||||
* for Session Initiation Protocol (SIP) Servers as per RFC 3319.
|
||||
*
|
||||
* @author Mamadou Diop <diopmamadou(at)yahoo.fr>
|
||||
*
|
||||
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
||||
*/
|
||||
|
||||
#ifndef TNET_DHCP_OPTION_SIP6_H
|
||||
#define TNET_DHCP_OPTION_SIP6_H
|
||||
|
||||
#include "tinyNET_config.h"
|
||||
|
||||
#include "tnet_dhcp_option.h"
|
||||
|
||||
TNET_BEGIN_DECLS
|
||||
|
||||
#define TNET_DHCP_OPTION_SIP6_CREATE(payload, payload_size) tsk_object_new(tnet_option_dhcp_sip6_def_t, (const void*)payload, (size_t)payload_size)
|
||||
|
||||
typedef struct tnet_dhcp_option_sip6_s
|
||||
{
|
||||
TNET_DECLARE_DHCP_OPTION;
|
||||
}
|
||||
tnet_dhcp_option_sip6_t;
|
||||
|
||||
TINYNET_GEXTERN const void *tnet_dhcp_option_sip6_def_t;
|
||||
|
||||
TNET_END_DECLS
|
||||
|
||||
#endif /* #define TNET_DHCP_OPTION_SIP6_H */
|
|
@ -49,8 +49,8 @@
|
|||
#define RUN_TEST_STUN 0
|
||||
#define RUN_TEST_NAT 0
|
||||
#define RUN_TEST_IFACES 0
|
||||
#define RUN_TEST_DNS 1
|
||||
#define RUN_TEST_DHCP 0
|
||||
#define RUN_TEST_DNS 0
|
||||
#define RUN_TEST_DHCP 1
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef TNET_TEST_DHCP_H
|
||||
#define TNET_TEST_DHCP_H
|
||||
|
||||
#include "dhcp/tnet_dhcp_option_sip4.h"
|
||||
|
||||
void test_dhcp_discover(tnet_dhcp_ctx_t *ctx)
|
||||
{
|
||||
}
|
||||
|
@ -40,12 +42,74 @@ void test_dhcp_inform(tnet_dhcp_ctx_t *ctx)
|
|||
tnet_dhcp_reply_t *reply = 0;
|
||||
|
||||
params = TNET_DHCP_PARAMS_CREATE();
|
||||
tnet_dhcp_params_add_code(params, dhcp_code_SIP_Servers_DHCP_Option);
|
||||
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(!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_sip4_t *option_sip4 = (const tnet_dhcp_option_sip4_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()
|
||||
|
|
|
@ -490,6 +490,14 @@
|
|||
RelativePath="..\..\tinyNET\src\dhcp\tnet_dhcp_option.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tinyNET\src\dhcp\tnet_dhcp_option_sip4.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tinyNET\src\dhcp\tnet_dhcp_option_sip6.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
|
@ -646,6 +654,14 @@
|
|||
RelativePath="..\..\tinyNET\src\dhcp\tnet_dhcp_option.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tinyNET\src\dhcp\tnet_dhcp_option_sip4.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tinyNET\src\dhcp\tnet_dhcp_option_sip6.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
|
|
Loading…
Reference in New Issue