]> Pileus Git - ~andy/fetchmail/blob - socket.h
Add .mailmap file.
[~andy/fetchmail] / socket.h
1 /**
2  * \file 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 /** Sets the send/receive timeouts for socket \a sock to \a timeout
24  * seconds. \return zero on success. */
25 int SockTimeout(int sock, int timeout);
26
27 /** 
28 Get a string terminated by an '\n' (matches interface of fgets).
29 Pass it a valid socket, a buffer for the string, and
30 the length of the buffer (including the trailing \0)
31 returns length of buffer on success, -1 on failure. 
32 */
33 int SockRead(int sock, char *buf, int len);
34
35 /**
36  * Peek at the next socket character without actually reading it.
37  */
38 int SockPeek(int sock);
39
40 /**
41 Write a chunk of bytes to the socket (matches interface of fwrite).
42 Returns number of bytes successfully written.
43 */
44 int SockWrite(int sock, const char *buf, int size);
45
46 /* from /usr/include/sys/cdefs.h */
47 #if !defined __GNUC__ || __GNUC__ < 2
48 # define __attribute__(xyz)    /* Ignore. */
49 #endif
50
51 /**
52 Send formatted output to the socket (matches interface of fprintf).
53 Returns number of bytes successfully written.
54 */
55 #if defined(HAVE_STDARG_H)
56 int SockPrintf(int sock, const char *format, ...)
57     __attribute__ ((format (printf, 2, 3)))
58     ;
59 #else
60 int SockPrintf();
61 #endif
62  
63 /**
64 Close a socket previously opened by SockOpen.  This allows for some
65 additional clean-up if necessary.
66 */
67 int SockClose(int sock);
68
69 /**
70  \todo document this
71 */
72 int UnixOpen(const char *path);
73
74 #ifdef SSL_ENABLE
75 int SSLOpen(int sock, char *mycert, char *mykey, const char *myproto, int certck, char *cacertfile, char *cacertpath,
76     char *fingerprint, char *servercname, char *label, char **remotename);
77 #endif /* SSL_ENABLE */
78
79 #endif /* SOCKET__ */