1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

ndr: Add support for pulling/printing an ipv6address type

This commit is contained in:
Kai Blin 2010-08-10 15:32:59 +02:00
parent 10a4ea7219
commit 013780b1e1
4 changed files with 55 additions and 4 deletions

View File

@ -493,6 +493,7 @@ NDR_SCALAR_PROTO(NTTIME_1sec, NTTIME)
NDR_SCALAR_PROTO(NTTIME_hyper, NTTIME)
NDR_SCALAR_PROTO(DATA_BLOB, DATA_BLOB)
NDR_SCALAR_PROTO(ipv4address, const char *)
NDR_SCALAR_PROTO(ipv6address, const char *)
NDR_SCALAR_PROTO(string, const char *)
NDR_SCALAR_PROTO(double, double)

View File

@ -831,7 +831,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_ipv4address(struct ndr_push *ndr, int ndr_fl
uint32_t addr;
if (!is_ipaddress(address)) {
return ndr_push_error(ndr, NDR_ERR_IPV4ADDRESS,
"Invalid IPv4 address: '%s'",
"Invalid IPv4 address: '%s'",
address);
}
addr = inet_addr(address);
@ -842,12 +842,60 @@ _PUBLIC_ enum ndr_err_code ndr_push_ipv4address(struct ndr_push *ndr, int ndr_fl
/*
print a ipv4address
*/
_PUBLIC_ void ndr_print_ipv4address(struct ndr_print *ndr, const char *name,
_PUBLIC_ void ndr_print_ipv4address(struct ndr_print *ndr, const char *name,
const char *address)
{
ndr->print(ndr, "%-25s: %s", name, address);
}
/*
pull a ipv6address
*/
#define IPV6_BYTES 16
#define IPV6_ADDR_STR_LEN 39
_PUBLIC_ enum ndr_err_code ndr_pull_ipv6address(struct ndr_pull *ndr, int ndr_flags, const char **address)
{
uint8_t addr[IPV6_BYTES];
char *addr_str = talloc_strdup(ndr->current_mem_ctx, "");
int i;
NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
for (i = 0; i < IPV6_BYTES; ++i) {
addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]);
/* We need a ':' every second byte but the last one */
if (i%2 == 1 && i != (IPV6_BYTES - 1)) {
addr_str = talloc_strdup_append(addr_str, ":");
}
}
*address = addr_str;
NDR_ERR_HAVE_NO_MEMORY(*address);
return NDR_ERR_SUCCESS;
}
/*
push a ipv6address
*/
_PUBLIC_ enum ndr_err_code ndr_push_ipv6address(struct ndr_push *ndr, int ndr_flags, const char *address)
{
uint32_t addr;
if (!is_ipaddress(address)) {
return ndr_push_error(ndr, NDR_ERR_IPV4ADDRESS,
"Invalid IPv6 address: '%s'",
address);
}
addr = inet_addr(address);
NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, htonl(addr)));
return NDR_ERR_SUCCESS;
}
/*
print a ipv6address
*/
_PUBLIC_ void ndr_print_ipv6address(struct ndr_print *ndr, const char *name,
const char *address)
{
ndr->print(ndr, "%-25s: %s", name, address);
}
#undef IPV6_BYTES
_PUBLIC_ void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type)
{

View File

@ -75,6 +75,7 @@ my $scalar_alignment = {
'nbt_string' => 4,
'wrepl_nbt_name' => 4,
'ipv4address' => 4,
'ipv6address' => 4, #16?
'dnsp_name' => 1
};

View File

@ -20,8 +20,8 @@ use strict;
my %types = ();
my @reference_scalars = (
"string", "string_array", "nbt_string",
"wrepl_nbt_name", "ipv4address"
"string", "string_array", "nbt_string",
"wrepl_nbt_name", "ipv4address", "ipv6address"
);
# a list of known scalar types
@ -57,6 +57,7 @@ my %scalars = (
"nbt_string" => "const char *",
"wrepl_nbt_name"=> "struct nbt_name *",
"ipv4address" => "const char *",
"ipv6address" => "const char *",
"dnsp_name" => "const char *",
);