/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Shim library which should be LD_PRELOADed before running applications
* that interact with NCA but do not explicitly use the AF_NCA family.
* This library overloads AF_INET's version of bind(3SOCKET) with AF_NCA's
* version. The new version of bind checks to see if that the port is one
* NCA is listening on, closes the socket(3SOCKET), and opens a new one
* the family AF_NCA. Afterwards, the real bind(3SOCKET) is called
* descriptors, etc. *
*
* Compile: cc -Kpic -G -o ncad_addr.so ncad_addr.c -lsocket -lnsl
* Use: LD_PRELOAD=/path/to/ncad_addr.so my_program
*/
#include <stdio.h>
#include <assert.h>
#include <dlfcn.h>
#include <door.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stropts.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <ctype.h>
typedef int sfunc1_t(int, int, int);
/*
* It is used to represent an address NCA is willing to handle.
*/
typedef struct nca_address_s {
/*
* It loads all NCA addresses from a configuration file. A NCA address
* entry is: ncaport=IPaddress:port. The line above can be repeatly for other
* addresses. If IPaddress is '*', then it is translated into INADDR_ANY.
*/
static void
ncad_init(void)
{
char *s, *p, *q;
" ncad_addr.so. Error = %s\n",
return;
}
s = buffer;
/* remove '\n' at the end from fgets() */
p = strchr(s, '\n');
if (p != NULL)
*p = '\0';
/* remove spaces from the front */
while (*s != '\0' && isspace(*s))
s++;
if (*s == '\0' || *s == '#')
continue;
/* it should start with ncaport= */
p = strchr(s, '=');
continue;
p++;
while (*p != '\0' && isspace(*p))
p++;
if (q == NULL)
continue;
*q++ = '\0';
if (strcmp(p, "*") == 0) {
addr = INADDR_ANY;
} else {
"NCA does not support IPv6\n");
} else {
"Invalid IP address: %s\n", p);
}
continue;
}
}
/* array is full, expand it */
if (addrcount == addrcapacity) {
if (addrcapacity == 0)
addrcapacity = 64;
else
addrcapacity *= 2;
addrcapacity * sizeof (nca_address_t));
break;
}
}
addrcount++;
}
}
/*
* It destroys memory at the end of program.
*/
static void
ncad_fini(void)
{
}
}
/*
* If the bind is happening on a port NCA is listening on, close
* the socket and open a new one with family AF_NCA.
*/
static int
{
int new_sock;
int i;
if (sock < 0) {
return (-1);
}
if (real_socket == NULL) {
== NULL) {
exit(-1);
}
}
== NULL) {
exit(-1);
}
}
}
/*
* If it is one of the addresses NCA is handling, convert it
* to NCA socket.
*/
for (i = 0; i < addrcount; i++) {
/* convert to NCA socket */
if (new_sock >= 0) {
}
break;
}
}
}