comparison dbutil.c @ 63:dcc43965928f

- A nice cleaner structure for tcp (acceptor) forwarding. - still a checkpoint-ish commit - sorted out listening on localhost only
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 Aug 2004 17:26:47 +0000
parents 20563735e8b5
children efb5e0b335cf
comparison
equal deleted inserted replaced
62:20563735e8b5 63:dcc43965928f
112 va_end(param); 112 va_end(param);
113 } 113 }
114 #endif /* DEBUG_TRACE */ 114 #endif /* DEBUG_TRACE */
115 115
116 /* Listen on address:port. Unless address is NULL, in which case listen on 116 /* Listen on address:port. Unless address is NULL, in which case listen on
117 * everything (ie 0.0.0.0, or ::1 - note that this is IPv? agnostic. Linux is 117 * everything. If called with address == "", we'll listen on localhost/loopback.
118 * broken with respect to listening to v6 or v4, so the addresses you get when 118 * Returns the number of sockets bound on success, or -1 on failure. On
119 * people connect will be wrong. It doesn't break things, just looks quite
120 * ugly. Returns the number of sockets bound on success, or -1 on failure. On
121 * failure, if errstring wasn't NULL, it'll be a newly malloced error 119 * failure, if errstring wasn't NULL, it'll be a newly malloced error
122 * string.*/ 120 * string.*/
123 int dropbear_listen(const char* address, const char* port, 121 int dropbear_listen(const char* address, const char* port,
124 int *socks, unsigned int sockcount, char **errstring, int *maxfd) { 122 int *socks, unsigned int sockcount, char **errstring, int *maxfd) {
125 123
133 TRACE(("enter dropbear_listen")); 131 TRACE(("enter dropbear_listen"));
134 132
135 memset(&hints, 0, sizeof(hints)); 133 memset(&hints, 0, sizeof(hints));
136 hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */ 134 hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */
137 hints.ai_socktype = SOCK_STREAM; 135 hints.ai_socktype = SOCK_STREAM;
138 hints.ai_flags = AI_PASSIVE; 136
137 if (address && address[0] == '\0') {
138 TRACE(("dropbear_listen: local loopback"));
139 address = NULL;
140 } else {
141 TRACE(("dropbear_listen: not local loopback"));
142 hints.ai_flags = AI_PASSIVE;
143 }
139 err = getaddrinfo(address, port, &hints, &res0); 144 err = getaddrinfo(address, port, &hints, &res0);
140 145
141 if (err) { 146 if (err) {
142 if (errstring != NULL && *errstring == NULL) { 147 if (errstring != NULL && *errstring == NULL) {
143 int len; 148 int len;