summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-03-25 03:20:26 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-03-25 03:20:26 +0000
commit7bc7c553af559c7f9429abd5fac841636ffeadde (patch)
tree713bc808ecd9fde378f6d9370224455328e93d99 /ace
parentb8c6347b29f1655df9fb7a6c4b0b0a1aa16cb855 (diff)
downloadATCD-7bc7c553af559c7f9429abd5fac841636ffeadde.tar.gz
*** empty log message ***
Diffstat (limited to 'ace')
-rw-r--r--ace/ACE.cpp85
-rw-r--r--ace/ACE.h11
-rw-r--r--ace/Malloc.h6
-rw-r--r--ace/SOCK_Dgram_Bcast.cpp34
4 files changed, 90 insertions, 46 deletions
diff --git a/ace/ACE.cpp b/ace/ACE.cpp
index c885beba3bf..0f3bfaf515c 100644
--- a/ace/ACE.cpp
+++ b/ace/ACE.cpp
@@ -1341,31 +1341,26 @@ ACE::sock_error (int error)
#endif /* ACE_WIN32 */
}
-ACE_UINT32
-ACE::get_bcast_addr (ACE_UINT32 host_addr,
+int
+ACE::get_bcast_addr (ACE_UINT32 &bcast_addr,
+ const char *host_name,
+ ACE_UINT32 host_addr,
ACE_HANDLE handle)
{
ACE_TRACE ("ACE_INET_Addr::get_bcast_addr");
#if !defined(ACE_WIN32)
- char buf[BUFSIZ];
- struct ifconf ifc;
- struct ifreq *ifr;
-
- struct ifreq flags;
- struct ifreq if_req;
-
- struct sockaddr_in ip_addr, if_addr;
-
- ACE_OS::memcpy ((void *) &ip_addr.sin_addr,
- (void*) &host_addr,
- sizeof ip_addr.sin_addr);
+ ACE_HANDLE s = handle;
- ACE_HANDLE s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0);
+ if (s == ACE_INVALID_HANDLE)
+ s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0);
if (s == ACE_INVALID_HANDLE)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_OS::socket"), -1);
+ struct ifconf ifc;
+ char buf[BUFSIZ];
+
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = buf;
@@ -1374,12 +1369,38 @@ ACE::get_bcast_addr (ACE_UINT32 host_addr,
if (ACE_OS::ioctl (s, SIOCGIFCONF, (char *) &ifc) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
"ACE_INET_Addr_::get_bcast_addr: ioctl (get interface configuration)"),
- host_addr);
+ -1);
+
+ struct ifreq *ifr = ifc.ifc_req;
- ifr = ifc.ifc_req;
+ struct sockaddr_in ip_addr;
- for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0; n--, ifr++)
+ // Get host ip address if necessary.
+ if (host_name)
{
+ hostent *hp = ACE_OS::gethostbyname (host_name);
+
+ if (hp == 0)
+ return -1;
+ else
+ ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr,
+ (char *) hp->h_addr,
+ hp->h_length);
+ }
+ else
+ {
+ ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr);
+ ACE_OS::memcpy ((void *) &ip_addr.sin_addr,
+ (void*) &host_addr,
+ sizeof ip_addr.sin_addr);
+ }
+
+ for (int n = ifc.ifc_len / sizeof (struct ifreq);
+ n > 0;
+ n--, ifr++)
+ {
+ struct sockaddr_in if_addr;
+
// Compare host ip address with interface ip address.
ACE_OS::memcpy (&if_addr, &ifr->ifr_addr, sizeof if_addr);
@@ -1393,7 +1414,8 @@ ACE::get_bcast_addr (ACE_UINT32 host_addr,
continue;
}
- flags = if_req = *ifr;
+ struct ifreq flags = *ifr;
+ struct ifreq if_req = *ifr;
if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1)
{
@@ -1419,25 +1441,34 @@ ACE::get_bcast_addr (ACE_UINT32 host_addr,
"ACE_INET_Addr::get_bcast_addr: ioctl (get broadaddr)"));
else
{
- ACE_OS::memcpy ((struct sockaddr_in *)&ip_addr,
- (struct sockaddr_in *)&if_req.ifr_broadaddr,
+ ACE_OS::memcpy ((struct sockaddr_in *) &ip_addr,
+ (struct sockaddr_in *) &if_req.ifr_broadaddr,
sizeof if_req.ifr_broadaddr);
- ACE_OS::memcpy ((void *)&host_addr, (void *)&ip_addr.sin_addr,
+ ACE_OS::memcpy ((void *) &host_addr,
+ (void *) &ip_addr.sin_addr,
sizeof host_addr);
- ACE_OS::close (s);
- return host_addr;
+ if (handle == ACE_INVALID_HANDLE)
+ ACE_OS::close (s);
+ bcast_addr = host_addr;
+ return 0;
}
}
else
ACE_ERROR ((LM_ERROR, "%p\n",
"ACE_INET_Addr::get_bcast_addr: Broadcast is not enable for this interface."));
- ACE_OS::close (s);
- return host_addr;
+ if (handle == ACE_INVALID_HANDLE)
+ ACE_OS::close (s);
+ bcast_addr = host_addr;
+ return 0;
}
#else
- return (ACE_UINT32 (INADDR_BROADCAST));
+ ACE_UNUSED_ARG (handle);
+ ACE_UNUSED_ARG (host_addr);
+ ACE_UNUSED_ARG (host_name);
+ bcast_addr = (ACE_UINT32 (INADDR_BROADCAST));
+ return 0;
#endif /* !ACE_WIN32 */
}
diff --git a/ace/ACE.h b/ace/ACE.h
index f51cd50a155..498cf59a3a5 100644
--- a/ace/ACE.h
+++ b/ace/ACE.h
@@ -197,6 +197,17 @@ public:
static int bind_port (ACE_HANDLE handle);
// Bind a new unused port to <handle>.
+ static int get_bcast_addr (ACE_UINT32 &bcast_addr,
+ const char *hostname = 0,
+ ACE_UINT32 host_addr = 0,
+ ACE_HANDLE handle = ACE_INVALID_HANDLE);
+ // Get our broadcast address based on our <host_addr>. If
+ // <hostname> is non-0 we'll use it to determine our IP address. If
+ // <handle> is not <ACE_INVALID_HANDLE> then we'll use this to
+ // determine our broadcast address, otherwise we'll have to create a
+ // socket internally (and free it). Returns -1 on failure and 0 on
+ // success.
+
static int handle_timed_accept (ACE_HANDLE listener,
ACE_Time_Value *timeout,
int restart);
diff --git a/ace/Malloc.h b/ace/Malloc.h
index b2d1d8f7e74..822044975c4 100644
--- a/ace/Malloc.h
+++ b/ace/Malloc.h
@@ -177,10 +177,10 @@ public:
// Dummy node used to anchor the freelist.
#if 0
- long align_[ACE_MALLOC_ALIGN/sizeof (long)];
-#else
- (ACE_MALLOC_ALIGN/sizeof (long)) -
+ long align_ [(ACE_MALLOC_ALIGN/sizeof (long)) -
1 - ((sizeof (ACE_Name_Node *) + sizeof (ACE_Malloc_Header *) + MAXNAMELEN) / sizeof (long))];
+#else
+ long align_[ACE_MALLOC_ALIGN/sizeof (long)];
#endif /* 0 */
void dump (void) const;
diff --git a/ace/SOCK_Dgram_Bcast.cpp b/ace/SOCK_Dgram_Bcast.cpp
index 0a949627d79..e1058fcce9c 100644
--- a/ace/SOCK_Dgram_Bcast.cpp
+++ b/ace/SOCK_Dgram_Bcast.cpp
@@ -98,17 +98,10 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const char *host_name)
return -1;
#if !defined(ACE_WIN32)
+ ACE_HANDLE s = this->get_handle ();
+
char buf[BUFSIZ];
struct ifconf ifc;
- struct ifreq *ifr;
-
- struct ifreq flags;
- struct ifreq if_req;
-
- struct sockaddr_in host_addr, if_addr;
- hostent *hp;
-
- int s = this->get_handle ();
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = buf;
@@ -120,15 +113,21 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const char *host_name)
"ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface configuration)"),
ACE_INVALID_HANDLE);
- ifr = ifc.ifc_req;
+ struct ifreq *ifr = ifc.ifc_req;
+
+ struct sockaddr_in host_addr;
//Get host ip address
if (host_name)
{
- hp = ACE_OS::gethostbyname (host_name);
- ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr,
- (char *) hp->h_addr,
- hp->h_length);
+ hostent *hp = ACE_OS::gethostbyname (host_name);
+
+ if (hp == 0)
+ return -1;
+ else
+ ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr,
+ (char *) hp->h_addr,
+ hp->h_length);
}
for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0; n--, ifr++)
@@ -136,6 +135,8 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const char *host_name)
// Compare host ip address with interface ip address.
if (host_name)
{
+ struct sockaddr_in if_addr;
+
ACE_OS::memcpy (&if_addr, &ifr->ifr_addr, sizeof if_addr);
if (host_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
@@ -149,8 +150,9 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const char *host_name)
continue;
}
- flags = if_req = *ifr;
-
+ struct ifreq flags = *ifr;
+ struct ifreq if_req = *ifr;
+
if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1)
{
ACE_ERROR ((LM_ERROR, "%p\n",