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 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 | #include <stdlib.h>
35 | #include <errno.h>
36 | #include <netdb.h>
37 |
38 | #include <signal.h>
39 | #include <stdio.h>
40 |
41 | #include <iproutines.h>
42 |
43 | /* connection data -> helps keep track of all errors etc */
44 | typedef struct {
45 | int sock; /* socket descriptor # */
46 | unsigned short rd_timeout; /* preset timeout values */
47 | unsigned short wr_timeout;
48 | unsigned short rtc; /* RTC flags (reason-to-close) */
49 | unsigned char lasterr; /* timeout, interrupt, etc. */
50 | ip_addr_t rIP; /* real IP */
51 | ip_addr_t eIP; /* effective IP */
52 | char *ip; /* text of the eIP */
53 | } sk_conn_st;
54 |
55 | /* reasons to close: socket-wise .... */
56 | #define SK_DISCONNECT 0x0001
57 | #define SK_INTERRUPT 0x0002
58 | #define SK_TIMEOUT 0x0004
59 |
60 | /* ... and user-wise: */
61 | #define SK_NOTEXT 0x0100
62 |
63 | int SK_atoport(const char *service, const char *proto);
64 | void SK_close(int socket);
65 | int SK_getsock(int socket_type, u_short port, uint32_t bind_address);
66 | int SK_accept_connection(int listening_socket);
67 | int SK_read(int sockfd, char *buf, size_t count);
68 | int SK_write(int sockfd, const char *buf, size_t count);
69 | int SK_gets(int sockfd, char *str, size_t count);
70 | int SK_puts(int sockfd, const char *str);
71 | int SK_putc(int sockfd, char ch);
72 | int SK_getc(int sockfd);
73 | char *SK_getpeername(int sockfd);
74 | int SK_getpeerip(int sockfd, ip_addr_t *ip);
75 | int SK_cd_puts(sk_conn_st *condat, const char *str);
76 | int SK_cd_gets(sk_conn_st *condat, char *str, size_t count);
77 | int SK_cd_close(sk_conn_st *condat);
78 |
79 | #endif /* READ_SOCKET */