Lines 138-172
Link Here
|
138 |
return retval; |
138 |
return retval; |
139 |
} |
139 |
} |
140 |
|
140 |
|
141 |
/*---------------------------------------------*/ |
|
|
142 |
struct hostent *get_hostent(const char *host) { |
143 |
struct in_addr saddr; |
144 |
int c; |
145 |
struct hostent *hi = NULL; |
146 |
|
147 |
if(host==NULL) { |
148 |
error_log(ERRLOG_REPORT,both_phrases[0], NULL); |
149 |
} |
150 |
else { |
151 |
c=*host; |
152 |
if(isdigit(c)) { |
153 |
saddr.s_addr = inet_addr(host); |
154 |
hi = gethostbyaddr((char *)&saddr,sizeof(struct in_addr),AF_INET); |
155 |
} |
156 |
else { |
157 |
hi = gethostbyname(host); |
158 |
} |
159 |
} |
160 |
return hi; |
161 |
} |
162 |
/*--------------------------------------------*/ |
141 |
/*--------------------------------------------*/ |
163 |
int connect_to_nntphost(const char *host, struct hostent **hi, FILE *msgs, unsigned short int portnr, int do_ssl, void **ssl) { |
142 |
int connect_to_nntphost(const char *host, char *hname, size_t hnlength, FILE *msgs, unsigned short int portnr, int do_ssl, void **ssl) |
164 |
char *ptr, *realhost; |
143 |
{ |
165 |
struct in_addr *aptr; |
144 |
char *realhost, *pport; |
166 |
struct in_addr saddr; |
|
|
167 |
struct sockaddr_in address; |
168 |
char sport[10]; |
145 |
char sport[10]; |
169 |
int sockfd = -1; |
146 |
struct addrinfo *l, hint = { 0 }; |
|
|
147 |
int r, sockfd = -1; |
170 |
|
148 |
|
171 |
#ifdef HAVE_LIBSSL |
149 |
#ifdef HAVE_LIBSSL |
172 |
SSL *ssl_struct = NULL; |
150 |
SSL *ssl_struct = NULL; |
Lines 184-248
Link Here
|
184 |
} |
162 |
} |
185 |
#endif |
163 |
#endif |
186 |
/* handle host:port type syntax */ |
164 |
/* handle host:port type syntax */ |
187 |
realhost = strdup(host); |
165 |
realhost = alloca(strlen(host) + 1); |
188 |
if(realhost == NULL) { |
166 |
strcpy(realhost, host); |
189 |
MyPerror("out of memory copying host name"); |
167 |
pport = strchr(realhost, ':'); |
190 |
return sockfd; |
168 |
if(pport != NULL) { |
191 |
} |
169 |
*pport = '\0'; /* null terminate host name */ |
192 |
ptr = strchr(realhost, ':'); |
170 |
++pport; /* get port number */ |
193 |
if(ptr != NULL) { |
171 |
} |
194 |
*ptr = '\0'; /* null terminate host name */ |
172 |
else |
195 |
portnr = atoi(++ptr); /* get port number */ |
173 |
{ |
196 |
} |
174 |
snprintf(sport, sizeof(sport), "%hu", portnr); /* cause print_phrases wants all strings */ |
197 |
|
175 |
pport = sport; |
198 |
|
176 |
} |
199 |
|
177 |
print_phrases(msgs, both_phrases[1], pport, NULL); |
200 |
sprintf(sport, "%hu", portnr); /* cause print_phrases wants all strings */ |
178 |
hint.ai_socktype = SOCK_STREAM; |
201 |
print_phrases(msgs, both_phrases[1], sport, NULL); |
179 |
hint.ai_flags = AI_ADDRCONFIG | AI_CANONNAME; |
202 |
|
180 |
r = getaddrinfo(realhost, pport, &hint, &l); |
203 |
/* Find the internet address of the NNTP server */ |
181 |
if(r != 0 || l == NULL) |
204 |
*hi = get_hostent(realhost); |
182 |
{ |
205 |
if(*hi == NULL) { |
|
|
206 |
error_log(ERRLOG_REPORT,"%v1%: ",realhost, NULL); |
183 |
error_log(ERRLOG_REPORT,"%v1%: ",realhost, NULL); |
207 |
MyPerror(both_phrases[2]); |
184 |
MyPerror(both_phrases[2]); |
208 |
free(realhost); |
|
|
209 |
} |
185 |
} |
210 |
else { |
186 |
else |
211 |
free(realhost); |
187 |
{ |
212 |
print_phrases(msgs, both_phrases[3], (*hi)->h_name, NULL); |
188 |
struct addrinfo *p = l; |
213 |
while((ptr = *((*hi)->h_aliases)) != NULL) { |
189 |
print_phrases(msgs, both_phrases[3], p->ai_canonname, NULL); |
214 |
print_phrases(msgs, both_phrases[4], ptr, NULL ); |
190 |
if((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) |
215 |
(*hi)->h_aliases++; |
191 |
{ |
216 |
} |
192 |
MyPerror(both_phrases[6]); |
217 |
if((*hi)->h_addrtype != AF_INET) { |
193 |
} |
218 |
error_log(ERRLOG_REPORT, both_phrases[5], NULL); |
194 |
else |
219 |
} |
195 |
{ |
220 |
else { |
196 |
if(connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) |
221 |
while((aptr = (struct in_addr *)*((*hi)->h_addr_list)++) != NULL) { |
197 |
{ |
222 |
saddr = *aptr; |
198 |
MyPerror(both_phrases[7]); |
223 |
print_phrases(msgs, both_phrases[17], inet_ntoa(*aptr), NULL); |
199 |
close(sockfd); |
224 |
} |
200 |
sockfd = -1; |
225 |
|
201 |
} |
226 |
/* Create a socket */ |
202 |
else |
227 |
if((sockfd = socket( AF_INET, SOCK_STREAM, SOCKET_PROTOCOL)) == -1) { |
203 |
{ |
228 |
MyPerror(both_phrases[6]); |
204 |
char lhost[256], lport[64]; |
229 |
} |
205 |
r = getnameinfo(p->ai_addr, p->ai_addrlen, lhost, sizeof(lhost), |
230 |
else { |
206 |
lport, sizeof(lport), 0); |
231 |
address.sin_family = AF_INET; |
207 |
if(r == 0) |
232 |
address.sin_port = htons(portnr); /* NNTP port */ |
208 |
{ |
233 |
address.sin_addr= saddr; |
209 |
print_phrases(msgs,both_phrases[8], lhost, NULL); |
234 |
|
210 |
if(hname && hnlength) |
235 |
/* Establish a connection */ |
211 |
{ |
236 |
if(connect(sockfd, (struct sockaddr *)&address, sizeof address ) == -1) { |
212 |
strncpy(hname, lhost, hnlength); |
237 |
MyPerror(both_phrases[7]); |
213 |
hname[hnlength] = '\0'; |
238 |
close(sockfd); |
214 |
} |
239 |
sockfd = -1; |
|
|
240 |
} |
241 |
else { |
242 |
print_phrases(msgs,both_phrases[8], (*hi)->h_name, NULL); |
243 |
} |
215 |
} |
244 |
} |
216 |
} |
245 |
} |
217 |
} |
|
|
218 |
freeaddrinfo(l); |
246 |
#ifdef HAVE_LIBSSL |
219 |
#ifdef HAVE_LIBSSL |
247 |
if(sockfd > -1 && do_ssl == TRUE) { |
220 |
if(sockfd > -1 && do_ssl == TRUE) { |
248 |
if((ssl_struct = SSL_new(test1)) == NULL) { |
221 |
if((ssl_struct = SSL_new(test1)) == NULL) { |