include/sk.h
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
1 #ifndef READ_SOCKET
2 #define READ_SOCKET
3 /***************************************
4 $Revision: 1.10 $
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 /* connection data -> helps keep track of all errors etc */
58 typedef struct {
59 int sock; /* socket descriptor # */
60 struct timeval rd_timeout; /* preset timeout values */
61 struct timeval wr_timeout;
62 unsigned short rtc; /* RTC flags (reason-to-close) */
63
64 pthread_t watchdog; /* thread id of the watchdog associated */
65 pthread_t killthis; /* thread to be killed by watchdog */
66 void * (*execthis)(void *); /* function to be called if watchdog triggers */
67 void * execargs; /* argument to be passed to that function */
68 pthread_mutex_t watchmutex;
69
70 unsigned char lasterr; /* timeout, interrupt, etc. */
71 ip_addr_t rIP; /* real IP */
72 ip_addr_t eIP; /* effective IP */
73 char *ip; /* text of the eIP */
74 } sk_conn_st;
75
76 /* reasons to close: socket-wise .... */
77 #define SK_DISCONNECT 0x0001
78 #define SK_INTERRUPT 0x0002
79 #define SK_TIMEOUT 0x0004
80
81 /* ... and user-wise: */
82 #define SK_NOTEXT 0x0100
83
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87
88
89 int SK_atoport(const char *service, const char *proto);
90 int SK_close(int socket);
91 int SK_getsock(int socket_type, unsigned port, int backlog, uint32_t bind_address);
92 er_ret_t SK_connect(int *sock, char *hostname, unsigned port, unsigned timeout);
93 int SK_accept_connection(int listening_socket);
94 int SK_read(int sockfd, char *buf, size_t count);
95 int SK_write(int sockfd,
96 const char *buf,
97 int count,
98 const struct timeval *timeout,
99 int *count_sent);
100 int SK_gets(int sockfd, char *str, size_t count);
101 int SK_puts(int sockfd, const char *str, const struct timeval *timeout);
102 int SK_putc(int sockfd, char ch, const struct timeval *timeout);
103 int SK_getc(int sockfd);
104 char *SK_getpeername(int sockfd);
105 int SK_getpeerip(int sockfd, ip_addr_t *ip);
106
107 void SK_cd_make(sk_conn_st *condat, int sock, unsigned timeout);
108 void SK_cd_free(sk_conn_st *condat);
109 int SK_cd_puts(sk_conn_st *condat, const char *str);
110 int SK_cd_gets(sk_conn_st *condat, char *str, size_t count);
111 int SK_cd_close(sk_conn_st *condat);
112 int SK_cd_printf(sk_conn_st *condat, char *txt, ...)
113 #ifdef __GNUC__ /* let gcc check the format string for problems */
114 __attribute__ ((format (printf, 2, 3)))
115 #endif
116 ;
117 void SK_init(void);
118
119 er_ret_t SK_watchstart(sk_conn_st *condat);
120 er_ret_t SK_watchstop(sk_conn_st *condat);
121 void SK_watch_setkill(sk_conn_st *condat, pthread_t killthis);
122 void SK_watch_setexec( sk_conn_st *condat, void *(*function)(void *), void *args);
123 void SK_watch_setclear(sk_conn_st *condat);
124 void SK_watchexec(sk_conn_st *condat);
125 void SK_watchkill(sk_conn_st *condat);
126 void SK_watchtrigger(sk_conn_st *condat);
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif /* READ_SOCKET */