1 | #ifndef READ_SOCKET
2 | #define READ_SOCKET
3 | /***************************************
4 | $Revision: 1.1 $
5 |
6 | Socket module (sk)
7 |
8 | Status: NOT REVUED, NOT TESTED
9 |
10 | ******************/ /******************
11 | Copyright (c) 1999 RIPE NCC
12 |
13 | All Rights Reserved
14 |
15 | Permission to use, copy, modify, and distribute this software and its
16 | documentation for any purpose and without fee is hereby granted,
17 | provided that the above copyright notice appear in all copies and that
18 | both that copyright notice and this permission notice appear in
19 | supporting documentation, and that the name of the author not be
20 | used in advertising or publicity pertaining to distribution of the
21 | software without specific, written prior permission.
22 |
23 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
25 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
26 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
28 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 | ***************************************/
30 | #include <sys/types.h>
31 | #include <sys/socket.h>
32 | #include <netinet/in.h>
33 |
34 | #ifdef _LINUX
35 | #include <sys/time.h>
36 | #include <unistd.h>
37 | #include <pthread.h>
38 | #endif
39 |
40 | #include <stdlib.h>
41 | #include <errno.h>
42 | #include <netdb.h>
43 |
44 | #include <signal.h>
45 | #include <stdio.h>
46 |
47 | #include <iproutines.h>
48 |
49 | /* connection data -> helps keep track of all errors etc */
50 | typedef struct {
51 | int sock; /* socket descriptor # */
52 | struct timeval rd_timeout; /* preset timeout values */
53 | struct timeval wr_timeout;
54 | unsigned short rtc; /* RTC flags (reason-to-close) */
55 |
56 | pthread_t watchdog; /* thread id of the watchdog associated */
57 | pthread_t killthis; /* thread to be killed by watchdog */
58 | void * (*execthis)(void *); /* function to be called if watchdog triggers */
59 | void * execargs; /* argument to be passed to that function */
60 | pthread_mutex_t watchmutex;
61 |
62 | unsigned char lasterr; /* timeout, interrupt, etc. */
63 | ip_addr_t rIP; /* real IP */
64 | ip_addr_t eIP; /* effective IP */
65 | char *ip; /* text of the eIP */
66 | } sk_conn_st;
67 |
68 | /* reasons to close: socket-wise .... */
69 | #define SK_DISCONNECT 0x0001
70 | #define SK_INTERRUPT 0x0002
71 | #define SK_TIMEOUT 0x0004
72 |
73 | /* ... and user-wise: */
74 | #define SK_NOTEXT 0x0100
75 |
76 | int SK_atoport(const char *service, const char *proto);
77 | int SK_close(int socket);
78 | int SK_getsock(int socket_type, u_short port, uint32_t bind_address);
79 | int SK_accept_connection(int listening_socket);
80 | int SK_read(int sockfd, char *buf, size_t count);
81 | int SK_write(int sockfd, const char *buf, size_t count);
82 | int SK_gets(int sockfd, char *str, size_t count);
83 | int SK_puts(int sockfd, const char *str);
84 | int SK_putc(int sockfd, char ch);
85 | int SK_getc(int sockfd);
86 | char *SK_getpeername(int sockfd);
87 | int SK_getpeerip(int sockfd, ip_addr_t *ip);
88 | int SK_cd_puts(sk_conn_st *condat, const char *str);
89 | int SK_cd_gets(sk_conn_st *condat, char *str, size_t count);
90 | int SK_cd_close(sk_conn_st *condat);
91 | int SK_cd_printf(sk_conn_st *condat, char *txt, ...)
92 | #ifdef __GNUC__ /* let gcc check the format string for problems */
93 | __attribute__ ((format (printf, 2, 3)))
94 | #endif
95 | ;
96 | void SK_init(void);
97 |
98 | #endif /* READ_SOCKET */
99 |
100 | er_ret_t SK_watchstart(sk_conn_st *condat);
101 | er_ret_t SK_watchstop(sk_conn_st *condat);
102 | void SK_watch_setkill(sk_conn_st *condat, pthread_t killthis);
103 | void SK_watch_setexec( sk_conn_st *condat, void *(*function)(void *), void *args);
104 | void SK_watch_setclear(sk_conn_st *condat);
105 | void SK_watchexec(sk_conn_st *condat);
106 | void SK_watchkill(sk_conn_st *condat);
107 | void SK_watchtrigger(sk_conn_st *condat);