{
struct smbcli_state *cli = NULL;
fstring desthost;
- struct ipv4_addr dest_ip;
+ struct in_addr dest_ip;
const char *p;
char *pserver;
bool connected_ok = false;
char * share;
char * ipaddress_string = NULL;
struct hostent * host_entry;
- struct ipv4_addr server_ipaddr;
+ struct in_addr server_ipaddr;
int rc,j;
char temp[64];
static pstring service;
static pstring options;
-static struct ipv4_addr dest_ip;
+static struct in_addr dest_ip;
static bool have_ip;
static int smb_port = 0;
static bool got_user;
struct smbcli_state *c;
struct nmb_name called, calling;
char *server_n;
- struct ipv4_addr ip;
+ struct in_addr ip;
pstring server;
char *share;
struct ldb_dn *dn;
};
+enum ldb_sequence_type {
+ LDB_SEQ_HIGHEST_SEQ,
+ LDB_SEQ_HIGHEST_TIMESTAMP,
+ LDB_SEQ_NEXT
+};
+
struct ldb_sequence_number {
- enum ldb_sequence_type {
- LDB_SEQ_HIGHEST_SEQ,
- LDB_SEQ_HIGHEST_TIMESTAMP,
- LDB_SEQ_NEXT
- } type;
+ enum ldb_sequence_type type;
uint64_t seq_num;
uint32_t flags;
};
int type;
time_t ttl;
uint32_t ip_count;
- struct ipv4_addr *ips;
+ struct in_addr *ips;
};
struct samba3_policy
#include "includes.h"
#include "system/filesys.h"
#include "lib/samba3/samba3.h"
+#include "system/network.h"
#define WINS_VERSION 1
}
/* Allocate the space for the ip_list. */
- if((entry.ips = talloc_array ( ctx, struct ipv4_addr, entry.ip_count)) == NULL) {
+ if((entry.ips = talloc_array ( ctx, struct in_addr, entry.ip_count)) == NULL) {
DEBUG(0,("initialise_wins: Malloc fail !\n"));
SAFE_FREE(line);
return NT_STATUS_NO_MEMORY;
/** used for network interfaces */
struct interface {
struct interface *next, *prev;
- struct ipv4_addr ip;
- struct ipv4_addr nmask;
+ struct in_addr ip;
+ struct in_addr nmask;
const char *ip_s;
const char *bcast_s;
const char *nmask_s;
#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.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(tov4(ip))) return local_interfaces;
+ if (is_zero_ip(ip)) return local_interfaces;
for (i=local_interfaces;i;i=i->next)
if (CheckMask) {
- if (same_net(i->ip,tov4(ip),i->nmask)) return i;
- } else if (i->ip.addr == ip.s_addr) return i;
+ if (same_net(i->ip,ip,i->nmask)) return i;
+ } else if (i->ip.s_addr == ip.s_addr) return i;
return NULL;
}
static void add_interface(struct in_addr ip, struct in_addr nmask)
{
struct interface *iface;
- struct ipv4_addr bcast;
+ struct in_addr bcast;
if (iface_find(ip, false)) {
DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip)));
ZERO_STRUCTPN(iface);
- iface->ip = tov4(ip);
- iface->nmask = tov4(nmask);
- bcast.addr = MKBCADDR(iface->ip.addr, iface->nmask.addr);
+ iface->ip = ip;
+ iface->nmask = nmask;
+ bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr);
/* keep string versions too, to avoid people tripping over the implied
- static in sys_inet_ntoa() */
- iface->ip_s = talloc_strdup(iface, sys_inet_ntoa(iface->ip));
- iface->nmask_s = talloc_strdup(iface, sys_inet_ntoa(iface->nmask));
+ static in inet_ntoa() */
+ iface->ip_s = talloc_strdup(iface, inet_ntoa(iface->ip));
+ iface->nmask_s = talloc_strdup(iface, inet_ntoa(iface->nmask));
if (nmask.s_addr != ~0) {
- iface->bcast_s = talloc_strdup(iface, sys_inet_ntoa(bcast));
+ iface->bcast_s = talloc_strdup(iface, inet_ntoa(bcast));
}
DLIST_ADD_END(local_interfaces, iface, struct interface *);
if (strpbrk(token, "*?") != NULL) {
return;
}
- ip.s_addr = interpret_addr2(token).addr;
+ ip.s_addr = interpret_addr2(token).s_addr;
for (i=0;i<total_probed;i++) {
if (ip.s_addr == probed_ifaces[i].ip.s_addr) {
add_interface(probed_ifaces[i].ip,
/* parse it into an IP address/netmasklength pair */
*p++ = 0;
- ip.s_addr = interpret_addr2(token).addr;
+ ip.s_addr = interpret_addr2(token).s_addr;
if (strlen(p) > 2) {
- nmask.s_addr = interpret_addr2(p).addr;
+ nmask.s_addr = interpret_addr2(p).s_addr;
} else {
nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES));
}
if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) ||
ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) {
for (i=0;i<total_probed;i++) {
- if (same_net(tov4(ip), tov4(probed_ifaces[i].ip), tov4(nmask))) {
+ if (same_net(ip, probed_ifaces[i].ip, nmask)) {
add_interface(probed_ifaces[i].ip, nmask);
return;
}
const char **ptr;
int i;
struct iface_struct ifaces[MAX_INTERFACES];
- struct ipv4_addr loopback_ip;
+ struct in_addr loopback_ip;
int total_probed;
if (local_interfaces != NULL) {
DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n"));
}
for (i=0;i<total_probed;i++) {
- if (ifaces[i].ip.s_addr != loopback_ip.addr) {
+ if (ifaces[i].ip.s_addr != loopback_ip.s_addr) {
add_interface(ifaces[i].ip,
ifaces[i].netmask);
}
uint32_t flags)
{
struct sockaddr_in srv_addr;
- struct ipv4_addr my_ip;
- struct ipv4_addr srv_ip;
+ struct in_addr my_ip;
+ struct in_addr srv_ip;
int ret;
if (my_address && my_address->sockaddr) {
} else if (my_address) {
my_ip = interpret_addr2(my_address->addr);
- if (my_ip.addr != 0 || my_address->port != 0) {
+ if (my_ip.s_addr != 0 || my_address->port != 0) {
struct sockaddr_in my_addr;
ZERO_STRUCT(my_addr);
#ifdef HAVE_SOCK_SIN_LEN
my_addr.sin_len = sizeof(my_addr);
#endif
- my_addr.sin_addr.s_addr = my_ip.addr;
+ my_addr.sin_addr.s_addr = my_ip.s_addr;
my_addr.sin_port = htons(my_address->port);
my_addr.sin_family = PF_INET;
}
} else {
srv_ip = interpret_addr2(srv_address->addr);
- if (!srv_ip.addr) {
+ if (!srv_ip.s_addr) {
return NT_STATUS_BAD_NETWORK_NAME;
}
#ifdef HAVE_SOCK_SIN_LEN
srv_addr.sin_len = sizeof(srv_addr);
#endif
- srv_addr.sin_addr.s_addr= srv_ip.addr;
+ srv_addr.sin_addr.s_addr= srv_ip.s_addr;
srv_addr.sin_port = htons(srv_address->port);
srv_addr.sin_family = PF_INET;
int queue_size, uint32_t flags)
{
struct sockaddr_in my_addr;
- struct ipv4_addr ip_addr;
+ struct in_addr ip_addr;
int ret;
socket_set_option(sock, "SO_REUSEADDR=1", NULL);
#ifdef HAVE_SOCK_SIN_LEN
my_addr.sin_len = sizeof(my_addr);
#endif
- my_addr.sin_addr.s_addr = ip_addr.addr;
+ my_addr.sin_addr.s_addr = ip_addr.s_addr;
my_addr.sin_port = htons(my_address->port);
my_addr.sin_family = PF_INET;
dest_addr->sockaddr, dest_addr->sockaddrlen);
} else {
struct sockaddr_in srv_addr;
- struct ipv4_addr addr;
+ struct in_addr addr;
ZERO_STRUCT(srv_addr);
#ifdef HAVE_SOCK_SIN_LEN
srv_addr.sin_len = sizeof(srv_addr);
#endif
addr = interpret_addr2(dest_addr->addr);
- if (addr.addr == 0) {
+ if (addr.s_addr == 0) {
return NT_STATUS_HOST_UNREACHABLE;
}
- srv_addr.sin_addr.s_addr = addr.addr;
+ srv_addr.sin_addr.s_addr = addr.s_addr;
srv_addr.sin_port = htons(dest_addr->port);
srv_addr.sin_family = PF_INET;
NTSTATUS tdr_pull_ipv4address(struct tdr_pull *tdr, TALLOC_CTX *ctx,
const char **address)
{
- struct ipv4_addr in;
- TDR_CHECK(tdr_pull_uint32(tdr, ctx, &in.addr));
- in.addr = htonl(in.addr);
- *address = talloc_strdup(tdr, sys_inet_ntoa(in));
+ struct in_addr in;
+ TDR_CHECK(tdr_pull_uint32(tdr, ctx, &in.s_addr));
+ in.s_addr = htonl(in.s_addr);
+ *address = talloc_strdup(tdr, inet_ntoa(in));
NT_STATUS_HAVE_NO_MEMORY(*address);
return NT_STATUS_OK;
}
#endif /* REDUCE_ROOT_DNS_LOOKUPS */
}
-_PUBLIC_ const char *sys_inet_ntoa(struct ipv4_addr in)
-{
- struct in_addr in2;
- in2.s_addr = in.addr;
- return inet_ntoa(in2);
-}
-
-_PUBLIC_ struct ipv4_addr sys_inet_makeaddr(int net, int host)
+_PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host)
{
struct in_addr in;
- struct ipv4_addr in2;
+ struct in_addr in2;
in = inet_makeaddr(net, host);
- in2.addr = in.s_addr;
+ in2.s_addr = in.s_addr;
return in2;
}
/**
A convenient addition to interpret_addr().
**/
-_PUBLIC_ struct ipv4_addr interpret_addr2(const char *str)
+_PUBLIC_ struct in_addr interpret_addr2(const char *str)
{
- struct ipv4_addr ret;
+ struct in_addr ret;
uint32_t a = interpret_addr(str);
- ret.addr = a;
+ ret.s_addr = a;
return ret;
}
Check if an IP is the 0.0.0.0.
**/
-_PUBLIC_ bool is_zero_ip(struct ipv4_addr ip)
+_PUBLIC_ bool is_zero_ip(struct in_addr ip)
{
- return ip.addr == 0;
+ return ip.s_addr == 0;
}
/**
Are two IPs on the same subnet?
**/
-_PUBLIC_ bool same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask)
+_PUBLIC_ bool same_net(struct in_addr ip1, struct in_addr ip2, struct in_addr mask)
{
uint32_t net1,net2,nmask;
- nmask = ntohl(mask.addr);
- net1 = ntohl(ip1.addr);
- net2 = ntohl(ip2.addr);
+ nmask = ntohl(mask.s_addr);
+ net1 = ntohl(ip1.s_addr);
+ net2 = ntohl(ip2.s_addr);
return((net1 & nmask) == (net2 & nmask));
}
/* The following definitions come from lib/util/system.c */
-/*
- we use struct ipv4_addr to avoid having to include all the
- system networking headers everywhere
-*/
-struct ipv4_addr {
- uint32_t addr;
-};
+struct in_addr;
/**************************************************************************
A wrapper for gethostbyname() that tries avoids looking up hostnames
apparent reason.
****************************************************************************/
_PUBLIC_ struct hostent *sys_gethostbyname(const char *name);
-_PUBLIC_ const char *sys_inet_ntoa(struct ipv4_addr in);
-_PUBLIC_ struct ipv4_addr sys_inet_makeaddr(int net, int host);
+_PUBLIC_ const char *sys_inet_ntoa(struct in_addr in);
+_PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host);
/* The following definitions come from lib/util/genrand.c */
/**
A convenient addition to interpret_addr().
**/
-_PUBLIC_ struct ipv4_addr interpret_addr2(const char *str);
+_PUBLIC_ struct in_addr interpret_addr2(const char *str);
/**
Check if an IP is the 0.0.0.0.
**/
-_PUBLIC_ bool is_zero_ip(struct ipv4_addr ip);
+_PUBLIC_ bool is_zero_ip(struct in_addr ip);
/**
Are two IPs on the same subnet?
**/
-_PUBLIC_ bool same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask);
+_PUBLIC_ bool same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask);
/**
Check if a process exists. Does this work on all unixes?
static void run_child(struct composite_context *c, int fd)
{
struct host_state *state = talloc_get_type(c->private_data, struct host_state);
- struct ipv4_addr ip;
+ struct in_addr ip;
const char *address;
/* this is the blocking call we are going to lots of trouble
to avoid in the parent */
ip = interpret_addr2(state->name.name);
- address = sys_inet_ntoa(ip);
+ address = inet_ntoa(ip);
if (address != NULL) {
write(fd, address, strlen(address)+1);
}
#include "libcli/resolve/resolve.h"
#include "librpc/gen_ndr/ndr_nbt.h"
#include "param/param.h"
+#include "system/network.h"
struct resolve_state {
struct nbt_name name;
if (is_ipaddress(state->name.name) ||
strcasecmp(state->name.name, "localhost") == 0) {
- struct ipv4_addr ip = interpret_addr2(state->name.name);
- state->reply_addr = talloc_strdup(state, sys_inet_ntoa(ip));
+ struct in_addr ip = interpret_addr2(state->name.name);
+ state->reply_addr = talloc_strdup(state, inet_ntoa(ip));
if (composite_nomem(state->reply_addr, c)) return c;
composite_done(c);
return c;
NTSTATUS ndr_pull_dom_sid28(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid);
void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid);
size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags);
-void ndr_print_ipv4_addr(struct ndr_print *ndr, const char *name, const struct ipv4_addr *_ip);
+void ndr_print_ipv4_addr(struct ndr_print *ndr, const char *name, const struct in_addr *_ip);
void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid);
#endif /* __LIBNDR_H__ */
*/
_PUBLIC_ NTSTATUS ndr_pull_ipv4address(struct ndr_pull *ndr, int ndr_flags, const char **address)
{
- struct ipv4_addr in;
- NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &in.addr));
- in.addr = htonl(in.addr);
- *address = talloc_strdup(ndr->current_mem_ctx, sys_inet_ntoa(in));
+ struct in_addr in;
+ NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &in.s_addr));
+ in.s_addr = htonl(in.s_addr);
+ *address = talloc_strdup(ndr->current_mem_ctx, inet_ntoa(in));
NT_STATUS_HAVE_NO_MEMORY(*address);
return NT_STATUS_OK;
}
#include "system/network.h"
#include "librpc/ndr/libndr.h"
-_PUBLIC_ void ndr_print_ipv4_addr(struct ndr_print *ndr, const char *name, const struct ipv4_addr *_ip)
+_PUBLIC_ void ndr_print_in_addr(struct ndr_print *ndr, const char *name, const struct in_addr *_ip)
{
- struct ipv4_addr ip;
+ struct in_addr ip;
- ip.addr = htonl(_ip->addr);
+ ip.s_addr = htonl(_ip->s_addr);
- ndr->print(ndr, "%-25s: %s", name, sys_inet_ntoa(ip));
+ ndr->print(ndr, "%-25s: %s", name, inet_ntoa(ip));
}
_PUBLIC_ void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid)
if (num_interfaces > 0) {
primary_address = iface_n_ip(0);
} else {
- primary_address = sys_inet_ntoa(interpret_addr2(
+ primary_address = inet_ntoa(interpret_addr2(
lp_netbios_name(global_loadparm)));
}
primary_address = talloc_strdup(tmp_ctx, primary_address);
nbtd_name_registration_reply(nbtsock, packet, src, rcode);
}
-static uint32_t ipv4_match_bits(struct ipv4_addr ip1,struct ipv4_addr ip2)
+static uint32_t ipv4_match_bits(struct in_addr ip1, struct in_addr ip2)
{
uint32_t i, j, match=0;
uint8_t *p1, *p2;
- p1 = (uint8_t *)&ip1.addr;
- p2 = (uint8_t *)&ip2.addr;
+ p1 = (uint8_t *)&ip1.s_addr;
+ p2 = (uint8_t *)&ip2.s_addr;
for (i=0; i<4; i++) {
if (p1[i] != p2[i]) break;
#include "lib/samba3/samba3.h"
#include "libcli/security/security.h"
#include "librpc/gen_ndr/ndr_misc.h"
+#include "system/network.h"
static struct MprVar mprRegistry(struct samba3_regdb *reg)
for (j = 0; j < samba3->winsdb_entries[i].ip_count; j++) {
const char *addr;
- addr = sys_inet_ntoa(samba3->winsdb_entries[i].ips[j]);
+ addr = inet_ntoa(samba3->winsdb_entries[i].ips[j]);
mprAddArray(&ips, j, mprString(addr));
}
#include "lib/events/events.h"
#include "libcli/resolve/resolve.h"
#include "torture/torture.h"
+#include "system/network.h"
static bool test_async_resolve(struct torture_context *tctx)
{
torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n",
host, timelimit);
while (timeval_elapsed(&tv) < timelimit) {
- sys_inet_ntoa(interpret_addr2(host));
+ inet_ntoa(interpret_addr2(host));
count++;
}