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