r5155: define ipv4address as a based IDL type, mapped to a "const char *" in
authorAndrew Tridgell <tridge@samba.org>
Tue, 1 Feb 2005 04:12:44 +0000 (04:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:28 +0000 (13:09 -0500)
the header, and defined on the wire as a 4 byte network byte order
IP. This means the calling code doesn't have to worry about network
byte order conversions.
(This used to be commit 72048e37179dd5b9ada0c5280d2f0d8c23d1a17d)

12 files changed:
source4/build/pidl/util.pm
source4/include/includes.h
source4/libcli/nbt/namequery.c
source4/libcli/nbt/namerefresh.c
source4/libcli/nbt/nameregister.c
source4/librpc/idl/epmapper.idl
source4/librpc/idl/misc.idl
source4/librpc/idl/nbt.idl
source4/librpc/ndr/ndr_basic.c
source4/librpc/rpc/dcerpc_util.c
source4/nbt_server/query.c
source4/torture/rpc/epmapper.c

index c57322a4625fbb3a13af52a50075ca828ccb4c46..112b617806f1776c258c23715fb505c7faa470f2 100644 (file)
@@ -302,6 +302,7 @@ my %type_alignments =
      "WERROR"         => 4,
      "boolean32"      => 4,
      "unsigned32"     => 4,
+     "ipv4address"    => 4,
      "hyper"          => 8,
      "NTTIME_hyper"   => 8
      );
@@ -538,7 +539,8 @@ my %type_mappings =
      "udlong"       => "uint64_t",
      "hyper"        => "uint64_t",
      "NTTIME_1sec"  => "NTTIME",
-     "NTTIME_hyper" => "NTTIME"
+     "NTTIME_hyper" => "NTTIME",
+     "ipv4address"  => "const char *"
      );
 
 # map from a IDL type to a C header type
index a185669abd3a071dfec50290ba77423920c8647a..7d1ee5afc7f2b9c46616fef7def7cd5454746b7b 100644 (file)
 
 typedef int BOOL;
 
+/*
+  we use struct ipv4_addr to avoid having to include all the
+  system networking headers everywhere
+*/
+struct ipv4_addr {
+       uint32_t addr;
+};
+
 #ifndef HAVE_STRERROR
 extern char *sys_errlist[];
 #define strerror(i) sys_errlist[i]
index d77482fc2bc5cdb25b73650ec33d5bcb83af5117..072b1e459aca8819a9c4e4c55613b841545d1c88 100644 (file)
@@ -72,8 +72,6 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
 {
        NTSTATUS status;
        struct nbt_name_packet *packet;
-       const char *addr;
-       struct in_addr in;
        int i;
 
        status = nbt_name_request_recv(req);
@@ -102,13 +100,8 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
        }
        
        for (i=0;i<io->out.num_addrs;i++) {
-               in.s_addr = htonl(packet->answers[0].rdata.netbios.addresses[i].ipaddr.addr);
-               addr = inet_ntoa(in);
-               if (addr == NULL) {
-                       talloc_free(req);
-                       return NT_STATUS_NO_MEMORY;
-               }
-               io->out.reply_addrs[i] = talloc_strdup(mem_ctx, addr);
+               io->out.reply_addrs[i] = talloc_steal(mem_ctx, 
+                                                     packet->answers[0].rdata.netbios.addresses[i].ipaddr);
        }
 
        talloc_steal(mem_ctx, io->out.name.name);
index c121d9c9209302e92d8789c3fb6e99d58ee5415b..0d0576d7643e1a9168bb9d1b519321674b2ad859 100644 (file)
@@ -64,7 +64,8 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock,
                                                                     struct nbt_rdata_address, 1);
        if (packet->additional[0].rdata.netbios.addresses == NULL) goto failed;
        packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags;
-       packet->additional[0].rdata.netbios.addresses[0].ipaddr.addr   = htonl(inet_addr(io->in.address));
+       packet->additional[0].rdata.netbios.addresses[0].ipaddr = 
+               talloc_strdup(packet->additional, io->in.address);
        
        req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
                                    timeval_current_ofs(io->in.timeout, 0), False);
@@ -86,8 +87,6 @@ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
 {
        NTSTATUS status;
        struct nbt_name_packet *packet;
-       const char *addr;
-       struct in_addr in;
 
        status = nbt_name_request_recv(req);
        if (!NT_STATUS_IS_OK(status) ||
@@ -112,13 +111,8 @@ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
                talloc_free(req);
                return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
-       in.s_addr = htonl(packet->answers[0].rdata.netbios.addresses[0].ipaddr.addr);
-       addr = inet_ntoa(in);
-       if (addr == NULL) {
-               talloc_free(req);
-               return NT_STATUS_NO_MEMORY;
-       }
-       io->out.reply_addr = talloc_strdup(mem_ctx, addr);
+       io->out.reply_addr = talloc_steal(mem_ctx, 
+                                         packet->answers[0].rdata.netbios.addresses[0].ipaddr);
        talloc_steal(mem_ctx, io->out.name.name);
        talloc_steal(mem_ctx, io->out.name.scope);
            
index 7bed37cf78d64521c3c90aa08c1c6d87d8d88652..4701d0c1bcdc7a843e6cc2331fc9c2dc8a395749 100644 (file)
@@ -67,7 +67,9 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
                                                                     struct nbt_rdata_address, 1);
        if (packet->additional[0].rdata.netbios.addresses == NULL) goto failed;
        packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags;
-       packet->additional[0].rdata.netbios.addresses[0].ipaddr.addr   = htonl(inet_addr(io->in.address));
+       packet->additional[0].rdata.netbios.addresses[0].ipaddr = 
+               talloc_strdup(packet->additional, io->in.address);
+       if (packet->additional[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed;
        
        req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
                                    timeval_current_ofs(io->in.timeout, 0), False);
@@ -89,8 +91,6 @@ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
 {
        NTSTATUS status;
        struct nbt_name_packet *packet;
-       const char *addr;
-       struct in_addr in;
 
        status = nbt_name_request_recv(req);
        if (!NT_STATUS_IS_OK(status) ||
@@ -115,13 +115,8 @@ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
                talloc_free(req);
                return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
-       in.s_addr = htonl(packet->answers[0].rdata.netbios.addresses[0].ipaddr.addr);
-       addr = inet_ntoa(in);
-       if (addr == NULL) {
-               talloc_free(req);
-               return NT_STATUS_NO_MEMORY;
-       }
-       io->out.reply_addr = talloc_strdup(mem_ctx, addr);
+       io->out.reply_addr = talloc_steal(mem_ctx, 
+                                         packet->answers[0].rdata.netbios.addresses[0].ipaddr);
        talloc_steal(mem_ctx, io->out.name.name);
        talloc_steal(mem_ctx, io->out.name.scope);
            
index ba5770b30508043d4bdb6cdf41f2264de8f2c387..89c4e246f9d85e046ad80947c2caa926a34fa0d7 100644 (file)
@@ -99,7 +99,7 @@ interface epmapper
        } epm_rhs_tcp;
 
        typedef struct {
-               ipv4_addr ipaddr;
+               ipv4address ipaddr;
        } epm_rhs_ip;
 
        typedef struct {
index 4b69d1089bbd5aa2e73778bf11a71bee93e89960..13306b687627637047e481e464bb36694d52dd60 100644 (file)
@@ -6,10 +6,6 @@
 
 interface misc
 {
-       typedef [public,noprint] struct {
-               uint32 addr;
-       } ipv4_addr;
-
        typedef [public,noprint,gensize] struct {
                uint32 time_low;
                uint16 time_mid;
index 9dc42fccbafc8f892d52681764be12d0f99de814..08dde1f0183ed52212f306b6475b567072bad0a4 100644 (file)
@@ -102,7 +102,7 @@ interface nbt
 
        typedef struct {
                nb_flags nb_flags;
-               ipv4_addr  ipaddr;
+               ipv4address ipaddr;
        } nbt_rdata_address;
 
        typedef struct {
index 9601421044670add7205b6ddd042559217ca62b6..507ee1594b80fafde1a37ff325650ecc0410072e 100644 (file)
@@ -21,6 +21,7 @@
 */
 
 #include "includes.h"
+#include "system/network.h"
 
 #define NDR_BE(ndr) (((ndr)->flags & (LIBNDR_FLAG_BIGENDIAN|LIBNDR_FLAG_LITTLE_ENDIAN)) == LIBNDR_FLAG_BIGENDIAN)
 #define NDR_SVAL(ndr, ofs) (NDR_BE(ndr)?RSVAL(ndr->data,ofs):SVAL(ndr->data,ofs))
@@ -1017,6 +1018,39 @@ NTSTATUS ndr_pull_time_t(struct ndr_pull *ndr, time_t *t)
 }
 
 
+/*
+  pull a ipv4address
+*/
+NTSTATUS ndr_pull_ipv4address(struct ndr_pull *ndr, const char **address)
+{
+       struct ipv4_addr in;
+       NDR_CHECK(ndr_pull_uint32(ndr, &in.addr));
+       in.addr = htonl(in.addr);
+       *address = talloc_strdup(ndr, sys_inet_ntoa(in));
+       NT_STATUS_HAVE_NO_MEMORY(*address);
+       return NT_STATUS_OK;
+}
+
+/*
+  push a ipv4address
+*/
+NTSTATUS ndr_push_ipv4address(struct ndr_push *ndr, const char *address)
+{
+       uint32_t addr = interpret_addr(address);
+       NDR_CHECK(ndr_push_uint32(ndr, htonl(addr)));
+       return NT_STATUS_OK;
+}
+
+/*
+  print a ipv4address
+*/
+void ndr_print_ipv4address(struct ndr_print *ndr, const char *name, 
+                          const char *address)
+{
+       ndr->print(ndr, "%-25s: %s", name, address);
+}
+
+
 void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type)
 {
        ndr->print(ndr, "%s: struct %s", name, type);
index 7639ca3fdd018da77b7615c6b5e8bc2c5a8eacb5..ddc9386c026310dd53c2a720cd2b56bba1436457 100644 (file)
@@ -386,15 +386,7 @@ const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *flo
                return talloc_asprintf(mem_ctx, "%d", floor->rhs.http.port);
 
        case EPM_PROTOCOL_IP:
-               if (floor->rhs.ip.ipaddr.addr == 0) {
-                       return NULL; 
-               }
-
-               {
-                       struct ipv4_addr in;
-                       in.addr = htonl(floor->rhs.ip.ipaddr.addr);
-                       return talloc_strdup(mem_ctx, sys_inet_ntoa(in));
-               }
+               return talloc_strdup(mem_ctx, floor->rhs.ip.ipaddr);
 
        case EPM_PROTOCOL_NCACN:
                return NULL;
@@ -457,11 +449,8 @@ static NTSTATUS dcerpc_floor_set_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor
                return NT_STATUS_OK;
 
        case EPM_PROTOCOL_IP:
-               if (strlen(data) > 0) {
-                       floor->rhs.ip.ipaddr.addr = ntohl(interpret_addr(data));
-               } else {
-                       floor->rhs.ip.ipaddr.addr = 0;
-               }
+               floor->rhs.ip.ipaddr = talloc_strdup(mem_ctx, data);
+               NT_STATUS_HAVE_NO_MEMORY(floor->rhs.ip.ipaddr);
                return NT_STATUS_OK;
 
        case EPM_PROTOCOL_NCACN:
@@ -474,23 +463,17 @@ static NTSTATUS dcerpc_floor_set_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor
 
        case EPM_PROTOCOL_SMB:
                floor->rhs.smb.unc = talloc_strdup(mem_ctx, data);
-               if (!floor->rhs.smb.unc) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+               NT_STATUS_HAVE_NO_MEMORY(floor->rhs.smb.unc);
                return NT_STATUS_OK;
 
        case EPM_PROTOCOL_PIPE:
                floor->rhs.pipe.path = talloc_strdup(mem_ctx, data);
-               if (!floor->rhs.pipe.path) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+               NT_STATUS_HAVE_NO_MEMORY(floor->rhs.pipe.path);
                return NT_STATUS_OK;
 
        case EPM_PROTOCOL_NETBIOS:
                floor->rhs.netbios.name = talloc_strdup(mem_ctx, data);
-               if (!floor->rhs.netbios.name) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+               NT_STATUS_HAVE_NO_MEMORY(floor->rhs.netbios.name);
                return NT_STATUS_OK;
 
        case EPM_PROTOCOL_NCALRPC:
@@ -506,16 +489,12 @@ static NTSTATUS dcerpc_floor_set_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor
                
        case EPM_PROTOCOL_STREETTALK:
                floor->rhs.streettalk.streettalk = talloc_strdup(mem_ctx, data);
-               if (!floor->rhs.streettalk.streettalk) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+               NT_STATUS_HAVE_NO_MEMORY(floor->rhs.streettalk.streettalk);
                return NT_STATUS_OK;
                
        case EPM_PROTOCOL_UNIX_DS:
                floor->rhs.unix_ds.path = talloc_strdup(mem_ctx, data);
-               if (!floor->rhs.unix_ds.path) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+               NT_STATUS_HAVE_NO_MEMORY(floor->rhs.unix_ds.path);
                return NT_STATUS_OK;
                
        case EPM_PROTOCOL_NULL:
index 9b9d1e29b9970af1e2481b4f1057321a9e18918a..2d2e75d51eef207fded7c6918f554ec9f1fb6ab9 100644 (file)
@@ -60,7 +60,9 @@ static void nbt_name_query_reply(struct nbt_name_socket *nbtsock,
                                                            struct nbt_rdata_address, 1);
        if (packet->answers[0].rdata.netbios.addresses == NULL) goto failed;
        packet->answers[0].rdata.netbios.addresses[0].nb_flags = nb_flags;
-       packet->answers[0].rdata.netbios.addresses[0].ipaddr.addr = htonl(inet_addr(address));
+       packet->answers[0].rdata.netbios.addresses[0].ipaddr = 
+               talloc_strdup(packet->answers, address);
+       if (packet->answers[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed;
 
        DEBUG(7,("Sending name query reply for %s<%02x> at %s to %s:%d\n", 
                 name->name, name->type, src_address, address, src_port));
index ea1166b4edcfc30bf2df39b27df2601883eeca12..b8cd93a4db825021c93238ac7ebdb0bc6fdb010a 100644 (file)
@@ -63,12 +63,7 @@ static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
                        break;
 
                case EPM_PROTOCOL_IP:
-                       printf(" IP:");
-                       {
-                               struct ipv4_addr in;
-                               in.addr = htonl(rhs->ip.ipaddr.addr);
-                               printf("%s", sys_inet_ntoa(in));
-                       }
+                       printf(" IP:%s", rhs->ip.ipaddr);
                        break;
 
                case EPM_PROTOCOL_PIPE:
@@ -158,7 +153,7 @@ static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
        twr->tower.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
-       twr->tower.floors[4].rhs.ip.ipaddr.addr = 0;
+       twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
 
        status = dcerpc_epm_Map(p, mem_ctx, &r);
        if (NT_STATUS_IS_OK(status) && r.out.result == 0) {