34 |
#include <sys/socket.h> |
#include <sys/socket.h> |
35 |
#include <net/if.h> |
#include <net/if.h> |
36 |
#include <netinet/in.h> |
#include <netinet/in.h> |
37 |
|
#include <arpa/inet.h> |
38 |
#include <netdb.h> |
#include <netdb.h> |
39 |
#include <fcntl.h> |
#include <fcntl.h> |
40 |
|
|
58 |
{ |
{ |
59 |
int port = PARAM_CABLE_AOL_PORT; |
int port = PARAM_CABLE_AOL_PORT; |
60 |
char *hostname = PARAM_CABLE_AOL_HOST; |
char *hostname = PARAM_CABLE_AOL_HOST; |
|
int address; |
|
61 |
|
|
62 |
struct sockaddr_in intcable; |
struct sockaddr_in aol_addr; |
63 |
|
struct in_addr address; |
64 |
struct hostent *hp; |
struct hostent *hp; |
65 |
|
|
66 |
log(LOG_NOTICE, "Resolving %s...\n", hostname); |
if( !inet_aton(hostname, &address) ) |
|
if ((hp = gethostbyname (hostname)) == 0) |
|
67 |
{ |
{ |
68 |
log (LOG_ERR, "Unable to resolve %s: %s (%d)\n",hostname, |
log(LOG_NOTICE, "Resolving %s...\n", hostname); |
69 |
strerror(errno), errno); |
if ((hp = gethostbyname (hostname)) == 0) |
70 |
return 0; |
{ |
71 |
|
log (LOG_ERR, "Unable to resolve %s: %s (%d)\n", hostname, |
72 |
|
hstrerror(h_errno), h_errno); |
73 |
|
return 0; |
74 |
|
} |
75 |
|
address.s_addr= *((unsigned long *) hp->h_addr_list[0]); |
76 |
} |
} |
77 |
memset ((char *) &intcable, 0, sizeof (struct sockaddr_in)); |
|
78 |
intcable.sin_family = AF_INET; |
memset ((char *) &aol_addr, 0, sizeof (struct sockaddr_in)); |
79 |
intcable.sin_port = htons (port); |
aol_addr.sin_family = AF_INET; |
80 |
intcable.sin_addr.s_addr = *((unsigned long *) hp->h_addr); |
aol_addr.sin_port = htons (port); |
81 |
address = ntohl(intcable.sin_addr.s_addr); |
aol_addr.sin_addr = address; |
|
/* strcpy(PARAM_CABLE_CONNECT_IP,inet_ntoa(adress)); */ |
|
82 |
|
|
83 |
if ((tcpipfd = socket (PF_INET, SOCK_STREAM, 0)) < 0) |
if ((tcpipfd = socket (PF_INET, SOCK_STREAM, 0)) < 0) |
84 |
{ |
{ |
87 |
return 0; |
return 0; |
88 |
} |
} |
89 |
|
|
90 |
log(LOG_NOTICE,"Connecting to %d.%d.%d.%d:%d ...\n", |
log(LOG_NOTICE,"Connecting to %s:%d ...\n", inet_ntoa(aol_addr.sin_addr), |
|
address>>24 & 0xff, address>>16 & 0xff, address>>8 & 0xff, address & 0xff, |
|
91 |
port); |
port); |
92 |
|
|
93 |
if (connect (tcpipfd, (struct sockaddr *) &intcable, |
if (connect (tcpipfd, (struct sockaddr *) &aol_addr, |
94 |
sizeof (struct sockaddr_in)) == -1) |
sizeof (struct sockaddr_in)) == -1) |
95 |
{ |
{ |
96 |
log (LOG_ERR, "Error while connecting to AOL: %s (%d)\n",strerror(errno), |
log (LOG_ERR, "Error while connecting to AOL: %s (%d)\n",strerror(errno), |