"Fossies" - the Fresh Open Source Software Archive
Member "msmtp-1.8.17/src/net.h" (16 Dec 2020, 6040 Bytes) of package /linux/privat/msmtp-1.8.17.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard
) with prefixed line numbers and code folding
Alternatively you can here view
the uninterpreted source code file.
For more information about "net.h" see the Fossies "Dox" file reference
documentation and the last Fossies "Diffs"
side-by-side code changes report: 1.8.13_vs_1.8.14
2 * net.h
4 * This file is part of msmtp, an SMTP client, and of mpop, a POP3 client.
6 * Copyright (C) 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2014, 2018, 2019,
7 * 2020
8 * Martin Lambers <email@example.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef NET_H
25 #define NET_H
27 #include <stddef.h>
29 #include "readbuf.h"
33 * If a function with an 'errstr' argument returns a value != NET_EOK,
34 * '*errstr' either points to an allocates string containing an error
35 * description or is NULL.
36 * If such a function returns NET_EOK, 'errstr' will not be changed.
38 #define NET_EOK 0 /* no error */
39 #define NET_ELIBFAILED 1 /* The underlying library failed */
40 #define NET_EHOSTNOTFOUND 2 /* Host not found */
41 #define NET_ESOCKET 3 /* Cannot create socket */
42 #define NET_ECONNECT 4 /* Cannot connect */
43 #define NET_EIO 5 /* Input/output error */
44 #define NET_EPROXY 6 /* Proxy failure */
45 #define NET_ESRVNOTFOUND 7 /* SRV record not found */
48 * net_lib_init()
50 * Initializes the networking libraries. If this function returns
51 * NET_ELIBFAILED, *errstr will always point to an error string.
52 * Used error codes: NET_ELIBFAILED
54 int net_lib_init(char **errstr);
57 * net_open_socket()
59 * Opens a TCP socket to 'hostname':'port'.
60 * 'proxy_hostname' and 'proxy_port' define a SOCKS5 proxy to use, unless they
61 * are NULL/-1, in which case no proxy will be used.
62 * If 'socketname' is not NULL, it overrides both 'hostname':'port' and 'proxy_*' by
63 * specifying the file name of a local socket to connect to.
64 * 'hostname' may be a host name or a network address.
65 * 'source_ip' may be NULL or a string representation of an IPv6 or IPv4 address
66 * that will be bound as the source address for the outgoing connection.
67 * 'timeout' is measured in secondes. If it is <= 0, no timeout will be set,
68 * which means that the OS dependent default timeout value will be used.
69 * The timeout will not only apply to the connection attempt but also to all
70 * following read/write operations on the socket.
71 * If 'canonical_name' is not NULL, a pointer to a string containing the
72 * canonical hostname of the server will be stored in '*canonical_name', or NULL
73 * if this information is not available.
74 * If 'address' is not NULL, a pointer to a string containing the network
75 * address of the server will be stored in '*address', or NULL if this
76 * information is not available.
77 * The strings must be deallocated when not used anymore.
78 * The file descriptor is returned in 'fd'. It can be closed with close().
80 * Used error codes: NET_EHOSTNOTFOUND, NET_ESOCKET, NET_ECONNECT, NET_EPROXY
82 int net_open_socket(
83 const char *socketname,
84 const char *proxy_hostname, int proxy_port,
85 const char *hostname, int port,
86 const char *source_ip,
87 int timeout,
88 int *fd, char **canonical_name, char **address,
89 char **errstr);
92 * net_gets()
94 * Reads in at most one less than 'size' characters from 'fd' and stores them
95 * into the buffer pointed to by 'str'. Reading stops after an EOF or a newline.
96 * If a newline is read, it is stored into the buffer. A '\0' is stored after
97 * the last character in the buffer. The length of the resulting string (the
98 * number of characters excluding the terminating '\0') will be stored in 'len'.
99 * 'readbuf' will be used as an input buffer and must of course be the same for
100 * all read operations on 'fd'.
101 * Used error codes: NET_EIO
103 int net_gets(int fd, readbuf_t *readbuf,
104 char *str, size_t size, size_t *len, char **errstr);
107 * net_puts()
109 * Writes 'len' characters from the string 's' to 'fd'.
110 * Used error codes: NET_EIO
112 int net_puts(int fd, const char *s, size_t len, char **errstr);
115 * net_close_socket()
117 * Closes a socket.
119 void net_close_socket(int fd);
122 * net_get_canonical_hostname()
124 * Get a canonical host name. This means that the name is meaningful to
125 * other hosts. Usually, it is the fully qualified domain name.
127 * You can optionally specify a hostname to try and canonicalize; if this is
128 * NULL, the name of the local host is used.
130 char *net_get_canonical_hostname(const char *hostname);
133 * net_get_srv_query()
135 * Construct a SRV record query for the given service at the given domain.
136 * For example, with service "pop3s" and domain "example.com", this function
137 * returns the SRV query "_pop3._tcp.example.com" as an allocated string.
139 char* net_get_srv_query(const char *domain, const char *service);
142 * net_get_srv()
144 * Fetches a SRV record for the given query string (typically constructed with
145 * net_get_srv_query()), and returns its hostname and port.
146 * If more than one matching SRV record exists, this chooses the record based
147 * on its priority and weight.
148 * Used error codes:
149 * - NET_ELIBFAILED: libresolv is missing so we cannot get SRV records
150 * - NET_ESRVNOTFOUND: the SRV record was not found
151 * - NET_EIO: a SRV record was found but could not be interpreted
153 int net_get_srv_record(const char* query, char **hostname, int *port);
156 * net_lib_deinit()
158 * Deinit networking library
160 void net_lib_deinit(void);
163 * net_exitcode()
165 * Translate NET_* error code to an error code from sysexits.h
167 int net_exitcode(int net_error_code);