- Timestamp:
- 2010-08-15T22:07:57Z (14 years ago)
- Branches:
- master
- Children:
- d20ea9f
- Parents:
- 136c2bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/proxy.c
r136c2bb r762d96f 49 49 char proxypass[128] = ""; 50 50 51 /* Some systems don't know this one. It's not essential, so set it to 0 then. */ 52 #ifndef AI_NUMERICSERV 53 #define AI_NUMERICSERV 0 54 #endif 55 51 56 struct PHB { 52 57 b_event_handler func, proxy_func; … … 56 61 int fd; 57 62 gint inpa; 63 struct addrinfo *gai, *gai_cur; 58 64 }; 65 66 static int proxy_connect_none(const char *host, unsigned short port_, struct PHB *phb); 59 67 60 68 static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition cond) … … 66 74 67 75 #ifndef _WIN32 68 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 76 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) { 77 if ((phb->gai_cur = phb->gai_cur->ai_next)) { 78 int new_fd; 79 b_event_remove(phb->inpa); 80 if ((new_fd = proxy_connect_none(NULL, 0, phb))) { 81 b_event_remove(phb->inpa); 82 closesocket(source); 83 dup2(new_fd, source); 84 phb->inpa = b_input_add(source, B_EV_IO_WRITE, gaim_io_connected, phb); 85 return FALSE; 86 } 87 } 88 freeaddrinfo(phb->gai); 69 89 closesocket(source); 70 90 b_event_remove(phb->inpa); … … 78 98 } 79 99 #endif 100 freeaddrinfo(phb->gai); 80 101 sock_make_blocking(source); 81 102 b_event_remove(phb->inpa); … … 94 115 struct sockaddr_in me; 95 116 int fd = -1; 96 int ret; 97 char port[6]; 98 struct addrinfo hints; 99 struct addrinfo* result; 100 101 g_snprintf(port, sizeof(port), "%d", port_); 102 103 memset(&hints, 0, sizeof(struct addrinfo)); 104 hints.ai_family = AF_UNSPEC; 105 hints.ai_socktype = SOCK_STREAM; 106 hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV; 107 108 if (!(ret = getaddrinfo(host, port, &hints, &result))) 117 118 if (phb->gai_cur == NULL) 109 119 { 110 struct addrinfo* rp; 111 112 for (rp = result; rp; rp = rp->ai_next) 120 int ret; 121 char port[6]; 122 struct addrinfo hints; 123 124 g_snprintf(port, sizeof(port), "%d", port_); 125 126 memset(&hints, 0, sizeof(struct addrinfo)); 127 hints.ai_family = AF_UNSPEC; 128 hints.ai_socktype = SOCK_STREAM; 129 hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV; 130 131 if (!(ret = getaddrinfo(host, port, &hints, &phb->gai))) 132 phb->gai_cur = phb->gai; 133 else 134 event_debug("gai(): %s\n", gai_strerror(ret)); 135 } 136 137 for (; phb->gai_cur; phb->gai_cur = phb->gai_cur->ai_next) 138 { 139 if ((fd = socket(phb->gai_cur->ai_family, phb->gai_cur->ai_socktype, phb->gai_cur->ai_protocol)) < 0) { 140 event_debug( "socket failed: %d\n", errno); 141 continue; 142 } 143 144 sock_make_nonblocking(fd); 145 146 if (global.conf->iface_out) 113 147 { 114 if ((fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0) { 115 event_debug( "socket failed: %d\n", errno); 116 continue; 117 } 118 119 sock_make_nonblocking(fd); 120 121 if (global.conf->iface_out) 122 { 123 me.sin_family = AF_INET; 124 me.sin_port = 0; 125 me.sin_addr.s_addr = inet_addr( global.conf->iface_out ); 148 me.sin_family = AF_INET; 149 me.sin_port = 0; 150 me.sin_addr.s_addr = inet_addr( global.conf->iface_out ); 126 151 127 if (bind(fd, (struct sockaddr *) &me, sizeof(me)) != 0) 128 event_debug("bind( %d, \"%s\" ) failure\n", fd, global.conf->iface_out); 129 } 130 131 event_debug("proxy_connect_none( \"%s\", %d ) = %d\n", host, port, fd); 132 133 if (connect(fd, rp->ai_addr, rp->ai_addrlen) < 0 && !sockerr_again()) { 134 event_debug( "connect failed: %s\n", strerror(errno)); 135 closesocket(fd); 136 fd = -1; 137 continue; 138 } else { 139 phb->inpa = b_input_add(fd, B_EV_IO_WRITE, gaim_io_connected, phb); 140 phb->fd = fd; 141 142 break; 143 } 144 } 145 146 freeaddrinfo(result); 147 } 148 else 149 { 150 event_debug("gai(): %s\n", gai_strerror(ret)); 151 } 152 153 if(fd < 0) 152 if (bind(fd, (struct sockaddr *) &me, sizeof(me)) != 0) 153 event_debug("bind( %d, \"%s\" ) failure\n", fd, global.conf->iface_out); 154 } 155 156 event_debug("proxy_connect_none( \"%s\", %d ) = %d\n", host, port, fd); 157 158 if (connect(fd, phb->gai_cur->ai_addr, phb->gai_cur->ai_addrlen) < 0 && !sockerr_again()) { 159 event_debug( "connect failed: %s\n", strerror(errno)); 160 closesocket(fd); 161 fd = -1; 162 continue; 163 } else { 164 phb->inpa = b_input_add(fd, B_EV_IO_WRITE, gaim_io_connected, phb); 165 phb->fd = fd; 166 167 break; 168 } 169 } 170 171 if(fd < 0 && host) 154 172 g_free(phb); 155 173
Note: See TracChangeset
for help on using the changeset viewer.