Add a -lhost switch to allow binding to a local address on a multihomed

host (i.e. choose with which address to connect to the server).

Bump revision to i2cb-6.0_ALPHAnb1.
This commit is contained in:
hubertf 2004-04-13 21:19:48 +00:00
parent 6930900086
commit 03786102ec
7 changed files with 181 additions and 8 deletions

View file

@ -1,7 +1,8 @@
# $NetBSD: Makefile,v 1.9 2004/04/11 05:48:49 snj Exp $
# $NetBSD: Makefile,v 1.10 2004/04/13 21:19:48 hubertf Exp $
#
DISTNAME= i2cb-6.0_ALPHA
PKGREVISION= 1
CATEGORIES= chat
MASTER_SITES= ${MASTER_SITE_LOCAL}

View file

@ -1,13 +1,13 @@
$NetBSD: distinfo,v 1.4 2003/12/19 19:15:06 agc Exp $
$NetBSD: distinfo,v 1.5 2004/04/13 21:19:48 hubertf Exp $
SHA1 (i2cb-6.0_ALPHA.tar.gz) = 6d2ddd234403fe33426ece3fd4de4104cf1a6257
Size (i2cb-6.0_ALPHA.tar.gz) = 73607 bytes
SHA1 (patch-aa) = ede7c2087324f0a79cfb4146926661fecc6af550
SHA1 (patch-ab) = 358b366c16290d6d2326e72c281f977e49a8a98b
SHA1 (patch-ac) = fb88b9e3fe894feab0bbc8ead48e46572598d17a
SHA1 (patch-ac) = 4dc5be4a2c05f453369c4bb56cd1aeb81636904e
SHA1 (patch-ad) = 609b2e5cf6118fbc36818a392866bc7fafc59abc
SHA1 (patch-ae) = 0f8765883c2b7e77394556405ee7fee7a054ad56
SHA1 (patch-af) = ba355bdbee708ae6de0583b4e8330dc0c1946670
SHA1 (patch-af) = 779ecab95384f8fa24000c90f6671317d6276c83
SHA1 (patch-ag) = e2bf71557fa486371e0d26ff8d5716ae0924a498
SHA1 (patch-ah) = 1785c0f09a7a0f83b7cb886e9e749959b1753972
SHA1 (patch-ai) = f2b83d20f6357dd6cb3e468b573c46d6123cae39
@ -18,3 +18,6 @@ SHA1 (patch-am) = 24d700b5e95248bc54253893bfbf4a664db50ace
SHA1 (patch-an) = 2b6db4e59da609a03c6cbe23d1866e01a48af756
SHA1 (patch-ao) = 73d6915d68bd02fbfc0e481f42f4626bbce18882
SHA1 (patch-ap) = f04fea14ab6a07095f6b2f95c693988563aa4f3a
SHA1 (patch-aq) = f07edc14636f1321f8c0b5c98e4962f3bfb1eee5
SHA1 (patch-ar) = 9fea79c9d7f701962e40f1b311c38b538029e633
SHA1 (patch-as) = 67627f9beb5336fa5859aa150bb44fc7b3e5c6cf

View file

@ -1,4 +1,4 @@
$NetBSD: patch-ac,v 1.1.1.1 2002/11/14 00:55:44 hubertf Exp $
$NetBSD: patch-ac,v 1.2 2004/04/13 21:19:48 hubertf Exp $
--- src/externs.h.orig Wed Mar 15 23:28:13 2000
+++ src/externs.h
@ -13,3 +13,20 @@ $NetBSD: patch-ac,v 1.1.1.1 2002/11/14 00:55:44 hubertf Exp $
/* external definitions for "icb" global variables */
/* defined in port.c */
@@ -25,6 +29,7 @@ extern char *mygroup; /* requested grou
extern char *myserver; /* server name */
extern char *myhost; /* server host */
extern int myport; /* server port */
+extern char *mylhost; /* local address */
extern char *mbuf; /* message buffer */
extern char *mbuf2; /* message buffer */
extern int connected; /* whether we are validated or not */
@@ -69,7 +74,7 @@ void clearargs (int argc, char **argv);
int clientserve (void);
void closesessionlog (void);
void cmdoutmsg (char *pkt);
-int connecttoport (char *host_name, int port_number);
+int connecttoport (char *host_name, int port_number, char *lhost_name);
void copenmsg (char *pkt);
void cpersonalmsg (char *pkt);
void csendopen (char *txt);

View file

@ -1,13 +1,67 @@
$NetBSD: patch-af,v 1.1.1.1 2002/11/14 00:55:44 hubertf Exp $
$NetBSD: patch-af,v 1.2 2004/04/13 21:19:48 hubertf Exp $
--- src/contoport.c.orig Wed Mar 15 23:13:28 2000
--- src/contoport.c.orig Tue Apr 13 22:29:28 2004
+++ src/contoport.c
@@ -21,7 +21,7 @@
@@ -14,14 +14,15 @@
#include "icb.h"
#include "externs.h"
-int connecttoport (char *host_name, int port_number);
+int connecttoport (char *host_name, int port_number, char *lhost_name);
int
-connecttoport (char *host_name, int port_number)
+connecttoport (char *host_name, int port_number, char *lhost_name)
{
struct addrinfo hints, *res, *a;
+ struct addrinfo lhints, *lres, *la;
char p[10];
- int err, s;
+ int err, s=-1;
snprintf(p, 9, "%d", port_number);
@@ -36,12 +37,43 @@ connecttoport (char *host_name, int port
perror(gai_strerror(err));
return(-1);
}
+
+ if (lhost_name != NULL) {
+ memset(&lhints, 0, sizeof(lhints));
+ lhints.ai_socktype = SOCK_STREAM;
+ lhints.ai_family = PF_UNSPEC;
+ lhints.ai_flags = AI_PASSIVE;
+
+ err = getaddrinfo(lhost_name, p, &lhints, &lres);
+ if (err) {
+ perror(gai_strerror(err));
+ return(-1);
+ }
+ }
+
a = res;
while (a) {
if ((s = socket(a->ai_family, a->ai_socktype, a->ai_protocol)) < 0) {
a = a->ai_next;
continue;
}
+
+ if (lhost_name != NULL) {
+ err = -1;
+ for(la = lres; la; la=la->ai_next) {
+ if (bind(s, la->ai_addr, la->ai_addrlen) == 0) {
+ /* bound locally! */
+ err = 0;
+ break;
+ }
+ }
+ freeaddrinfo(lres);
+ if (err < 0) {
+ perror(gai_strerror(err));
+ return(-1);
+ }
+ }
+
if (connect(s, a->ai_addr, a->ai_addrlen) < 0) {
close(s);
a = a->ai_next;

View file

@ -0,0 +1,12 @@
$NetBSD: patch-aq,v 1.1 2004/04/13 21:19:48 hubertf Exp $
--- src/globals.c.orig Wed Mar 15 23:13:28 2000
+++ src/globals.c
@@ -26,6 +26,7 @@ char *mygroup = ""; /* requested group
char *myserver = NULL; /* name of server */
char *myhost = NULL; /* hostname of server */
int myport = 0; /* string form of port number */
+char *mylhost = NULL; /* local address */
int connected = 0; /* 1 when server validates us */
char continued = 0; /* did we bg then fg this job? */
int whoflg = 0; /* just do a who at startup */

View file

@ -0,0 +1,13 @@
$NetBSD: patch-ar,v 1.1 2004/04/13 21:19:48 hubertf Exp $
--- src/helpdata.c.orig Wed Mar 15 23:42:52 2000
+++ src/helpdata.c
@@ -344,6 +344,8 @@ char *ht_options[] =
"",
" -port port try to connect to port port.",
"",
+" -lhost lhost connect from local address lhost.",
+"",
" -list list known servers, in order.",
"",
" -clear wipe args from command line.",

View file

@ -0,0 +1,73 @@
$NetBSD: patch-as,v 1.1 2004/04/13 21:19:48 hubertf Exp $
--- src/main.c.orig Wed Mar 15 23:13:28 2000
+++ src/main.c
@@ -19,6 +19,7 @@ static void usage (char *name, int ret);
char *optv[] = { "clear", "list", "who", "restricted", "nickname:", "group:",
"host:", "port:", "password:", "server:", "N:", "help/",
+ "lhost:",
(char *)NULL };
static void
@@ -33,6 +34,7 @@ fprintf(stderr," -group group\t\tsign o
fprintf(stderr," -server name\t\tconnect to server named name.\n");
fprintf(stderr," -host host\t\tconnect to server on host host.\n");
fprintf(stderr," -port port\t\ttry to connect to port port.\n");
+fprintf(stderr," -lhost lhost\t\tconnect from local address lhost.\n");
fprintf(stderr," -list\t\t\tlist known servers, in order.\n");
fprintf(stderr," -clear\t\twipe args from command line.\n");
fprintf(stderr," -who\t\t\tsee who's on; don't sign on.\n");
@@ -56,12 +58,14 @@ main (int argc, char **argv)
static char server[MAX_NICKLEN+1];
static char host[MAX_HOSTLEN+1];
static char pass[MAX_PASSLEN+1];
+ static char lhost[MAX_HOSTLEN+1];
mynick = NULL;
mygroup = "1";
myserver = NULL;
myhost = NULL;
myport = DEFAULTPORT;
+ mylhost = NULL;
switcherr=0;
while ((s = getswitch(argc, argv, optv)) != NULL)
@@ -93,8 +97,18 @@ main (int argc, char **argv)
break;
case 'l':
- listflg++;
- gv.interactive = 0;
+ switch (s[1])
+ {
+ case 'i':
+ listflg++;
+ gv.interactive = 0;
+ break;
+ case 'h':
+ strncpy(lhost,switcharg,MAX_HOSTLEN-1);
+ lhost[MAX_HOSTLEN-1]='\0';
+ mylhost = lhost;
+ break;
+ }
break;
case 'p':
@@ -261,14 +275,14 @@ main (int argc, char **argv)
myport = serverdata->port;
}
- if (connecttoport(myhost, myport) < 0)
+ if (connecttoport(myhost, myport, mylhost) < 0)
{
connected = 0;
if (try)
{
while ((serverdata = getserver())!=NULL)
{
- if (connecttoport(serverdata->host, serverdata->port) == 0)
+ if (connecttoport(serverdata->host, serverdata->port, mylhost) == 0)
{
connected = 1;
break;