Copied missing files from the subversion repository.
[collectd.git] / src / libping / sock.h
1 /**
2  * LIBPING socket header file
3  *
4  * Copyright (C) 2000, 2001, 2002 by
5  * Jeffrey Fulmer - <jdfulmer@armstrong.com>
6  * This file is distributed as part of libping
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 #ifndef SOCK_H
23 #define SOCK_H
24
25 #ifdef  HAVE_ARPA_INET_H
26 # include <arpa/inet.h>
27 #endif/*HAVE_ARPA_INET_H*/
28  
29 #ifdef  HAVE_SYS_SOCKET_H
30 # include <sys/socket.h>
31 #endif/*HAVE_SYS_SOCKET_H*/
32
33 #ifdef  HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif/*HAVE_UNISTD_H*/ 
36  
37 #ifdef  HAVE_NETINET_IN_H
38 # include <netinet/in.h>
39 #endif/*HAVE_NETINET_IN_H*/
40
41 #ifdef HAVE_SYS_TIMES_H
42 # include <sys/times.h>
43 #endif /*HAVE_SYS_TIMES_H*/
44 #if TIME_WITH_SYS_TIME
45 # include <sys/time.h>
46 # include <time.h>
47 #else
48 # if HAVE_SYS_TIME_H
49 #  include <sys/time.h>
50 # else
51 #  include <time.h>
52 # endif
53 #endif/*TIME_WITH_SYS_TIME*/ 
54  
55 #ifdef  HAVE_NETDB_H
56 # include <netdb.h>
57 #endif/*HAVE_NETDB_H*/ 
58
59 #ifdef  HAVE_SSL
60 # include <openssl/ssl.h>
61 # include <openssl/err.h>
62 # include <openssl/rsa.h>
63 # include <openssl/crypto.h>
64 # include <openssl/x509.h>
65 # include <openssl/pem.h>
66 #endif/*HAVE_SSL*/
67
68 #include <url.h>
69
70 typedef enum
71 {
72   S_CONNECTING = 1,
73   S_READING    = 2,
74   S_WRITING    = 4,
75   S_DONE       = 8
76 } STATUS; 
77
78 typedef enum
79 {
80   READ  = 0,
81   WRITE = 1,
82   RDWR  = 2
83 } SDSET;  
84
85 typedef struct
86 {
87   int      sock;
88   int      port;
89   int      timeout;
90   STATUS   status;
91   PROTOCOL prot;
92 #ifdef  HAVE_SSL
93   SSL      *ssl;
94   SSL_CTX  *ctx;
95 #endif/*HAVE_SSL*/
96   fd_set   rset;
97   fd_set   wset;
98 } CONN; 
99
100 /**
101  * create socket 
102  * const char *hostname
103  * const char *service
104  */
105 int JOEsocket( CONN *conn, const char *hostname );
106
107 /**
108  * checks the socket for both
109  * readability, writeability or both.
110  */
111 int JOEsocket_check( CONN *C, SDSET S );
112
113 /** 
114  * write int sock 
115  * from char *buf, 
116  * unsigned int length 
117  */
118 int JOEsocket_write( CONN *conn, const void *b, size_t n );
119
120 /** 
121  * read int sock, 
122  * into void *buf, 
123  * size_t length 
124  */
125 ssize_t JOEread_byte( CONN *conn, void *buf, size_t len ); 
126 ssize_t JOEreadline( CONN *C, char *ptr, size_t len ); 
127 ssize_t JOEsocket_read( CONN *conn, void *buf, size_t len ); 
128
129 /** 
130  * close int socket 
131  */
132 void JOEclose( CONN *C );
133
134 #endif /* SOCK_H */
135