28 |
#include <stdio.h> |
#include <stdio.h> |
29 |
#include <stdlib.h> |
#include <stdlib.h> |
30 |
#include <string.h> |
#include <string.h> |
31 |
|
#include <errno.h> |
32 |
|
|
33 |
#include <sys/types.h> |
#include <sys/types.h> |
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 <netdb.h> |
#include <netdb.h> |
38 |
|
#include <fcntl.h> |
39 |
|
|
40 |
#include "options.h" |
#include "options.h" |
41 |
#include "access.h" |
#include "access.h" |
42 |
|
#include "log.h" |
43 |
#include "cable/cable.h" |
#include "cable/cable.h" |
44 |
|
#include "tcpip/tcpip.h" |
|
static int cablefd = -1; |
|
45 |
|
|
46 |
const access_t cable_access = (access_t) { |
const access_t cable_access = (access_t) { |
47 |
cable_connect, |
cable_connect, |
48 |
cable_close, |
cable_close, |
49 |
cable_connected, |
cable_connected, |
50 |
&cablefd |
&tcpipfd |
51 |
}; |
}; |
52 |
|
|
53 |
|
|
55 |
int |
int |
56 |
cable_connect () |
cable_connect () |
57 |
{ |
{ |
58 |
int port = PARAM_CABLE_AOL_PORT; |
return tcpip_connect(); |
|
char *hostname = PARAM_CABLE_AOL_HOST; |
|
|
|
|
|
struct sockaddr_in intcable; |
|
|
struct hostent *hp; |
|
|
|
|
|
if ((hp = gethostbyname (hostname)) == 0) |
|
|
{ |
|
|
perror ("error gethostbyname() !\n"); |
|
|
return 1; |
|
|
} |
|
|
memset ((char *) &intcable, 0, sizeof (struct sockaddr_in)); |
|
|
intcable.sin_family = AF_INET; |
|
|
intcable.sin_port = htons (port); |
|
|
intcable.sin_addr.s_addr = *((unsigned long *) hp->h_addr); |
|
|
/* strcpy(PARAM_CABLE_CONNECT_IP,inet_ntoa(adresse)); */ |
|
|
|
|
|
if ((cablefd = socket (PF_INET, SOCK_STREAM, 0)) < 0) |
|
|
{ |
|
|
perror ("error while opening socket !\n"); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
|
|
|
if (connect (cablefd, (struct sockaddr *) &intcable, |
|
|
sizeof (struct sockaddr_in)) == 0) |
|
|
return 1; |
|
|
|
|
|
return 0; |
|
59 |
} |
} |
60 |
|
|
61 |
int |
int |
62 |
cable_close () |
cable_close () |
63 |
{ |
{ |
64 |
if (cablefd != -1) |
return tcpip_close(); |
|
{ |
|
|
if ((close (cablefd)) == -1) |
|
|
{ |
|
|
perror ("error closing socket !\n"); |
|
|
return 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
perror ("error closing socket !\n"); |
|
|
return 1; |
|
65 |
} |
} |
66 |
|
|
67 |
int |
int |
68 |
cable_connected () |
cable_connected () |
69 |
{ |
{ |
70 |
return 0; |
return tcpip_connected(); |
71 |
} |
} |
72 |
|
|
73 |
#endif |
#endif |