/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following functions.
- sk_conn_st
1 #ifndef READ_SOCKET
2 #define READ_SOCKET
3 /***************************************
4 $Revision: 1.11 $
5
6 Socket module (sk)
7
8 Status: NOT REVUED, NOT TESTED
9
10 ******************/ /******************
11 Copyright (c) 1999,2000,2001,2002 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
31 #include "stubs.h"
32
33 #ifdef HAVE_SYS_TIME_H
34 #include <sys/time.h>
35 #endif /* HAVE_SYS_TIME_H */
36
37 #ifdef HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif /* HAVE_UNISTD_H */
40
41 /* #include <arpa/inet.h> */
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <netdb.h>
46
47 #include <pthread.h>
48 #include <stdlib.h>
49 #include <errno.h>
50 #include <fcntl.h>
51
52 #include <signal.h>
53 #include <stdio.h>
54
55 #include "iproutines.h"
56
57 /* maximum amount of input data to buffer */
58 #define INPUT_BUF_LEN 2048
59
60 /* connection data -> helps keep track of all errors etc */
61 typedef struct {
62 int sock; /* socket descriptor # */
63 struct timeval rd_timeout; /* preset timeout values */
64 struct timeval wr_timeout;
65 unsigned short rtc; /* RTC flags (reason-to-close) */
66
67 pthread_t watchdog; /* thread id of the watchdog associated */
68 pthread_t killthis; /* thread to be killed by watchdog */
69 void * (*execthis)(void *); /* function to be called if watchdog triggers */
70 void * execargs; /* argument to be passed to that function */
71 pthread_mutex_t watchmutex;
72
73 unsigned char lasterr; /* timeout, interrupt, etc. */
74 ip_addr_t rIP; /* real IP */
75 ip_addr_t eIP; /* effective IP */
76 char *ip; /* text of the eIP */
77
78 char rd_buf[INPUT_BUF_LEN]; /* buffer for input */
79 int rd_buf_len; /* number of characters in input buffer */
80 } sk_conn_st;
/* [<][>][^][v][top][bottom][index][help] */
81
82 /* reasons to close: socket-wise .... */
83 #define SK_DISCONNECT 0x0001
84 #define SK_INTERRUPT 0x0002
85 #define SK_TIMEOUT 0x0004
86
87 /* ... and user-wise: */
88 #define SK_NOTEXT 0x0100
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94
95 int SK_atoport(const char *service, const char *proto);
96 int SK_close(int socket);
97 int SK_getsock(int socket_type, unsigned port, int backlog, uint32_t bind_address);
98 er_ret_t SK_connect(int *sock, char *hostname, unsigned port, unsigned timeout);
99 int SK_accept_connection(int listening_socket);
100 /*int SK_read(int sockfd, char *buf, size_t count);*/
101 int SK_write(int sockfd,
102 const char *buf,
103 int count,
104 const struct timeval *timeout,
105 int *count_sent);
106 /*int SK_gets(int sockfd, char *str, size_t count);*/
107 int SK_puts(int sockfd, const char *str, const struct timeval *timeout);
108 int SK_putc(int sockfd, char ch, const struct timeval *timeout);
109 /*int SK_getc(int sockfd);*/
110 char *SK_getpeername(int sockfd);
111 int SK_getpeerip(int sockfd, ip_addr_t *ip);
112
113 void SK_cd_make(sk_conn_st *condat, int sock, unsigned timeout);
114 void SK_cd_free(sk_conn_st *condat);
115 int SK_cd_puts(sk_conn_st *condat, const char *str);
116 int SK_cd_gets(sk_conn_st *condat, char *str, size_t count);
117 int SK_cd_close(sk_conn_st *condat);
118 int SK_cd_printf(sk_conn_st *condat, char *txt, ...)
119 #ifdef __GNUC__ /* let gcc check the format string for problems */
120 __attribute__ ((format (printf, 2, 3)))
121 #endif
122 ;
123 void SK_init(void);
124
125 er_ret_t SK_watchstart(sk_conn_st *condat);
126 er_ret_t SK_watchstop(sk_conn_st *condat);
127 void SK_watch_setkill(sk_conn_st *condat, pthread_t killthis);
128 void SK_watch_setexec( sk_conn_st *condat, void *(*function)(void *), void *args);
129 void SK_watch_setclear(sk_conn_st *condat);
130 void SK_watchexec(sk_conn_st *condat);
131 void SK_watchkill(sk_conn_st *condat);
132 void SK_watchtrigger(sk_conn_st *condat);
133
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif /* READ_SOCKET */