]>
jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscanconnect.c
1 /* proxyscanconnect: handle connections etc. */
6 #include <sys/socket.h>
7 #include <netinet/in.h>
9 #include "../core/error.h"
10 #include <sys/ioctl.h>
13 int createconnectsocket(long ip
, int socknum
) {
15 struct sockaddr_in sin
;
19 memset(&sin
,0,sizeof(sin
));
21 sin
.sin_family
=AF_INET
;
22 sin
.sin_port
=htons(socknum
);
23 sin
.sin_addr
.s_addr
=htonl(ip
);
25 if ((fd
=socket(AF_INET
,SOCK_STREAM
,0))<0) {
26 Error("proxyscan",ERR_ERROR
,"Unable to create socket (%d)",errno
);
29 if (ioctl(fd
,FIONBIO
,&res
)!=0) {
30 Error("proxyscan",ERR_ERROR
,"Unable to make socket nonblocking");
33 if (setsockopt(fd
, SOL_SOCKET
, SO_REUSEADDR
, (const char *) &opt
, sizeof(opt
))!=0) {
34 Error("proxyscan",ERR_ERROR
,"Unable to set SO_REUSEADDR on scan socket.");
38 opt
=IP_PORTRANGE_HIGH
;
39 if (setsockopt(fd
, IPPROTO_IP
, IP_PORTRANGE
, (char *) &opt
, sizeof(opt
))!=0) {
40 Error("proxyscan",ERR_WARNING
,"Error selecting high port range.");
43 if (connect(fd
,(const struct sockaddr
*) &sin
, sizeof(sin
))) {
44 if (errno
!= EINPROGRESS
) {
45 Error("proxyscan",ERR_ERROR
,"Unable to connect socket (%d)",errno
);