From 284349482f5293a9a23d0f72d7c2aab46b55843b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 22:48:25 +0000 Subject: [PATCH] r3443: the next stage in the include files re-organisation. I have created the include/system/ directory, which will contain the wrappers for the system includes for logical subsystems. So far I have created include/system/kerberos.h and include/system/network.h, which contain all the system includes for kerberos code and networking code. These are the included in subsystems that need kerberos or networking respectively. Note that this method avoids the mess of #ifdef HAVE_XXX_H in every C file, instead each C module includes the include/system/XXX.h file for the logical system support it needs, and the details are kept isolated in include/system/ This patch also creates a "struct ipv4_addr" which replaces "struct in_addr" in our code. That avoids every C file needing to import all the system networking headers. (This used to be commit 2e25c71853f8996f73755277e448e7d670810349) --- source4/auth/auth_domain.c | 12 +-- source4/auth/auth_server.c | 2 +- source4/build/m4/rewrite.m4 | 9 +- source4/client/mount.cifs.c | 2 +- source4/client/smbmount.c | 4 +- source4/include/ads.h | 2 +- source4/include/includes.h | 78 ++--------------- source4/include/interfaces.h | 12 --- source4/include/nameserv.h | 32 +++---- source4/include/structs.h | 1 + source4/include/system/README | 4 + source4/include/system/kerberos.h | 44 ++++++++++ source4/include/system/network.h | 60 +++++++++++++ source4/ldap_server/ldap_server.c | 8 +- source4/lib/basic.m4 | 1 + source4/lib/basic.mk | 14 +++- source4/lib/{ => netif}/interface.c | 66 +++++++++------ source4/lib/{interfaces.c => netif/netif.c} | 19 ++--- source4/lib/netif/netif.h | 34 ++++++++ source4/lib/replace.c | 2 +- source4/lib/socket/access.c | 1 + source4/lib/socket/socket_ipv4.c | 13 +-- source4/lib/socket/socket_ipv6.c | 1 + source4/lib/system.c | 22 +++++ source4/lib/util.c | 15 ++-- source4/lib/util_sock.c | 21 ++--- source4/lib/util_strlist.c | 16 ++-- source4/lib/wins_srv.c | 30 +++---- source4/libcli/auth/clikrb5.c | 2 + source4/libcli/auth/gensec_krb5.c | 2 + source4/libcli/auth/kerberos.c | 1 + source4/libcli/auth/kerberos_verify.c | 2 + source4/libcli/cliconnect.c | 2 +- source4/libcli/ldap/ldap.c | 3 +- source4/libcli/namecache.c | 6 +- source4/libcli/namequery.c | 93 +++++++++++---------- source4/libcli/namequery_dc.c | 6 +- source4/libcli/nmblib.c | 15 ++-- source4/libcli/raw/clisocket.c | 6 +- source4/libcli/raw/libcliraw.h | 2 +- source4/libnet/libnet_rpc.c | 4 +- source4/librpc/rpc/dcerpc_util.c | 5 +- source4/rpc_server/dcerpc_sock.c | 14 ++-- source4/smb_server/smb_server.c | 8 +- source4/torture/rpc/epmapper.c | 5 +- source4/utils/nmblookup.c | 10 +-- 46 files changed, 420 insertions(+), 291 deletions(-) create mode 100644 source4/include/system/README create mode 100644 source4/include/system/kerberos.h create mode 100644 source4/include/system/network.h rename source4/lib/{ => netif}/interface.c (86%) rename source4/lib/{interfaces.c => netif/netif.c} (97%) create mode 100644 source4/lib/netif/netif.h diff --git a/source4/auth/auth_domain.c b/source4/auth/auth_domain.c index 028bfc550b9..2452f8f65d5 100644 --- a/source4/auth/auth_domain.c +++ b/source4/auth/auth_domain.c @@ -35,7 +35,7 @@ BOOL global_machine_password_needs_changing = False; the 'ADS server' smb.conf parameter, which is what we really want anyway */ static NTSTATUS ads_resolve_dc(fstring remote_machine, - struct in_addr *dest_ip) + struct ipv4_addr *dest_ip) { ADS_STRUCT *ads; ads = ads_init_simple(); @@ -76,10 +76,10 @@ static NTSTATUS ads_resolve_dc(fstring remote_machine, */ static NTSTATUS rpc_resolve_dc(const char *server, fstring remote_machine, - struct in_addr *dest_ip) + struct ipv4_addr *dest_ip) { if (is_ipaddress(server)) { - struct in_addr to_ip = interpret_addr2(server); + struct ipv4_addr to_ip = interpret_addr2(server); /* we need to know the machines netbios name - this is a lousy way to find it, but until we have a RPC call that does this @@ -125,7 +125,7 @@ static NTSTATUS connect_to_domain_password_server(struct smbcli_state **cli, const uint8_t *trust_passwd, BOOL *retry) { - struct in_addr dest_ip; + struct ipv4_addr dest_ip; fstring remote_machine; NTSTATUS result; uint32_t neg_flags = 0x000001ff; @@ -230,7 +230,7 @@ machine %s. Error was : %s.\n", remote_machine, smbcli_errstr(*cli))); static NTSTATUS attempt_connect_to_dc(struct smbcli_state **cli, const char *domain, - struct in_addr *ip, + struct ipv4_addr *ip, const char *setup_creds_as, uint16_t sec_chan, const uint8_t *trust_passwd) @@ -267,7 +267,7 @@ static NTSTATUS find_connect_dc(struct smbcli_state **cli, uint8_t *trust_passwd, time_t last_change_time) { - struct in_addr dc_ip; + struct ipv4_addr dc_ip; fstring srv_name; if ( !rpc_find_dc(lp_workgroup(), srv_name, &dc_ip) ) { diff --git a/source4/auth/auth_server.c b/source4/auth/auth_server.c index d0c4bfc9023..8e1c712f5ef 100644 --- a/source4/auth/auth_server.c +++ b/source4/auth/auth_server.c @@ -32,7 +32,7 @@ static struct smbcli_state *server_cryptkey(TALLOC_CTX *mem_ctx) { struct smbcli_state *cli = NULL; fstring desthost; - struct in_addr dest_ip; + struct ipv4_addr dest_ip; const char *p; char *pserver; BOOL connected_ok = False; diff --git a/source4/build/m4/rewrite.m4 b/source4/build/m4/rewrite.m4 index 7fecd0b2655..48c6c6627a7 100644 --- a/source4/build/m4/rewrite.m4 +++ b/source4/build/m4/rewrite.m4 @@ -1065,7 +1065,8 @@ AC_TRY_RUN([ #define HAVE_IFACE_AIX 1 #define AUTOCONF_TEST 1 #include "confdefs.h" -#include "${srcdir-.}/lib/interfaces.c"], +#include "${srcdir-.}/lib/netif/netif.h" +#include "${srcdir-.}/lib/netif/netif.c"], samba_cv_HAVE_IFACE_AIX=yes,samba_cv_HAVE_IFACE_AIX=no,samba_cv_HAVE_IFACE_AIX=cross)]) if test x"$samba_cv_HAVE_IFACE_AIX" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available]) @@ -1077,7 +1078,8 @@ AC_TRY_RUN([ #define HAVE_IFACE_IFCONF 1 #define AUTOCONF_TEST 1 #include "confdefs.h" -#include "${srcdir-.}/lib/interfaces.c"], +#include "${srcdir-.}/lib/netif/netif.h" +#include "${srcdir-.}/lib/netif/netif.c"], samba_cv_HAVE_IFACE_IFCONF=yes,samba_cv_HAVE_IFACE_IFCONF=no,samba_cv_HAVE_IFACE_IFCONF=cross)]) if test x"$samba_cv_HAVE_IFACE_IFCONF" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available]) @@ -1090,7 +1092,8 @@ AC_TRY_RUN([ #define HAVE_IFACE_IFREQ 1 #define AUTOCONF_TEST 1 #include "confdefs.h" -#include "${srcdir-.}/lib/interfaces.c"], +#include "${srcdir-.}/lib/netif/netif.h" +#include "${srcdir-.}/lib/netif/netif.c"], samba_cv_HAVE_IFACE_IFREQ=yes,samba_cv_HAVE_IFACE_IFREQ=no,samba_cv_HAVE_IFACE_IFREQ=cross)]) if test x"$samba_cv_HAVE_IFACE_IFREQ" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available]) diff --git a/source4/client/mount.cifs.c b/source4/client/mount.cifs.c index 7167859d7b2..82904038158 100644 --- a/source4/client/mount.cifs.c +++ b/source4/client/mount.cifs.c @@ -197,7 +197,7 @@ char * parse_server(char * unc_name) char * share; char * ipaddress_string = NULL; struct hostent * host_entry; - struct in_addr server_ipaddr; + struct ipv4_addr server_ipaddr; int rc,j; char temp[64]; diff --git a/source4/client/smbmount.c b/source4/client/smbmount.c index 358fad6ae17..5e6d0209f2e 100644 --- a/source4/client/smbmount.c +++ b/source4/client/smbmount.c @@ -35,7 +35,7 @@ static pstring mpoint; static pstring service; static pstring options; -static struct in_addr dest_ip; +static struct ipv4_addr dest_ip; static BOOL have_ip; static int smb_port = 0; static BOOL got_user; @@ -118,7 +118,7 @@ static struct smbcli_state *do_connection(char *the_service) struct smbcli_state *c; struct nmb_name called, calling; char *server_n; - struct in_addr ip; + struct ipv4_addr ip; pstring server; char *share; diff --git a/source4/include/ads.h b/source4/include/ads.h index 71bca6eb711..8db0209573b 100644 --- a/source4/include/ads.h +++ b/source4/include/ads.h @@ -22,7 +22,7 @@ typedef struct { void *ld; /* the active ldap structure */ - struct in_addr ldap_ip; /* the ip of the active connection, if any */ + struct ipv4_addr ldap_ip; /* the ip of the active connection, if any */ time_t last_attempt; /* last attempt to reconnect */ int ldap_port; diff --git a/source4/include/includes.h b/source4/include/includes.h index 374abc4c370..a9198dbc1da 100644 --- a/source4/include/includes.h +++ b/source4/include/includes.h @@ -83,6 +83,7 @@ #endif /* RELIANTUNIX */ #include +#include #ifdef TIME_WITH_SYS_TIME #include @@ -114,14 +115,6 @@ #include #endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#ifdef HAVE_UNIXSOCKET -#include -#endif - #ifdef HAVE_SYS_SYSCALL_H #include #elif HAVE_SYSCALL_H @@ -213,10 +206,6 @@ #include #endif -#include -#include -#include - #ifdef HAVE_SYSLOG_H #include #else @@ -227,27 +216,6 @@ #include -#ifdef HAVE_NETINET_TCP_H -#include -#endif - -/* - * The next three defines are needed to access the IPTOS_* options - * on some systems. - */ - -#ifdef HAVE_NETINET_IN_SYSTM_H -#include -#endif - -#ifdef HAVE_NETINET_IN_IP_H -#include -#endif - -#ifdef HAVE_NETINET_IP_H -#include -#endif - #if defined(HAVE_TERMIOS_H) /* POSIX terminal handling. */ #include @@ -280,11 +248,6 @@ #include #endif -#ifdef HAVE_NET_IF_H -#include -#endif - - #ifdef HAVE_SYS_MOUNT_H #include #endif @@ -374,28 +337,6 @@ #endif #endif -#ifdef HAVE_KRB5_H -#include -#else -#undef HAVE_KRB5 -#endif - -#ifdef HAVE_GSSAPI_H -#include -#endif - -#ifdef HAVE_GSSAPI_GSSAPI_H -#include -#endif - -#ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H -#include -#endif - -#ifdef HAVE_COM_ERR_H -#include -#endif - /* we support ADS if we want it and have krb5 and ldap libs */ #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP) #define HAVE_ADS @@ -466,6 +407,14 @@ typedef int socklen_t; #define uint64 uint64_t #endif +/* + we use struct ipv4_addr to avoid having to include all the + system networking headers everywhere +*/ +struct ipv4_addr { + uint32_t s_addr; +}; + #ifndef UINT8_MAX #define UINT8_MAX 255 #endif @@ -518,7 +467,6 @@ extern int errno; #include "talloc.h" #include "db_wrap.h" #include "nt_status.h" -#include "interfaces.h" #include "trans2.h" #include "ioctl.h" #include "nterr.h" @@ -557,7 +505,6 @@ extern int errno; #include "libcli/auth/ntlmssp.h" #include "libcli/auth/credentials.h" -#include "libcli/auth/kerberos.h" #include "libcli/auth/gensec.h" #include "libcli/auth/spnego.h" #include "auth/auth.h" @@ -721,13 +668,6 @@ unsigned long strtoul(const char *nptr, char **endptr, int base); int setenv(const char *name, const char *value, int overwrite); #endif -#if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL)) -/* stupid glibc */ -int setresuid(uid_t ruid, uid_t euid, uid_t suid); -#endif -#if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL)) -int setresgid(gid_t rgid, gid_t egid, gid_t sgid); -#endif #ifndef HAVE_VASPRINTF_DECL int vasprintf(char **ptr, const char *format, va_list ap); #endif diff --git a/source4/include/interfaces.h b/source4/include/interfaces.h index 3b786f1ebcb..e69de29bb2d 100644 --- a/source4/include/interfaces.h +++ b/source4/include/interfaces.h @@ -1,12 +0,0 @@ -/* - This structure is used by lib/interfaces.c to return the list of network - interfaces on the machine -*/ - -#define MAX_INTERFACES 128 - -struct iface_struct { - char name[16]; - struct in_addr ip; - struct in_addr netmask; -}; diff --git a/source4/include/nameserv.h b/source4/include/nameserv.h index 33ee8f99e66..9efee46466e 100644 --- a/source4/include/nameserv.h +++ b/source4/include/nameserv.h @@ -206,7 +206,7 @@ struct nmb_data { uint16_t nb_flags; /* Netbios flags. */ int num_ips; /* Number of ip entries. */ - struct in_addr *ip; /* The ip list for this name. */ + struct ipv4_addr *ip; /* The ip list for this name. */ enum name_source source; /* Where the name came from. */ @@ -214,7 +214,7 @@ struct nmb_data time_t refresh_time; /* The time the record should be refreshed. */ uint64_t id; /* unique id */ - struct in_addr wins_ip; /* the adress of the wins server this record comes from */ + struct ipv4_addr wins_ip; /* the adress of the wins server this record comes from */ int wins_flags; /* similar to the netbios flags but different ! */ }; @@ -238,7 +238,7 @@ struct browse_cache_record #endif pstring lmb_name; pstring work_group; - struct in_addr ip; + struct ipv4_addr ip; time_t sync_time; time_t death_time; /* The time the record must be removed. */ }; @@ -307,7 +307,7 @@ struct work_record /* Domain master browser info. Used for efficient syncs. */ struct nmb_name dmb_name; - struct in_addr dmb_addr; + struct ipv4_addr dmb_addr; }; /* typedefs needed to define copy & free functions for userdata. */ @@ -353,7 +353,7 @@ typedef void (*register_name_success_function)( struct subnet_record *, struct nmb_name *, uint16_t, int, - struct in_addr); + struct ipv4_addr); typedef void (*register_name_fail_function)( struct subnet_record *, struct response_record *, struct nmb_name *); @@ -361,7 +361,7 @@ typedef void (*register_name_fail_function)( struct subnet_record *, typedef void (*release_name_success_function)( struct subnet_record *, struct userdata_struct *, struct nmb_name *, - struct in_addr); + struct ipv4_addr); typedef void (*release_name_fail_function)( struct subnet_record *, struct response_record *, struct nmb_name *); @@ -371,7 +371,7 @@ typedef void (*refresh_name_success_function)( struct subnet_record *, struct nmb_name *, uint16_t, int, - struct in_addr); + struct ipv4_addr); typedef void (*refresh_name_fail_function)( struct subnet_record *, struct response_record *, struct nmb_name *); @@ -379,7 +379,7 @@ typedef void (*refresh_name_fail_function)( struct subnet_record *, typedef void (*query_name_success_function)( struct subnet_record *, struct userdata_struct *, struct nmb_name *, - struct in_addr, + struct ipv4_addr, struct res_rec *answers); typedef void (*query_name_fail_function)( struct subnet_record *, @@ -390,7 +390,7 @@ typedef void (*query_name_fail_function)( struct subnet_record *, typedef void (*node_status_success_function)( struct subnet_record *, struct userdata_struct *, struct res_rec *, - struct in_addr); + struct ipv4_addr); typedef void (*node_status_fail_function)( struct subnet_record *, struct response_record *); @@ -457,9 +457,9 @@ struct subnet_record BOOL namelist_changed; BOOL work_changed; - struct in_addr bcast_ip; - struct in_addr mask_ip; - struct in_addr myip; + struct ipv4_addr bcast_ip; + struct ipv4_addr mask_ip; + struct ipv4_addr myip; int nmb_sock; /* socket to listen for unicast 137. */ int dgram_sock; /* socket to listen for unicast 138. */ }; @@ -535,7 +535,7 @@ struct dgram_packet { BOOL more; } flags; int dgm_id; - struct in_addr source_ip; + struct ipv4_addr source_ip; int source_port; int dgm_length; int packet_offset; @@ -554,7 +554,7 @@ struct packet_struct struct packet_struct *next; struct packet_struct *prev; BOOL locked; - struct in_addr ip; + struct ipv4_addr ip; int port; int fd; time_t timestamp; @@ -642,8 +642,8 @@ typedef struct _WINS_RECORD { int wins_flags; uint64_t id; int num_ips; - struct in_addr ip[25]; - struct in_addr wins_ip; + struct ipv4_addr ip[25]; + struct ipv4_addr wins_ip; } WINS_RECORD; /* To be removed. */ diff --git a/source4/include/structs.h b/source4/include/structs.h index 2757e6df578..e1e6de5d776 100644 --- a/source4/include/structs.h +++ b/source4/include/structs.h @@ -48,3 +48,4 @@ struct samr_CryptPasswordEx; struct netr_SamInfo3; struct netr_Authenticator; +struct iface_struct; diff --git a/source4/include/system/README b/source4/include/system/README new file mode 100644 index 00000000000..69a2b80b56c --- /dev/null +++ b/source4/include/system/README @@ -0,0 +1,4 @@ +This directory contains wrappers around logical groups of system +include files. The idea is to avoid #ifdef blocks in the main code, +and instead put all the necessary conditional includes in subsystem +specific header files in this directory. diff --git a/source4/include/system/kerberos.h b/source4/include/system/kerberos.h new file mode 100644 index 00000000000..85c635e2233 --- /dev/null +++ b/source4/include/system/kerberos.h @@ -0,0 +1,44 @@ +/* + Unix SMB/CIFS implementation. + + kerberos system include wrappers + + Copyright (C) Andrew Tridgell 2004 + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#ifdef HAVE_KRB5_H +#include +#else +#undef HAVE_KRB5 +#endif + +#ifdef HAVE_GSSAPI_H +#include +#endif + +#ifdef HAVE_GSSAPI_GSSAPI_H +#include +#endif + +#ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H +#include +#endif + +#ifdef HAVE_COM_ERR_H +#include +#endif diff --git a/source4/include/system/network.h b/source4/include/system/network.h new file mode 100644 index 00000000000..fcee0f7c246 --- /dev/null +++ b/source4/include/system/network.h @@ -0,0 +1,60 @@ +/* + Unix SMB/CIFS implementation. + + networking system include wrappers + + Copyright (C) Andrew Tridgell 2004 + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#ifdef HAVE_UNIXSOCKET +#include +#endif + +#include +#include +#include + +#ifdef HAVE_NETINET_TCP_H +#include +#endif + +/* + * The next three defines are needed to access the IPTOS_* options + * on some systems. + */ + +#ifdef HAVE_NETINET_IN_SYSTM_H +#include +#endif + +#ifdef HAVE_NETINET_IN_IP_H +#include +#endif + +#ifdef HAVE_NETINET_IP_H +#include +#endif + +#ifdef HAVE_NET_IF_H +#include +#endif + + diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c index a9aea2b4490..6013b6ecf4f 100644 --- a/source4/ldap_server/ldap_server.c +++ b/source4/ldap_server/ldap_server.c @@ -34,11 +34,11 @@ static void ldapsrv_terminate_connection(struct ldapsrv_connection *ldap_conn, c */ static void add_socket(struct server_service *service, const struct model_ops *model_ops, - struct in_addr *ifip) + struct ipv4_addr *ifip) { struct server_socket *srv_sock; uint16_t port = 389; - char *ip_str = talloc_strdup(service, inet_ntoa(*ifip)); + char *ip_str = talloc_strdup(service, sys_inet_ntoa(*ifip)); srv_sock = service_setup_socket(service, model_ops, "ipv4", ip_str, &port); @@ -99,7 +99,7 @@ static void ldapsrv_init(struct server_service *service, socket per interface and bind to only these. */ for(i = 0; i < num_interfaces; i++) { - struct in_addr *ifip = iface_n_ip(i); + struct ipv4_addr *ifip = iface_n_ip(i); if (ifip == NULL) { DEBUG(0,("ldapsrv_init: interface %d has NULL " @@ -110,7 +110,7 @@ static void ldapsrv_init(struct server_service *service, add_socket(service, model_ops, ifip); } } else { - struct in_addr ifip; + struct ipv4_addr ifip; /* Just bind to lp_socket_address() (usually 0.0.0.0) */ ifip = interpret_addr2(lp_socket_address()); diff --git a/source4/lib/basic.m4 b/source4/lib/basic.m4 index 6701ddaee52..1640ef2b9da 100644 --- a/source4/lib/basic.m4 +++ b/source4/lib/basic.m4 @@ -1,4 +1,5 @@ dnl # LIB BASIC subsystem SMB_SUBSYSTEM_MK(LIBREPLACE,lib/basic.mk) +SMB_SUBSYSTEM_MK(LIBNETIF,lib/basic.mk) SMB_SUBSYSTEM_MK(LIBBASIC,lib/basic.mk) diff --git a/source4/lib/basic.mk b/source4/lib/basic.mk index 56fc19dca73..55e654ec74e 100644 --- a/source4/lib/basic.mk +++ b/source4/lib/basic.mk @@ -9,6 +9,16 @@ ADD_OBJ_FILES = \ # End SUBSYSTEM LIBREPLACE ############################## +############################## +# Start SUBSYSTEM LIBNETIF +[SUBSYSTEM::LIBNETIF] +INIT_OBJ_FILES = \ + lib/netif/interface.o +ADD_OBJ_FILES = \ + lib/netif/netif.o +# End SUBSYSTEM LIBNETIF +############################## + ############################## # Start SUBSYSTEM LIBBASIC [SUBSYSTEM::LIBBASIC] @@ -17,8 +27,6 @@ ADD_OBJ_FILES = \ lib/debug.o \ lib/fault.o \ lib/getsmbpass.o \ - lib/interface.o \ - lib/interfaces.o \ lib/pidfile.o \ lib/signal.o \ lib/system.o \ @@ -57,6 +65,6 @@ ADD_OBJ_FILES = \ lib/server_mutex.o \ lib/idtree.o REQUIRED_SUBSYSTEMS = \ - LIBTDB CHARSET LIBREPLACE + LIBTDB CHARSET LIBREPLACE LIBNETIF # End SUBSYSTEM LIBBASIC ############################## diff --git a/source4/lib/interface.c b/source4/lib/netif/interface.c similarity index 86% rename from source4/lib/interface.c rename to source4/lib/netif/interface.c index 72568912af3..75fdf8c9762 100644 --- a/source4/lib/interface.c +++ b/source4/lib/netif/interface.c @@ -19,19 +19,21 @@ */ #include "includes.h" +#include "system/network.h" +#include "lib/netif/netif.h" static struct iface_struct *probed_ifaces; static int total_probed; -static struct in_addr allones_ip; -struct in_addr loopback_ip; +static struct ipv4_addr allones_ip; +struct ipv4_addr loopback_ip; /* used for network interfaces */ struct interface { struct interface *next, *prev; - struct in_addr ip; - struct in_addr bcast; - struct in_addr nmask; + struct ipv4_addr ip; + struct ipv4_addr bcast; + struct ipv4_addr nmask; }; static struct interface *local_interfaces; @@ -40,17 +42,24 @@ static struct interface *local_interfaces; #define MKBCADDR(_IP, _NM) ((_IP & _NM) | (_NM ^ ALLONES)) #define MKNETADDR(_IP, _NM) (_IP & _NM) +static struct ipv4_addr tov4(struct in_addr in) +{ + struct ipv4_addr in2; + in2.s_addr = in.s_addr; + return in2; +} + /**************************************************************************** Try and find an interface that matches an ip. If we cannot, return NULL **************************************************************************/ static struct interface *iface_find(struct in_addr ip, BOOL CheckMask) { struct interface *i; - if (is_zero_ip(ip)) return local_interfaces; + if (is_zero_ip(tov4(ip))) return local_interfaces; for (i=local_interfaces;i;i=i->next) if (CheckMask) { - if (same_net(i->ip,ip,i->nmask)) return i; + if (same_net(i->ip,tov4(ip),i->nmask)) return i; } else if ((i->ip).s_addr == ip.s_addr) return i; return NULL; @@ -78,15 +87,15 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) ZERO_STRUCTPN(iface); - iface->ip = ip; - iface->nmask = nmask; + iface->ip = tov4(ip); + iface->nmask = tov4(nmask); iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr); DLIST_ADD(local_interfaces, iface); - DEBUG(2,("added interface ip=%s ",inet_ntoa(iface->ip))); - DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast))); - DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask))); + DEBUG(2,("added interface ip=%s ",sys_inet_ntoa(iface->ip))); + DEBUG(2,("bcast=%s ",sys_inet_ntoa(iface->bcast))); + DEBUG(2,("nmask=%s\n",sys_inet_ntoa(iface->nmask))); } @@ -108,8 +117,8 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, const char *token) char *p; int i, added=0; - zero_ip(&ip); - zero_ip(&nmask); + ip.s_addr = 0; + nmask.s_addr = 0; /* first check if it is an interface name */ for (i=0;i 2) { - nmask = interpret_addr2(p); + nmask.s_addr = interpret_addr2(p).s_addr; } else { nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES)); } @@ -152,7 +161,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, const char *token) if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) || ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) { for (i=0;inext) @@ -268,7 +277,7 @@ BOOL ismyip(struct in_addr ip) /**************************************************************************** check if a packet is from a local (known) net **************************************************************************/ -BOOL is_local_net(struct in_addr from) +BOOL is_local_net(struct ipv4_addr from) { struct interface *i; for (i=local_interfaces;i;i=i->next) { @@ -295,7 +304,7 @@ int iface_count(void) /**************************************************************************** return IP of the Nth interface **************************************************************************/ -struct in_addr *iface_n_ip(int n) +struct ipv4_addr *iface_n_ip(int n) { struct interface *i; @@ -309,7 +318,7 @@ struct in_addr *iface_n_ip(int n) /**************************************************************************** return bcast of the Nth interface **************************************************************************/ -struct in_addr *iface_n_bcast(int n) +struct ipv4_addr *iface_n_bcast(int n) { struct interface *i; @@ -326,16 +335,21 @@ struct in_addr *iface_n_bcast(int n) an appropriate interface they return the requested field of the first known interface. */ -struct in_addr *iface_ip(struct in_addr ip) +struct ipv4_addr *iface_ip(struct ipv4_addr ip) { - struct interface *i = iface_find(ip, True); + struct in_addr in; + struct interface *i; + in.s_addr = ip.s_addr; + i = iface_find(in, True); return(i ? &i->ip : &local_interfaces->ip); } /* return True if a IP is directly reachable on one of our interfaces */ -BOOL iface_local(struct in_addr ip) +BOOL iface_local(struct ipv4_addr ip) { - return iface_find(ip, True) ? True : False; + struct in_addr in; + in.s_addr = ip.s_addr; + return iface_find(in, True) ? True : False; } diff --git a/source4/lib/interfaces.c b/source4/lib/netif/netif.c similarity index 97% rename from source4/lib/interfaces.c rename to source4/lib/netif/netif.c index 89ed144eec1..729aeedbe3a 100644 --- a/source4/lib/interfaces.c +++ b/source4/lib/netif/netif.c @@ -33,23 +33,18 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include -#ifdef AUTOCONF_TEST -struct iface_struct { - char name[16]; - struct in_addr ip; - struct in_addr netmask; -}; -#else +#ifndef AUTOCONF_TEST +#include "lib/netif/netif.h" #include "config.h" -#include "interfaces.h" #endif #ifdef HAVE_SYS_TIME_H @@ -386,8 +381,6 @@ int get_interfaces(struct iface_struct *ifaces, int max_interfaces) #ifdef AUTOCONF_TEST /* this is the autoconf driver to test get_interfaces() */ -#define MAX_INTERFACES 128 - int main() { struct iface_struct ifaces[MAX_INTERFACES]; diff --git a/source4/lib/netif/netif.h b/source4/lib/netif/netif.h new file mode 100644 index 00000000000..d25294f8c22 --- /dev/null +++ b/source4/lib/netif/netif.h @@ -0,0 +1,34 @@ +/* + Unix SMB/CIFS implementation. + + structures for lib/netif/ + + Copyright (C) Andrew Tridgell 2004 + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include + +struct iface_struct { + char name[16]; + struct in_addr ip; + struct in_addr netmask; +}; + +#define MAX_INTERFACES 128 + diff --git a/source4/lib/replace.c b/source4/lib/replace.c index c23c65c8c81..28c60130f87 100644 --- a/source4/lib/replace.c +++ b/source4/lib/replace.c @@ -326,7 +326,7 @@ duplicate a string #ifndef WITH_PTHREADS /* REWRITE: not thread safe */ #ifdef REPLACE_INET_NTOA -char *rep_inet_ntoa(struct in_addr ip) +char *rep_inet_ntoa(struct ipv4_addr ip) { uint8_t *p = (uint8_t *)&ip.s_addr; static char buf[18]; diff --git a/source4/lib/socket/access.c b/source4/lib/socket/access.c index f33f8d56b10..f5093177ddd 100644 --- a/source4/lib/socket/access.c +++ b/source4/lib/socket/access.c @@ -32,6 +32,7 @@ */ #include "includes.h" +#include "system/network.h" #define FAIL (-1) #define ALLONES ((uint32_t)0xFFFFFFFF) diff --git a/source4/lib/socket/socket_ipv4.c b/source4/lib/socket/socket_ipv4.c index f9318a29bb5..9777705419a 100644 --- a/source4/lib/socket/socket_ipv4.c +++ b/source4/lib/socket/socket_ipv4.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "system/network.h" static NTSTATUS ipv4_tcp_init(struct socket_context *sock) { @@ -41,8 +42,8 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock, uint32_t flags) { struct sockaddr_in srv_addr; - struct in_addr my_ip; - struct in_addr srv_ip; + struct ipv4_addr my_ip; + struct ipv4_addr srv_ip; int ret; my_ip = interpret_addr2(my_address); @@ -53,7 +54,7 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock, #ifdef HAVE_SOCK_SIN_LEN my_addr.sin_len = sizeof(my_addr); #endif - my_addr.sin_addr = my_ip; + my_addr.sin_addr.s_addr = my_ip.s_addr; my_addr.sin_port = htons(my_port); my_addr.sin_family = PF_INET; @@ -69,7 +70,7 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock, #ifdef HAVE_SOCK_SIN_LEN srv_addr.sin_len = sizeof(srv_addr); #endif - srv_addr.sin_addr = srv_ip; + srv_addr.sin_addr.s_addr= srv_ip.s_addr; srv_addr.sin_port = htons(srv_port); srv_addr.sin_family = PF_INET; @@ -95,7 +96,7 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock, int queue_size, uint32_t flags) { struct sockaddr_in my_addr; - struct in_addr ip_addr; + struct ipv4_addr ip_addr; int ret; ip_addr = interpret_addr2(my_address); @@ -104,7 +105,7 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock, #ifdef HAVE_SOCK_SIN_LEN my_addr.sin_len = sizeof(my_addr); #endif - my_addr.sin_addr = ip_addr; + my_addr.sin_addr.s_addr = ip_addr.s_addr; my_addr.sin_port = htons(port); my_addr.sin_family = PF_INET; diff --git a/source4/lib/socket/socket_ipv6.c b/source4/lib/socket/socket_ipv6.c index 268212dccab..75e6fcab5c6 100644 --- a/source4/lib/socket/socket_ipv6.c +++ b/source4/lib/socket/socket_ipv6.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" static struct in6_addr interpret_addr6(const char *name) { diff --git a/source4/lib/system.c b/source4/lib/system.c index 1407e7474e1..2baa412622e 100644 --- a/source4/lib/system.c +++ b/source4/lib/system.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" /* The idea is that this file will eventually have wrappers around all @@ -533,3 +534,24 @@ int sys_dup2(int oldfd, int newfd) #endif } + +const char *sys_inet_ntoa(struct ipv4_addr in) +{ + struct in_addr in2; + in2.s_addr = in.s_addr; + return inet_ntoa(in2); +} + +uint32_t sys_inet_addr(const char *s) +{ + return inet_addr(s); +} + +struct ipv4_addr sys_inet_makeaddr(int net, int host) +{ + struct in_addr in; + struct ipv4_addr in2; + in = inet_makeaddr(net, host); + in2.s_addr = in.s_addr; + return in2; +} diff --git a/source4/lib/util.c b/source4/lib/util.c index 07dc182580e..7b6396fa932 100644 --- a/source4/lib/util.c +++ b/source4/lib/util.c @@ -23,6 +23,7 @@ */ #include "includes.h" +#include "system/network.h" /**************************************************************************n Find a suitable temporary directory. The result should be copied immediately @@ -421,7 +422,7 @@ uint32_t interpret_addr(const char *str) /* if it's in the form of an IP address then get the lib to interpret it */ if (is_ipaddress(str)) { - res = inet_addr(str); + res = sys_inet_addr(str); } else { /* otherwise assume it's a network name of some sort and use sys_gethostbyname */ @@ -446,9 +447,9 @@ uint32_t interpret_addr(const char *str) /******************************************************************* A convenient addition to interpret_addr(). ******************************************************************/ -struct in_addr interpret_addr2(const char *str) +struct ipv4_addr interpret_addr2(const char *str) { - struct in_addr ret; + struct ipv4_addr ret; uint32_t a = interpret_addr(str); ret.s_addr = a; return ret; @@ -458,7 +459,7 @@ struct in_addr interpret_addr2(const char *str) Check if an IP is the 0.0.0.0. ******************************************************************/ -BOOL is_zero_ip(struct in_addr ip) +BOOL is_zero_ip(struct ipv4_addr ip) { uint32_t a; putip((char *)&a,(char *)&ip); @@ -469,9 +470,9 @@ BOOL is_zero_ip(struct in_addr ip) Set an IP to 0.0.0.0. ******************************************************************/ -void zero_ip(struct in_addr *ip) +void zero_ip(struct ipv4_addr *ip) { - *ip = inet_makeaddr(0,0); + *ip = sys_inet_makeaddr(0,0); return; } @@ -480,7 +481,7 @@ void zero_ip(struct in_addr *ip) Are two IPs on the same subnet? ********************************************************************/ -BOOL same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask) +BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) { uint32_t net1,net2,nmask; diff --git a/source4/lib/util_sock.c b/source4/lib/util_sock.c index 0cb23920f1c..dbd71b58b6f 100644 --- a/source4/lib/util_sock.c +++ b/source4/lib/util_sock.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" /**************************************************************************** @@ -156,7 +157,7 @@ void set_socket_options(int fd, const char *options) ****************************************************************************/ ssize_t read_udp_socket(int fd, char *buf, size_t len, - struct in_addr *from_addr, int *from_port) + struct ipv4_addr *from_addr, int *from_port) { ssize_t ret; struct sockaddr_in sock; @@ -169,7 +170,7 @@ ssize_t read_udp_socket(int fd, char *buf, size_t len, } if (from_addr) { - *from_addr = sock.sin_addr; + from_addr->s_addr = sock.sin_addr.s_addr; } if (from_port) { *from_port = ntohs(sock.sin_port); @@ -337,7 +338,7 @@ int open_socket_in( int type, int port, int dlevel, uint32_t socket_addr, BOOL r /**************************************************************************** create an outgoing socket. timeout is in milliseconds. **************************************************************************/ -int open_socket_out(int type, struct in_addr *addr, int port, int timeout) +int open_socket_out(int type, struct ipv4_addr *addr, int port, int timeout) { struct sockaddr_in sock_out; int res,ret; @@ -360,7 +361,7 @@ int open_socket_out(int type, struct in_addr *addr, int port, int timeout) /* set it non-blocking */ set_blocking(res,False); - DEBUG(3,("Connecting to %s at port %d\n",inet_ntoa(*addr),port)); + DEBUG(3,("Connecting to %s at port %d\n", sys_inet_ntoa(*addr),port)); /* and connect it to the destination */ connect_again: @@ -375,7 +376,7 @@ connect_again: if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || errno == EAGAIN)) { - DEBUG(1,("timeout connecting to %s:%d\n",inet_ntoa(*addr),port)); + DEBUG(1,("timeout connecting to %s:%d\n", sys_inet_ntoa(*addr),port)); close(res); return -1; } @@ -389,7 +390,7 @@ connect_again: if (ret < 0) { DEBUG(2,("error connecting to %s:%d (%s)\n", - inet_ntoa(*addr),port,strerror(errno))); + sys_inet_ntoa(*addr),port,strerror(errno))); close(res); return -1; } @@ -408,7 +409,7 @@ int open_udp_socket(const char *host, int port) int type = SOCK_DGRAM; struct sockaddr_in sock_out; int res; - struct in_addr addr; + struct ipv4_addr addr; TALLOC_CTX *mem_ctx; mem_ctx = talloc_init("open_udp_socket"); @@ -442,7 +443,7 @@ int open_udp_socket(const char *host, int port) matchname - determine if host name matches IP address. Used to confirm a hostname lookup to prevent spoof attacks ******************************************************************/ -static BOOL matchname(char *remotehost, struct in_addr addr) +static BOOL matchname(char *remotehost, struct ipv4_addr addr) { struct hostent *hp; int i; @@ -480,7 +481,7 @@ static BOOL matchname(char *remotehost, struct in_addr addr) */ DEBUG(0,("host name/address mismatch: %s != %s\n", - inet_ntoa(addr), hp->h_name)); + sys_inet_ntoa(addr), hp->h_name)); return False; } @@ -492,7 +493,7 @@ char *get_socket_name(TALLOC_CTX *mem_ctx, int fd, BOOL force_lookup) { char *name_buf; struct hostent *hp; - struct in_addr addr; + struct ipv4_addr addr; char *p; /* reverse lookups can be *very* expensive, and in many diff --git a/source4/lib/util_strlist.c b/source4/lib/util_strlist.c index 12fb0946e2d..0b32955ac20 100644 --- a/source4/lib/util_strlist.c +++ b/source4/lib/util_strlist.c @@ -228,7 +228,7 @@ BOOL str_list_substitute(char **list, const char *pattern, const char *insert) * reallocated to new length **/ -char* ipstr_list_add(char** ipstr_list, const struct in_addr *ip) +char* ipstr_list_add(char** ipstr_list, const struct ipv4_addr *ip) { char* new_ipstr = NULL; @@ -237,10 +237,10 @@ char* ipstr_list_add(char** ipstr_list, const struct in_addr *ip) /* attempt to convert ip to a string and append colon separator to it */ if (*ipstr_list) { - asprintf(&new_ipstr, "%s%s%s", *ipstr_list, IPSTR_LIST_SEP,inet_ntoa(*ip)); + asprintf(&new_ipstr, "%s%s%s", *ipstr_list, IPSTR_LIST_SEP,sys_inet_ntoa(*ip)); SAFE_FREE(*ipstr_list); } else { - asprintf(&new_ipstr, "%s", inet_ntoa(*ip)); + asprintf(&new_ipstr, "%s", sys_inet_ntoa(*ip)); } *ipstr_list = new_ipstr; return *ipstr_list; @@ -256,7 +256,7 @@ char* ipstr_list_add(char** ipstr_list, const struct in_addr *ip) * @return pointer to allocated ip string **/ -char* ipstr_list_make(char** ipstr_list, const struct in_addr* ip_list, int ip_count) +char* ipstr_list_make(char** ipstr_list, const struct ipv4_addr* ip_list, int ip_count) { int i; @@ -283,7 +283,7 @@ char* ipstr_list_make(char** ipstr_list, const struct in_addr* ip_list, int ip_c * @return number of succesfully parsed addresses **/ -int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list) +int ipstr_list_parse(const char* ipstr_list, struct ipv4_addr** ip_list) { fstring token_str; int count; @@ -294,14 +294,14 @@ int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list) next_token(&ipstr_list, token_str, IPSTR_LIST_SEP, FSTRING_LEN); count++) { - struct in_addr addr; + struct ipv4_addr addr; /* convert single token to ip address */ - if ( (addr.s_addr = inet_addr(token_str)) == INADDR_NONE ) + if ( (addr.s_addr = sys_inet_addr(token_str)) == INADDR_NONE ) break; /* prepare place for another in_addr structure */ - *ip_list = Realloc(*ip_list, (count + 1) * sizeof(struct in_addr)); + *ip_list = Realloc(*ip_list, (count + 1) * sizeof(struct ipv4_addr)); if (!*ip_list) return -1; (*ip_list)[count] = addr; diff --git a/source4/lib/wins_srv.c b/source4/lib/wins_srv.c index eb7f280e6f2..d8be9e61d6a 100644 --- a/source4/lib/wins_srv.c +++ b/source4/lib/wins_srv.c @@ -68,12 +68,12 @@ #define WINS_SRV_FMT "WINS_SRV_DEAD/%s,%s" /* wins_ip,src_ip */ -static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip) +static char *wins_srv_keystr(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr; - if (asprintf(&keystr, WINS_SRV_FMT, inet_ntoa(wins_ip), - inet_ntoa(src_ip)) == -1) { + if (asprintf(&keystr, WINS_SRV_FMT, sys_inet_ntoa(wins_ip), + sys_inet_ntoa(src_ip)) == -1) { DEBUG(0, ("wins_srv_is_dead: malloc error\n")); return NULL; } @@ -85,7 +85,7 @@ static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip) see if an ip is on the dead list */ -BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) +BOOL wins_srv_is_dead(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr = wins_srv_keystr(wins_ip, src_ip); BOOL result; @@ -95,7 +95,7 @@ BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) result = gencache_get(keystr, NULL, NULL); SAFE_FREE(keystr); - DEBUG(4, ("wins_srv_is_dead: %s is %s\n", inet_ntoa(wins_ip), + DEBUG(4, ("wins_srv_is_dead: %s is %s\n", sys_inet_ntoa(wins_ip), result ? "dead" : "alive")); return result; @@ -105,7 +105,7 @@ BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) /* mark a wins server as being alive (for the moment) */ -void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip) +void wins_srv_alive(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr = wins_srv_keystr(wins_ip, src_ip); @@ -113,13 +113,13 @@ void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip) SAFE_FREE(keystr); DEBUG(4, ("wins_srv_alive: marking wins server %s alive\n", - inet_ntoa(wins_ip))); + sys_inet_ntoa(wins_ip))); } /* mark a wins server as temporarily dead */ -void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip) +void wins_srv_died(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr; @@ -133,7 +133,7 @@ void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip) SAFE_FREE(keystr); DEBUG(4,("Marking wins server %s dead for %u seconds from source %s\n", - inet_ntoa(wins_ip), DEATH_TIME, inet_ntoa(src_ip))); + sys_inet_ntoa(wins_ip), DEATH_TIME, sys_inet_ntoa(src_ip))); } /* @@ -160,7 +160,7 @@ uint_t wins_srv_count(void) attached */ struct tagged_ip { fstring tag; - struct in_addr ip; + struct ipv4_addr ip; }; /* @@ -267,7 +267,7 @@ void wins_srv_tags_free(char **list) return the IP of the currently active wins server for the given tag, or the zero IP otherwise */ -struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) +struct ipv4_addr wins_srv_ip_tag(const char *tag, struct ipv4_addr src_ip) { const char **list; int i; @@ -276,13 +276,13 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) /* if we are a wins server then we always just talk to ourselves */ if (lp_wins_support()) { - extern struct in_addr loopback_ip; + extern struct ipv4_addr loopback_ip; return loopback_ip; } list = lp_wins_server_list(); if (!list || !list[0]) { - struct in_addr ip; + struct ipv4_addr ip; zero_ip(&ip); return ip; } @@ -297,11 +297,11 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) } if (!wins_srv_is_dead(t_ip.ip, src_ip)) { char *src_name; - src_name = talloc_strdup(mem_ctx, inet_ntoa(src_ip)); + src_name = talloc_strdup(mem_ctx, sys_inet_ntoa(src_ip)); DEBUG(6,("Current wins server for tag '%s' with source %s is %s\n", tag, src_name, - inet_ntoa(t_ip.ip))); + sys_inet_ntoa(t_ip.ip))); goto exit; } } diff --git a/source4/libcli/auth/clikrb5.c b/source4/libcli/auth/clikrb5.c index c3ea33aaeca..6f17bddfa08 100644 --- a/source4/libcli/auth/clikrb5.c +++ b/source4/libcli/auth/clikrb5.c @@ -20,6 +20,8 @@ */ #include "includes.h" +#include "system/network.h" +#include "system/kerberos.h" #ifdef HAVE_KRB5 diff --git a/source4/libcli/auth/gensec_krb5.c b/source4/libcli/auth/gensec_krb5.c index 95cc6bacbe6..f393ce09c15 100644 --- a/source4/libcli/auth/gensec_krb5.c +++ b/source4/libcli/auth/gensec_krb5.c @@ -24,6 +24,8 @@ */ #include "includes.h" +#include "system/kerberos.h" +#include "libcli/auth/kerberos.h" #include "librpc/gen_ndr/ndr_krb5pac.h" #undef DBGC_CLASS diff --git a/source4/libcli/auth/kerberos.c b/source4/libcli/auth/kerberos.c index b08c7f505c2..06e89d4d337 100644 --- a/source4/libcli/auth/kerberos.c +++ b/source4/libcli/auth/kerberos.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "system/kerberos.h" #ifdef HAVE_KRB5 diff --git a/source4/libcli/auth/kerberos_verify.c b/source4/libcli/auth/kerberos_verify.c index 8d050182f9a..8e598e2a664 100644 --- a/source4/libcli/auth/kerberos_verify.c +++ b/source4/libcli/auth/kerberos_verify.c @@ -23,6 +23,8 @@ */ #include "includes.h" +#include "system/kerberos.h" +#include "libcli/auth/kerberos.h" #ifdef HAVE_KRB5 diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c index c3bc43aa8cf..2949633b86c 100644 --- a/source4/libcli/cliconnect.c +++ b/source4/libcli/cliconnect.c @@ -154,7 +154,7 @@ NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_state **ret_cli, const char *myname, const char *host, - struct in_addr *ip, + struct ipv4_addr *ip, const char *sharename, const char *devtype, const char *username, diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c index 6e182c38432..1eb7888d413 100644 --- a/source4/libcli/ldap/ldap.c +++ b/source4/libcli/ldap/ldap.c @@ -24,6 +24,7 @@ */ #include "includes.h" +#include "system/network.h" /**************************************************************************** * @@ -1272,7 +1273,7 @@ struct ldap_connection *new_ldap_connection(void) BOOL ldap_connect(struct ldap_connection *conn, const char *url) { struct hostent *hp; - struct in_addr ip; + struct ipv4_addr ip; if (!ldap_parse_basic_url(conn->mem_ctx, url, &conn->host, &conn->port, &conn->ldaps)) diff --git a/source4/libcli/namecache.c b/source4/libcli/namecache.c index 9f4796af1a8..8a4dab75229 100644 --- a/source4/libcli/namecache.c +++ b/source4/libcli/namecache.c @@ -113,7 +113,7 @@ static char* namecache_key(TALLOC_CTX *mem_ctx, const char *name, int name_type) **/ BOOL namecache_store(TALLOC_CTX *mem_ctx, const char *name, int name_type, - int num_names, struct in_addr *ip_list) + int num_names, struct ipv4_addr *ip_list) { time_t expiry; char *key, *value_string; @@ -129,7 +129,7 @@ BOOL namecache_store(TALLOC_CTX *mem_ctx, const char *name, int name_type, num_names, num_names == 1 ? "": "es", name, name_type)); for (i = 0; i < num_names; i++) - DEBUGADD(5, ("%s%s", inet_ntoa(ip_list[i]), + DEBUGADD(5, ("%s%s", sys_inet_ntoa(ip_list[i]), i == (num_names - 1) ? "" : ", ")); DEBUGADD(5, ("\n")); @@ -172,7 +172,7 @@ BOOL namecache_store(TALLOC_CTX *mem_ctx, const char *name, int name_type, * false if name isn't found in the cache or has expired **/ -BOOL namecache_fetch(TALLOC_CTX *mem_ctx, const char *name, int name_type, struct in_addr **ip_list, +BOOL namecache_fetch(TALLOC_CTX *mem_ctx, const char *name, int name_type, struct ipv4_addr **ip_list, int *num_names) { char *key, *value; diff --git a/source4/libcli/namequery.c b/source4/libcli/namequery.c index a9464718c52..7a2d6977971 100644 --- a/source4/libcli/namequery.c +++ b/source4/libcli/namequery.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" /* A netbios node status array element. */ struct node_status { @@ -83,7 +84,7 @@ do a NBT node status query on an open socket and return an array of structures holding the returned names or NULL if the query failed **************************************************************************/ struct node_status *node_status_query(int fd,struct nmb_name *name, - struct in_addr to_ip, int *num_names) + struct ipv4_addr to_ip, int *num_names) { BOOL found=False; int retries = 2; @@ -170,7 +171,7 @@ a servers name given its IP return the matched name in *name **************************************************************************/ -BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr to_ip, char *name) +BOOL name_status_find(const char *q_name, int q_type, int type, struct ipv4_addr to_ip, char *name) { struct node_status *status = NULL; struct nmb_name nname; @@ -184,7 +185,7 @@ BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr t } DEBUG(10, ("name_status_find: looking up %s#%02x at %s\n", q_name, - q_type, inet_ntoa(to_ip))); + q_type, sys_inet_ntoa(to_ip))); sock = open_socket_in(SOCK_DGRAM, 0, 3, interpret_addr(lp_socket_address()), True); if (sock == -1) @@ -213,7 +214,7 @@ BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr t DEBUG(10, ("name_status_find: name %sfound", result ? "" : "not ")); if (result) - DEBUGADD(10, (", ip address is %s", inet_ntoa(to_ip))); + DEBUGADD(10, (", ip address is %s", sys_inet_ntoa(to_ip))); DEBUG(10, ("\n")); @@ -224,14 +225,14 @@ BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr t /* comparison function used by sort_ip_list */ -int ip_compare(struct in_addr *ip1, struct in_addr *ip2) +int ip_compare(struct ipv4_addr *ip1, struct ipv4_addr *ip2) { int max_bits1=0, max_bits2=0; int num_interfaces = iface_count(); int i; for (i=0;is_addr, (uint8_t *)&ip.s_addr); @@ -256,13 +257,13 @@ int ip_compare(struct in_addr *ip1, struct in_addr *ip2) are at the top. This prevents the problem where a WINS server returns an IP that is not reachable from our subnet as the first match */ -static void sort_ip_list(struct in_addr *iplist, int count) +static void sort_ip_list(struct ipv4_addr *iplist, int count) { if (count <= 1) { return; } - qsort(iplist, count, sizeof(struct in_addr), QSORT_CAST ip_compare); + qsort(iplist, count, sizeof(struct ipv4_addr), QSORT_CAST ip_compare); } @@ -272,9 +273,9 @@ static void sort_ip_list(struct in_addr *iplist, int count) *count will be set to the number of addresses returned. *timed_out is set if we failed by timing out ****************************************************************************/ -struct in_addr *name_query(int fd,const char *name,int name_type, +struct ipv4_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOOL recurse, - struct in_addr to_ip, int *count, int *flags, + struct ipv4_addr to_ip, int *count, int *flags, BOOL *timed_out) { BOOL found=False; @@ -284,7 +285,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, struct packet_struct p; struct packet_struct *p2; struct nmb_packet *nmb = &p.packet.nmb; - struct in_addr *ip_list = NULL; + struct ipv4_addr *ip_list = NULL; if (lp_disable_netbios()) { DEBUG(5,("name_query(%s#%02x): netbios is disabled\n", name, name_type)); @@ -333,7 +334,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, while (1) { struct timeval tval2; - struct in_addr *tmp_ip_list; + struct ipv4_addr *tmp_ip_list; GetTimeOfDay(&tval2); if (TvalDiff(&tval,&tval2) > retry_time) { @@ -398,7 +399,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, continue; } - tmp_ip_list = (struct in_addr *)Realloc( ip_list, sizeof( ip_list[0] ) + tmp_ip_list = (struct ipv4_addr *)Realloc( ip_list, sizeof( ip_list[0] ) * ( (*count) + nmb2->answers->rdlength/6 ) ); if (!tmp_ip_list) { @@ -409,10 +410,10 @@ struct in_addr *name_query(int fd,const char *name,int name_type, ip_list = tmp_ip_list; if (ip_list) { - DEBUG(2,("Got a positive name query response from %s ( ", inet_ntoa(p2->ip))); + DEBUG(2,("Got a positive name query response from %s ( ", sys_inet_ntoa(p2->ip))); for (i=0;ianswers->rdlength/6;i++) { putip((char *)&ip_list[(*count)],&nmb2->answers->rdata[2+i*6]); - DEBUGADD(2,("%s ",inet_ntoa(ip_list[(*count)]))); + DEBUGADD(2,("%s ",sys_inet_ntoa(ip_list[(*count)]))); (*count)++; } DEBUGADD(2,(")\n")); @@ -474,7 +475,7 @@ XFILE *startlmhosts(char *fname) *********************************************************/ BOOL getlmhostsent( TALLOC_CTX *mem_ctx, - XFILE *fp, pstring name, int *name_type, struct in_addr *ipaddr) + XFILE *fp, pstring name, int *name_type, struct ipv4_addr *ipaddr) { pstring line; @@ -571,7 +572,7 @@ void endlmhosts(XFILE *fp) *********************************************************/ BOOL name_resolve_bcast(const char *name, int name_type, - struct in_addr **return_ip_list, int *return_count) + struct ipv4_addr **return_ip_list, int *return_count) { int sock, i; int num_interfaces = iface_count(); @@ -601,7 +602,7 @@ BOOL name_resolve_bcast(const char *name, int name_type, * the first successful match. */ for( i = num_interfaces-1; i >= 0; i--) { - struct in_addr sendto_ip; + struct ipv4_addr sendto_ip; int flags; /* Done this way to fix compiler error on IRIX 5.x */ sendto_ip = *iface_n_bcast(i); @@ -621,11 +622,11 @@ BOOL name_resolve_bcast(const char *name, int name_type, Resolve via "wins" method. *********************************************************/ BOOL resolve_wins(TALLOC_CTX *mem_ctx, const char *name, int name_type, - struct in_addr **return_iplist, int *return_count) + struct ipv4_addr **return_iplist, int *return_count) { int sock, t, i; char **wins_tags; - struct in_addr src_ip; + struct ipv4_addr src_ip; if (lp_disable_netbios()) { DEBUG(5,("resolve_wins(%s#%02x): netbios is disabled\n", name, name_type)); @@ -658,7 +659,7 @@ BOOL resolve_wins(TALLOC_CTX *mem_ctx, const char *name, int name_type, for (t=0; wins_tags && wins_tags[t]; t++) { int srv_count = wins_srv_count_tag(wins_tags[t]); for (i=0; i\n", name)); if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) { - struct in_addr return_ip; + struct ipv4_addr return_ip; putip((char *)&return_ip,(char *)hp->h_addr); - *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr)); + *return_iplist = (struct ipv4_addr *)malloc(sizeof(struct ipv4_addr)); if(*return_iplist == NULL) { DEBUG(3,("resolve_hosts: malloc fail !\n")); return False; @@ -749,7 +750,7 @@ static BOOL resolve_hosts(const char *name, *********************************************************/ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int name_type, - struct in_addr **return_iplist, int *return_count) + struct ipv4_addr **return_iplist, int *return_count) { char *name_resolve_list; fstring tok; @@ -758,7 +759,7 @@ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int nam BOOL allzeros = (strcmp(name,"0.0.0.0") == 0); BOOL is_address = is_ipaddress(name); BOOL result = False; - struct in_addr *nodupes_iplist; + struct ipv4_addr *nodupes_iplist; int i; *return_iplist = NULL; @@ -767,7 +768,7 @@ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int nam DEBUG(10, ("internal_resolve_name: looking up %s#%x\n", name, name_type)); if (allzeros || allones || is_address) { - *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr)); + *return_iplist = (struct ipv4_addr *)malloc(sizeof(struct ipv4_addr)); if(*return_iplist == NULL) { DEBUG(3,("internal_resolve_name: malloc fail !\n")); return False; @@ -841,8 +842,8 @@ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int nam controllers including the PDC in iplist[1..n]. Iterating over the iplist when the PDC is down will cause two sets of timeouts. */ - if (*return_count && (nodupes_iplist = (struct in_addr *) - malloc(sizeof(struct in_addr) * (*return_count)))) { + if (*return_count && (nodupes_iplist = (struct ipv4_addr *) + malloc(sizeof(struct ipv4_addr) * (*return_count)))) { int nodupes_count = 0; /* Iterate over return_iplist looking for duplicates */ @@ -879,7 +880,7 @@ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int nam /* Save in name cache */ for (i = 0; i < *return_count && DEBUGLEVEL == 100; i++) DEBUG(100, ("Storing name %s of type %d (ip: %s)\n", name, - name_type, inet_ntoa((*return_iplist)[i]))); + name_type, sys_inet_ntoa((*return_iplist)[i]))); namecache_store(mem_ctx, name, name_type, *return_count, *return_iplist); @@ -889,7 +890,7 @@ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int nam *return_count)); for (i = 0; i < *return_count; i++) - DEBUGADD(10, ("%s ", inet_ntoa((*return_iplist)[i]))); + DEBUGADD(10, ("%s ", sys_inet_ntoa((*return_iplist)[i]))); DEBUG(10, ("\n")); @@ -902,9 +903,9 @@ static BOOL internal_resolve_name(TALLOC_CTX *mem_ctx, const char *name, int nam or host name or NetBIOS name. This uses the name switch in the smb.conf to determine the order of name resolution. *********************************************************/ -BOOL resolve_name(TALLOC_CTX *mem_ctx, const char *name, struct in_addr *return_ip, int name_type) +BOOL resolve_name(TALLOC_CTX *mem_ctx, const char *name, struct ipv4_addr *return_ip, int name_type) { - struct in_addr *ip_list = NULL; + struct ipv4_addr *ip_list = NULL; int count = 0; if (is_ipaddress(name)) { @@ -916,7 +917,7 @@ BOOL resolve_name(TALLOC_CTX *mem_ctx, const char *name, struct in_addr *return_ int i; /* only return valid addresses for TCP connections */ for (i=0; isource_name),nmb_namestr(&dgram2->dest_name), - inet_ntoa(p_ret->ip), smb_buf(buf),SVAL(buf2,0),len)); + sys_inet_ntoa(p_ret->ip), smb_buf(buf),SVAL(buf2,0),len)); if(SVAL(buf2,0) != QUERYFORPDC_R) { DEBUG(0,("lookup_pdc_name: datagram type (%u) != QUERYFORPDC_R(%u)\n", @@ -1175,9 +1176,9 @@ NT GETDC call, UNICODE, NT domain SID and uncle tom cobbley and all... for a domain. *********************************************************/ -BOOL get_pdc_ip(TALLOC_CTX *mem_ctx, const char *domain, struct in_addr *ip) +BOOL get_pdc_ip(TALLOC_CTX *mem_ctx, const char *domain, struct ipv4_addr *ip) { - struct in_addr *ip_list; + struct ipv4_addr *ip_list; int count; int i = 0; @@ -1217,7 +1218,7 @@ BOOL get_pdc_ip(TALLOC_CTX *mem_ctx, const char *domain, struct in_addr *ip) a domain. *********************************************************/ -BOOL get_dc_list(TALLOC_CTX *mem_ctx, const char *domain, struct in_addr **ip_list, int *count, int *ordered) +BOOL get_dc_list(TALLOC_CTX *mem_ctx, const char *domain, struct ipv4_addr **ip_list, int *count, int *ordered) { *ordered = False; @@ -1230,8 +1231,8 @@ BOOL get_dc_list(TALLOC_CTX *mem_ctx, const char *domain, struct in_addr **ip_li fstring name; int num_addresses = 0; int local_count, i, j; - struct in_addr *return_iplist = NULL; - struct in_addr *auto_ip_list = NULL; + struct ipv4_addr *return_iplist = NULL; + struct ipv4_addr *auto_ip_list = NULL; BOOL done_auto_lookup = False; int auto_count = 0; @@ -1266,7 +1267,7 @@ BOOL get_dc_list(TALLOC_CTX *mem_ctx, const char *domain, struct in_addr **ip_li if ( (num_addresses == 0) && !done_auto_lookup ) return internal_resolve_name(mem_ctx, domain, 0x1C, ip_list, count); - return_iplist = (struct in_addr *)malloc(num_addresses * sizeof(struct in_addr)); + return_iplist = (struct ipv4_addr *)malloc(num_addresses * sizeof(struct ipv4_addr)); if (return_iplist == NULL) { DEBUG(3,("get_dc_list: malloc fail !\n")); @@ -1279,7 +1280,7 @@ BOOL get_dc_list(TALLOC_CTX *mem_ctx, const char *domain, struct in_addr **ip_li /* fill in the return list now with real IP's */ while ( (local_count 1) ) { - qsort(ip_list, count, sizeof(struct in_addr), QSORT_CAST ip_compare); + qsort(ip_list, count, sizeof(struct ipv4_addr), QSORT_CAST ip_compare); } for (i = 0; i < count; i++) { diff --git a/source4/libcli/nmblib.c b/source4/libcli/nmblib.c index 5eeec480035..ef5210cf630 100644 --- a/source4/libcli/nmblib.c +++ b/source4/libcli/nmblib.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" static const struct opcode_names { const char *nmb_opcode_name; @@ -102,7 +103,7 @@ void debug_nmb_packet(struct packet_struct *p) if (DEBUGLVL(4)) { DEBUG(4, ("nmb packet from %s(%d) header: id=%d opcode=%s(%d) response=%s\n", - inet_ntoa(p->ip), p->port, + sys_inet_ntoa(p->ip), p->port, nmb->header.name_trn_id, lookup_opcode_name(nmb->header.opcode), nmb->header.opcode, @@ -696,7 +697,7 @@ struct packet_struct *read_packet(int fd,enum packet_type packet_type) struct packet_struct *packet; char buf[MAX_DGRAM_SIZE]; int length; - struct in_addr addr; + struct ipv4_addr addr; int port; length = read_udp_socket(fd, buf, sizeof(buf), &addr, &port); @@ -710,7 +711,7 @@ struct packet_struct *read_packet(int fd,enum packet_type packet_type) packet->port = port; DEBUG(5,("Received a packet of len %d from (%s) port %d\n", - length, inet_ntoa(packet->ip), packet->port)); + length, sys_inet_ntoa(packet->ip), packet->port)); return packet; } @@ -719,7 +720,7 @@ struct packet_struct *read_packet(int fd,enum packet_type packet_type) /******************************************************************* send a udp packet on a already open socket ******************************************************************/ -static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port) +static BOOL send_udp(int fd,char *buf,int len,struct ipv4_addr ip,int port) { BOOL ret = False; int i; @@ -732,7 +733,7 @@ static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port) sock_out.sin_family = AF_INET; DEBUG( 5, ( "Sending a packet of len %d to (%s) on port %d\n", - len, inet_ntoa(ip), port ) ); + len, sys_inet_ntoa(ip), port ) ); /* * Patch to fix asynch error notifications from Linux kernel. @@ -746,7 +747,7 @@ static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port) if (!ret) DEBUG(0,("Packet send failed to %s(%d) ERRNO=%s\n", - inet_ntoa(ip),port,strerror(errno))); + sys_inet_ntoa(ip),port,strerror(errno))); return(ret); } @@ -1069,7 +1070,7 @@ static int name_query_comp(uint8_t *p1, uint8_t *p2) sort a set of 6 byte name query response records so that the IPs that have the most leading bits in common with the specified address come first ***************************************************************************/ -void sort_query_replies(char *data, int n, struct in_addr ip) +void sort_query_replies(char *data, int n, struct ipv4_addr ip) { if (n <= 1) return; diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c641f8bf126..349b4b9a9cc 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -49,7 +49,7 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) connect a smbcli_socket context to an IP/port pair if port is 0 then choose 445 then 139 */ -BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) +BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) { NTSTATUS status; @@ -71,7 +71,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } talloc_steal(sock, sock->sock); - status = socket_connect(sock->sock, NULL, 0, inet_ntoa(*ip), port, 0); + status = socket_connect(sock->sock, NULL, 0, sys_inet_ntoa(*ip), port, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(sock->sock); sock->sock = NULL; @@ -159,7 +159,7 @@ resolve a hostname and connect BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { int name_type = 0x20; - struct in_addr ip; + struct ipv4_addr ip; char *name, *p; BOOL ret; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 48abc82a68e..9bbdd8a222f 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -60,7 +60,7 @@ struct smbcli_negotiate { /* this is the context for a SMB socket associated with the socket itself */ struct smbcli_socket { - struct in_addr dest_ip; + struct ipv4_addr dest_ip; /* dest hostname (which may or may not be a DNS name) */ char *hostname; diff --git a/source4/libnet/libnet_rpc.c b/source4/libnet/libnet_rpc.c index 14f0ba0ad01..48a7f967749 100644 --- a/source4/libnet/libnet_rpc.c +++ b/source4/libnet/libnet_rpc.c @@ -24,7 +24,7 @@ static NTSTATUS libnet_find_pdc_generic(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_find_pdc *r) { BOOL ret; - struct in_addr ip; + struct ipv4_addr ip; if (is_ipaddress(r->generic.in.domain_name)) { r->generic.out.pdc_name = r->generic.in.domain_name; @@ -40,7 +40,7 @@ static NTSTATUS libnet_find_pdc_generic(struct libnet_context *ctx, TALLOC_CTX * } } - r->generic.out.pdc_name = talloc_strdup(mem_ctx, inet_ntoa(ip)); + r->generic.out.pdc_name = talloc_strdup(mem_ctx, sys_inet_ntoa(ip)); return NT_STATUS_OK; } diff --git a/source4/librpc/rpc/dcerpc_util.c b/source4/librpc/rpc/dcerpc_util.c index 55818e28fe4..638b2e1c554 100644 --- a/source4/librpc/rpc/dcerpc_util.c +++ b/source4/librpc/rpc/dcerpc_util.c @@ -22,6 +22,7 @@ */ #include "includes.h" +#include "system/network.h" #include "librpc/gen_ndr/ndr_epmapper.h" /* @@ -385,9 +386,9 @@ const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *flo } { - struct in_addr in; + struct ipv4_addr in; in.s_addr = htonl(floor->rhs.ip.address); - return talloc_strdup(mem_ctx, inet_ntoa(in)); + return talloc_strdup(mem_ctx, sys_inet_ntoa(in)); } case EPM_PROTOCOL_NCACN: diff --git a/source4/rpc_server/dcerpc_sock.c b/source4/rpc_server/dcerpc_sock.c index 508f42d2fba..b131df5de24 100644 --- a/source4/rpc_server/dcerpc_sock.c +++ b/source4/rpc_server/dcerpc_sock.c @@ -123,15 +123,15 @@ static void add_socket_rpc_ncalrpc(struct server_service *service, add a socket address to the list of events, one event per dcerpc endpoint */ static void add_socket_rpc_tcp_iface(struct server_service *service, - const struct model_ops *model_ops, - struct dcesrv_context *dce_ctx, - struct dcesrv_endpoint *e, - struct in_addr *ifip) + const struct model_ops *model_ops, + struct dcesrv_context *dce_ctx, + struct dcesrv_endpoint *e, + struct ipv4_addr *ifip) { struct server_socket *sock; struct dcesrv_socket_context *dcesrv_sock; uint16_t port = 0; - char *ip_str = talloc_strdup(service, inet_ntoa(*ifip)); + char *ip_str = talloc_strdup(service, sys_inet_ntoa(*ifip)); if (e->ep_description.endpoint) port = atoi(e->ep_description.endpoint); @@ -173,14 +173,14 @@ static void add_socket_rpc_tcp(struct server_service *service, int num_interfaces = iface_count(); int i; for(i = 0; i < num_interfaces; i++) { - struct in_addr *ifip = iface_n_ip(i); + struct ipv4_addr *ifip = iface_n_ip(i); if (ifip == NULL) { continue; } add_socket_rpc_tcp_iface(service, model_ops, dce_ctx, e, ifip); } } else { - struct in_addr ifip; + struct ipv4_addr ifip; ifip = interpret_addr2(lp_socket_address()); add_socket_rpc_tcp_iface(service, model_ops, dce_ctx, e, &ifip); } diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index de3d60a6bdd..a1a90852a18 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -728,11 +728,11 @@ static void smbsrv_exit(struct server_service *service, const char *reason) static void add_socket(struct server_service *service, const struct model_ops *model_ops, struct socket_context *socket_ctx, - struct in_addr *ifip) + struct ipv4_addr *ifip) { const char **ports = lp_smb_ports(); int i; - char *ip_str = talloc_strdup(service, inet_ntoa(*ifip)); + char *ip_str = talloc_strdup(service, sys_inet_ntoa(*ifip)); for (i=0;ports[i];i++) { uint16_t port = atoi(ports[i]); @@ -759,7 +759,7 @@ static void smbsrv_init(struct server_service *service, const struct model_ops * socket per interface and bind to only these. */ for(i = 0; i < num_interfaces; i++) { - struct in_addr *ifip = iface_n_ip(i); + struct ipv4_addr *ifip = iface_n_ip(i); if (ifip == NULL) { DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i)); @@ -769,7 +769,7 @@ static void smbsrv_init(struct server_service *service, const struct model_ops * add_socket(service, model_ops, NULL, ifip); } } else { - struct in_addr ifip; + struct ipv4_addr ifip; /* Just bind to lp_socket_address() (usually 0.0.0.0) */ ifip = interpret_addr2(lp_socket_address()); add_socket(service, model_ops, NULL, &ifip); diff --git a/source4/torture/rpc/epmapper.c b/source4/torture/rpc/epmapper.c index fa0199a3c60..78721d075e0 100644 --- a/source4/torture/rpc/epmapper.c +++ b/source4/torture/rpc/epmapper.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" #include "librpc/gen_ndr/ndr_epmapper.h" @@ -64,9 +65,9 @@ static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr) case EPM_PROTOCOL_IP: printf(" IP:"); { - struct in_addr in; + struct ipv4_addr in; in.s_addr = htonl(rhs->ip.address); - printf("%s", inet_ntoa(in)); + printf("%s", sys_inet_ntoa(in)); } break; diff --git a/source4/utils/nmblookup.c b/source4/utils/nmblookup.c index 8c9eccf424e..2ef1470ee42 100644 --- a/source4/utils/nmblookup.c +++ b/source4/utils/nmblookup.c @@ -26,7 +26,7 @@ extern BOOL AllowDebugChange; static BOOL give_flags = False; static BOOL use_bcast = True; static BOOL got_bcast = False; -static struct in_addr bcast_addr; +static struct ipv4_addr bcast_addr; static BOOL recursion_desired = False; static BOOL translate_addresses = False; static int ServerFD= -1; @@ -119,7 +119,7 @@ static char *query_flags(int flags) /**************************************************************************** do a node status query ****************************************************************************/ -static void do_node_status(int fd, const char *name, int type, struct in_addr ip) +static void do_node_status(int fd, const char *name, int type, struct ipv4_addr ip) { struct nmb_name nname; int count, i, j; @@ -151,7 +151,7 @@ send out one query static BOOL query_one(const char *lookup, uint_t lookup_type) { int j, count, flags = 0; - struct in_addr *ip_list=NULL; + struct ipv4_addr *ip_list=NULL; if (got_bcast) { d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); @@ -159,7 +159,7 @@ static BOOL query_one(const char *lookup, uint_t lookup_type) use_bcast?True:recursion_desired, bcast_addr,&count, &flags, NULL); } else { - struct in_addr *bcast; + struct ipv4_addr *bcast; for (j=iface_count() - 1; !ip_list && j >= 0; j--) { @@ -299,7 +299,7 @@ int main(int argc,char *argv[]) for (i=optind;i