ORBIIOPAddrIPv4 and ORBNoResolveIPv4
- From: Mark van Walraven <markv wave co nz>
- To: orbit-list gnome org
- Subject: ORBIIOPAddrIPv4 and ORBNoResolveIPv4
- Date: Fri, 9 Aug 2002 23:29:03 +1200
Dear Orbiteers,
I've been checking out Orbit 0.5 and wished to control the IIOP address
and port (mainly to assist in firewalling and tunneling). I decided to
implement the non-functional ORBIIOPAddr option, albeit only for IPv4.
The patch is included below. Why Orbit 0.5? Owen Taylor's wonderful
perl bindings!
My sources already had Jamie Walker's 'nodns' patch applied. I observed
its effect was very similar to Mico's ORBNoResolve option, so I renamed
it. Again, the functionality only covers IPv4.
Allowing binding to addresses other than INADDR_ANY opened up the
possibility of bind() failing. After tracking down an annoying number
of segfaults, I rewrote a section of iiop_connection_server() to only
create an IIOPConnection block *after* the socket had been successfully
created and bound. I hope adding a couple of temporary variables has
also helped make the code clearer.
The inet address bound to by iiop_connection_server() is now passed in as
a sockaddr_in struct. The ORBIIOPAddr string is scanned left to right
to find address and port values. Errors in the string format cause the
parse to silently cease (a diagnostic would be kinder). This lump of
code, in CORBA_ORB_init(), probably deserves to be in a function of its
own - a more general version would be useful for supporting ORBIIOPAddr
for the IPv6 and UNIX-domain sockets.
Examples:
-ORBIIOPAddr=inet:192.168.2.13:32766 -> 192.168.2.13:32766
-ORBIIOPAddr=inet:192.168.2.13: -> 192.168.2.13:<random>
-ORBIIOPAddr=inet:192.168.2.13 -> 192.168.2.13:<random>
-ORBIIOPAddr=inet:0.0.0.0:32766 -> *:32766
-ORBIIOPAddr=inet:0.0.0.0:32766:blah -> *:32766
-ORBIIOPAddr=inet:myhostname:32766 -> *:<random>
-ORBIIOPAddr=blahblahblahblahblah -> *:<random>
"It would be nice" to allow the ORBIIOPAddr option to occur multiple
times (which would also make ORBIIOPUSock, ORBIIOPIPv4 and ORBIIOPIPv6
redundant), though this would require changes to the way options are
parsed and evaluated.
ORBIIOPAddr is useful to me, so please let me know what you think.
Regards,
Mark.
diff -ur ORBit-0.5.16-pristine/src/orb/orb.c ORBit-0.5.16/src/orb/orb.c
--- ORBit-0.5.16-pristine/src/orb/orb.c Tue Mar 12 01:40:03 2002
+++ ORBit-0.5.16/src/orb/orb.c Fri Aug 9 22:44:43 2002
@@ -288,10 +288,12 @@
int use_ipv4=0;
int use_ipv6=0;
int use_usock=1;
+ int noresolve=0;
int debug_level=0;
int debug_modules=0;
int nosysrc=0;
int nouserrc=0;
+ char *iiop_addr=NULL;
char *imr_ior=NULL, *imr_addr=NULL;
char *ir_ior=NULL, *ir_addr=NULL;
char *naming_ior=NULL, *naming_addr=NULL;
@@ -327,6 +329,7 @@
{"ORBBindAddr", string_arg, NULL}, /* XXX need to make
libIIOP support this */
{"ORBIIOPAddr", string_arg, NULL},
+ {"ORBNoResolve", no_arg, NULL},
/* These options aren't */
{"ORBDebugModules", int_arg, NULL},
@@ -356,12 +359,14 @@
options[7].arg = (void *) &naming_ior;
options[8].arg = (void *) &naming_addr;
options[9].arg = (void *) &debug_level;
- options[12].arg = (void *) &debug_modules;
- options[13].arg = (void *) &root_poa_ior;
- options[14].arg = (void *) &root_poa_addr;
- options[15].arg = (void *) &use_usock;
- options[16].arg = (void *) &use_ipv4;
- options[17].arg = (void *) &use_ipv6;
+ options[11].arg = (void *) &iiop_addr;
+ options[12].arg = (void *) &noresolve;
+ options[13].arg = (void *) &debug_modules;
+ options[14].arg = (void *) &root_poa_ior;
+ options[15].arg = (void *) &root_poa_addr;
+ options[16].arg = (void *) &use_usock;
+ options[17].arg = (void *) &use_ipv4;
+ options[18].arg = (void *) &use_ipv6;
ORBit_option_parse(argc, argv, pre_rc_options);
@@ -420,9 +425,28 @@
}
if(use_ipv4) {
- orb->cnx.ipv4 = GIOP_CONNECTION(iiop_connection_server());
- giop_connection_ref(orb->cnx.ipv4);
- GIOP_CONNECTION(orb->cnx.ipv4)->orb_data = orb;
+ struct sockaddr_in iiop_sa;
+
+ /* default: IIOP server on all local addresses, random port */
+ iiop_sa.sin_family = AF_INET;
+ iiop_sa.sin_addr.s_addr = htons(INADDR_ANY);
+ iiop_sa.sin_port = 0;
+
+ /* override IIOP server address and port if specified */
+ if (iiop_addr && *iiop_addr) {
+ gchar **tokens = g_strsplit(iiop_addr, ":", 3);
+ if (tokens[0] && strcmp(tokens[0], "inet") == 0)
+ if (tokens[1] && inet_aton(tokens[1], &iiop_sa.sin_addr))
+ if (tokens[2])
+ iiop_sa.sin_port = htons(atoi(tokens[2]));
+ g_strfreev(tokens);
+ }
+
+ orb->cnx.ipv4 = GIOP_CONNECTION(iiop_connection_server(noresolve, &iiop_sa));
+ if (orb->cnx.ipv4) {
+ giop_connection_ref(orb->cnx.ipv4);
+ GIOP_CONNECTION(orb->cnx.ipv4)->orb_data = orb;
+ }
}
@@ -544,6 +568,7 @@
ORBit_ORB_release(orb, ev);
orb = NULL;
}
+ g_free(iiop_addr);
g_free(imr_ior);
g_free(imr_addr);
g_free(ir_ior);
diff -ur ORBit-0.5.16-pristine/src/IIOP/connection.c ORBit-0.5.16/src/IIOP/connection.c
--- ORBit-0.5.16-pristine/src/IIOP/connection.c Tue Mar 12 01:40:02 2002
+++ ORBit-0.5.16/src/IIOP/connection.c Fri Aug 9 16:18:59 2002
@@ -501,46 +501,46 @@
* connections come.
*/
IIOPConnection *
-iiop_connection_server(void)
+iiop_connection_server(int noresolve, struct sockaddr_in *iiop_addr)
{
struct hostent *hent;
char hn_tmp[65];
socklen_t n;
- IIOPConnection *server_cnx = g_new0(IIOPConnection, 1);
+ IIOPConnection *server_cnx;
+ int sock;
- iiop_connection_init(server_cnx, GIOP_CONNECTION_SERVER, IIOP_IPV4);
-
- server_cnx->is_serversock = TRUE;
- GIOP_CONNECTION(server_cnx)->fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
-
- if(GIOP_CONNECTION_GET_FD(server_cnx) < 0) {
+ /* create TCP socket */
+ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if(sock < 0) {
ORBit_Trace(TraceMod_IIOP, TraceLevel_Debug, "iiop_connection_server: socket_error: %s\n", strerror(errno));
- goto failed;
+ return NULL;
+ }
+
+ /* bind socket to port */
+ if (bind(sock, (struct sockaddr *)iiop_addr, sizeof *iiop_addr)) {
+ ORBit_Trace(TraceMod_IIOP, TraceLevel_Debug, "iiop_connection_server: bind_error: %s\n", strerror(errno));
+ close(sock);
+ return NULL;
}
- server_cnx->u.ipv4.location.sin_family = AF_INET;
- server_cnx->u.ipv4.location.sin_addr.s_addr = INADDR_ANY;
- bind(GIOP_CONNECTION_GET_FD(server_cnx),
- (struct sockaddr *)&server_cnx->u.ipv4.location,
- sizeof(struct sockaddr_in));
-
- fcntl(GIOP_CONNECTION_GET_FD(server_cnx), F_SETFD,
- fcntl(GIOP_CONNECTION_GET_FD(server_cnx), F_GETFD, 0)
- | FD_CLOEXEC);
- fcntl(GIOP_CONNECTION_GET_FD(server_cnx), F_SETFL,
- fcntl(GIOP_CONNECTION_GET_FD(server_cnx), F_GETFL, 0)
- | O_NONBLOCK);
-
- n = sizeof(struct sockaddr_in);
- getsockname(GIOP_CONNECTION_GET_FD(server_cnx),
- (struct sockaddr *)&server_cnx->u.ipv4.location, &n);
+ fcntl(sock, F_SETFD, fcntl(sock, F_GETFD, 0) | FD_CLOEXEC);
+ fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);
+
+ /* create IIOPConnection and initialise with details of bound socket */
+ server_cnx = g_new0(IIOPConnection, 1);
+ iiop_connection_init(server_cnx, GIOP_CONNECTION_SERVER, IIOP_IPV4);
+ server_cnx->is_serversock = TRUE;
+ GIOP_CONNECTION(server_cnx)->fd = sock;
+ n = sizeof *iiop_addr;
+ getsockname(sock, (struct sockaddr *)iiop_addr, &n);
+ server_cnx->u.ipv4.location = *iiop_addr;
gethostname(hn_tmp, sizeof(hn_tmp) - 1);
hent = gethostbyname(hn_tmp);
if(hent)
{
- if (strchr (hent->h_name, '.'))
+ if (strchr (hent->h_name, '.') && !noresolve)
server_cnx->u.ipv4.hostname = g_strdup(hent->h_name);
else
{
@@ -557,17 +557,6 @@
giop_connection_add_to_list(GIOP_CONNECTION(server_cnx));
return server_cnx;
-
-failed:
- close(GIOP_CONNECTION_GET_FD(server_cnx));
- GIOP_CONNECTION(server_cnx)->fd = -1;
- giop_connection_free(GIOP_CONNECTION(server_cnx));
- server_cnx = NULL;
- /*
- * FIXME: GET_LOCK and DEFINE_LOCK never called for server_cnx
- RELEASE_LOCK(server_cnx);
- */
- return NULL;
}
/*
diff -ur ORBit-0.5.16-pristine/src/IIOP/IIOP.h ORBit-0.5.16/src/IIOP/IIOP.h
--- ORBit-0.5.16-pristine/src/IIOP/IIOP.h Tue Mar 12 01:40:02 2002
+++ ORBit-0.5.16/src/IIOP/IIOP.h Fri Aug 9 16:27:56 2002
@@ -25,7 +25,7 @@
gboolean existing_only);
/* gives us a local socket that other people can connect to... */
-IIOPConnection *iiop_connection_server(void);
+IIOPConnection *iiop_connection_server(int noresolve, struct sockaddr_in *iiop_addr);
IIOPConnection *iiop_connection_server_ipv6(void);
IIOPConnection *iiop_connection_server_unix(const char *sockpath);
(end)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]