Mercurial > pidgin
changeset 2911:4790fb1272a1
[gaim-migrate @ 2924]
wait
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 21 Dec 2001 23:27:48 +0000 |
parents | 9f324f8b5fdf |
children | 152d726312b2 |
files | src/proxy.c |
diffstat | 1 files changed, 36 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/proxy.c Fri Dec 21 22:50:52 2001 +0000 +++ b/src/proxy.c Fri Dec 21 23:27:48 2001 +0000 @@ -33,6 +33,7 @@ #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> +#include <arpa/inet.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> @@ -118,6 +119,25 @@ g_source_remove(tag); } +static struct sockaddr_in *gaim_gethostbyname(char *host, int port) +{ + static struct sockaddr_in sin; + + if (!inet_aton(host, &sin.sin_addr)) { + struct hostent *hp; + if (!(hp = gethostbyname(host))) { + return NULL; + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + + return &sin; +} + static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) { struct PHB *phb = data; @@ -151,31 +171,25 @@ static int proxy_connect_none(char *host, unsigned short port, struct PHB *phb) { - struct sockaddr_in sin; - struct hostent *hp; + struct sockaddr_in *sin; int fd = -1; debug_printf("connecting to %s:%d with no proxy\n", host, port); - if (!(hp = gethostbyname(host))) { + if (!(sin = gaim_gethostbyname(host, port))) { debug_printf("gethostbyname failed\n"); g_free(phb); return -1; } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(port); - - if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { + if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { debug_printf("unable to create socket\n"); g_free(phb); return -1; } fcntl(fd, F_SETFL, O_NONBLOCK); - if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { if ((errno == EINPROGRESS) || (errno == EINTR)) { debug_printf("Connect would have blocked\n"); phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb); @@ -302,23 +316,17 @@ static int proxy_connect_http(char *host, unsigned short port, struct PHB *phb) { - struct hostent *hp; - struct sockaddr_in sin; + struct sockaddr_in *sin; int fd = -1; debug_printf("connecting to %s:%d via %s:%d using HTTP\n", host, port, proxyhost, proxyport); - if (!(hp = gethostbyname(proxyhost))) { + if (!(sin = gaim_gethostbyname(proxyhost, port))) { g_free(phb); return -1; } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(proxyport); - - if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { + if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { g_free(phb); return -1; } @@ -327,7 +335,7 @@ phb->port = port; fcntl(fd, F_SETFL, O_NONBLOCK); - if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { if ((errno == EINPROGRESS) || (errno == EINTR)) { debug_printf("Connect would have blocked\n"); phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, http_canwrite, phb); @@ -427,23 +435,17 @@ static int proxy_connect_socks4(char *host, unsigned short port, struct PHB *phb) { - struct sockaddr_in sin; - struct hostent *hp; + struct sockaddr_in *sin; int fd = -1; debug_printf("connecting to %s:%d via %s:%d using SOCKS4\n", host, port, proxyhost, proxyport); - if (!(hp = gethostbyname(proxyhost))) { + if (!(sin = gaim_gethostbyname(proxyhost, port))) { g_free(phb); return -1; } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(proxyport); - - if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { + if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { g_free(phb); return -1; } @@ -452,7 +454,7 @@ phb->port = port; fcntl(fd, F_SETFL, O_NONBLOCK); - if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { if ((errno == EINPROGRESS) || (errno == EINTR)) { debug_printf("Connect would have blocked\n"); phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s4_canwrite, phb); @@ -656,23 +658,17 @@ static int proxy_connect_socks5(char *host, unsigned short port, struct PHB *phb) { + struct sockaddr_in *sin; int fd = -1; - struct sockaddr_in sin; - struct hostent *hp; debug_printf("connecting to %s:%d via %s:%d using SOCKS5\n", host, port, proxyhost, proxyport); - if (!(hp = gethostbyname(proxyhost))) { + if (!(sin = gaim_gethostbyname(proxyhost, port))) { g_free(phb); return -1; } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(proxyport); - - if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { + if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { g_free(phb); return -1; } @@ -681,7 +677,7 @@ phb->port = port; fcntl(fd, F_SETFL, O_NONBLOCK); - if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { if ((errno == EINPROGRESS) || (errno == EINTR)) { debug_printf("Connect would have blocked\n"); phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s5_canwrite, phb);