host (i.e. choose with which address to connect to the server). Bump revision to i2cb-6.0_ALPHAnb1.
67 lines
1.5 KiB
Text
67 lines
1.5 KiB
Text
$NetBSD: patch-af,v 1.2 2004/04/13 21:19:48 hubertf Exp $
|
|
|
|
--- src/contoport.c.orig Tue Apr 13 22:29:28 2004
|
|
+++ src/contoport.c
|
|
@@ -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;
|