]> Pileus Git - ~andy/fetchmail/blob - socket.h
Freeaddrinfo() fix for Uli Zappe's bug.
[~andy/fetchmail] / socket.h
1 /*
2  * socket.h -- declarations for socket library functions
3  *
4  * For license terms, see the file COPYING in this directory.
5  */
6
7 #ifndef SOCKET__
8 #define SOCKET__
9
10 #include <config.h>
11 #ifdef HAVE_SYS_SOCKET_H
12 #include <sys/socket.h>
13 #elif HAVE_NET_SOCKET_H
14 #include <net/socket.h>
15 #endif
16 #include <netdb.h>
17
18 /* Create a new client socket; returns -1 on error */
19 int SockOpen(const char *host, const char *service, const char *plugin, struct addrinfo **);
20
21 /* Returns 1 if this socket is OK, 0 if it isn't select()able
22  * on - probably because it's been closed. You should
23  * always check this function before passing stuff to the
24  * select()-based waiter, as otherwise it may loop. 
25  */
26 int SockCheckOpen(int fd);
27
28 /* 
29 Get a string terminated by an '\n' (matches interface of fgets).
30 Pass it a valid socket, a buffer for the string, and
31 the length of the buffer (including the trailing \0)
32 returns length of buffer on success, -1 on failure. 
33 */
34 int SockRead(int sock, char *buf, int len);
35
36 /*
37  * Peek at the next socket character without actually reading it.
38  */
39 int SockPeek(int sock);
40
41 /*
42 Write a chunk of bytes to the socket (matches interface of fwrite).
43 Returns number of bytes successfully written.
44 */
45 int SockWrite(int sock, char *buf, int size);
46
47 /* 
48 Send formatted output to the socket (matches interface of fprintf).
49 Returns number of bytes successfully written.
50 */
51 #if defined(HAVE_STDARG_H)
52 int SockPrintf(int sock, const char *format, ...) ;
53 #else
54 int SockPrintf();
55 #endif
56  
57 /*
58 Close a socket previously opened by SockOpen.  This allows for some
59 additional clean-up if necessary.
60 */
61 int SockClose(int sock);
62
63 /*
64 FIXME: document this
65 */
66 int UnixOpen(const char *path);
67
68 #ifdef SSL_ENABLE
69 int SSLOpen(int sock, char *mycert, char *mykey, char *myproto, int certck, char *certpath,
70     char *fingerprint, char *servercname, char *label);
71 #endif /* SSL_ENABLE */
72
73 #endif /* SOCKET__ */