"Fossies" - the Fresh Open Source Software Archive

Member "msmtp-1.8.5/src/net.h" (11 Jan 2019, 5712 Bytes) of package /linux/privat/msmtp-1.8.5.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 option. Alternatively you can here view or download 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.1_vs_1.8.2.

    1 /*
    2  * net.h
    3  *
    4  * This file is part of msmtp, an SMTP client, and of mpop, a POP3 client.
    5  *
    6  * Copyright (C) 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2014, 2018, 2019
    7  * Martin Lambers <marlam@marlam.de>
    8  *
    9  *   This program is free software; you can redistribute it and/or modify
   10  *   it under the terms of the GNU General Public License as published by
   11  *   the Free Software Foundation; either version 3 of the License, or
   12  *   (at your option) any later version.
   13  *
   14  *   This program is distributed in the hope that it will be useful,
   15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  *   GNU General Public License for more details.
   18  *
   19  *   You should have received a copy of the GNU General Public License
   20  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   21  */
   22 
   23 #ifndef NET_H
   24 #define NET_H
   25 
   26 #include "readbuf.h"
   27 
   28 
   29 /*
   30  * If a function with an 'errstr' argument returns a value != NET_EOK,
   31  * '*errstr' either points to an allocates string containing an error
   32  * description or is NULL.
   33  * If such a function returns NET_EOK, 'errstr' will not be changed.
   34  */
   35 #define NET_EOK                 0       /* no error */
   36 #define NET_ELIBFAILED          1       /* The underlying library failed */
   37 #define NET_EHOSTNOTFOUND       2       /* Host not found */
   38 #define NET_ESOCKET             3       /* Cannot create socket */
   39 #define NET_ECONNECT            4       /* Cannot connect */
   40 #define NET_EIO                 5       /* Input/output error */
   41 #define NET_EPROXY              6       /* Proxy failure */
   42 #define NET_ESRVNOTFOUND        7       /* SRV record not found */
   43 
   44 /*
   45  * net_lib_init()
   46  *
   47  * Initializes the networking libraries. If this function returns
   48  * NET_ELIBFAILED, *errstr will always point to an error string.
   49  * Used error codes: NET_ELIBFAILED
   50  */
   51 int net_lib_init(char **errstr);
   52 
   53 /*
   54  * net_open_socket()
   55  *
   56  * Opens a TCP socket to 'hostname':'port'.
   57  * 'proxy_hostname' and 'proxy_port' define a SOCKS5 proxy to use, unless they
   58  * are NULL/-1, in which case no proxy will be used.
   59  * 'hostname' may be a host name or a network address.
   60  * 'source_ip' may be NULL or a string representation of an IPv6 or IPv4 address
   61  * that will be bound as the source address for the outgoing connection.
   62  * 'timeout' is measured in secondes. If it is <= 0, no timeout will be set,
   63  * which means that the OS dependent default timeout value will be used.
   64  * The timeout will not only apply to the connection attempt but also to all
   65  * following read/write operations on the socket.
   66  * If 'canonical_name' is not NULL, a pointer to a string containing the
   67  * canonical hostname of the server will be stored in '*canonical_name', or NULL
   68  * if this information is not available.
   69  * If 'address' is not NULL, a pointer to a string containing the network
   70  * address of the server will be stored in '*address', or NULL if this
   71  * information is not available.
   72  * The strings must be deallocated when not used anymore.
   73  * The file descriptor is returned in 'fd'. It can be closed with close().
   74  *
   75  * Used error codes: NET_EHOSTNOTFOUND, NET_ESOCKET, NET_ECONNECT, NET_EPROXY
   76  */
   77 int net_open_socket(
   78         const char *proxy_hostname, int proxy_port,
   79         const char *hostname, int port,
   80         const char *source_ip,
   81         int timeout,
   82         int *fd, char **canonical_name, char **address,
   83         char **errstr);
   84 
   85 /*
   86  * net_gets()
   87  *
   88  * Reads in at most one less than 'size' characters from 'fd' and stores them
   89  * into the buffer pointed to by 'str'. Reading stops after an EOF or a newline.
   90  * If a newline is read, it is stored into the buffer. A '\0' is stored after
   91  * the last character in the buffer. The length of the resulting string (the
   92  * number of characters excluding the terminating '\0') will be stored in 'len'.
   93  * 'readbuf' will be used as an input buffer and must of course be the same for
   94  * all read operations on 'fd'.
   95  * Used error codes: NET_EIO
   96  */
   97 int net_gets(int fd, readbuf_t *readbuf,
   98         char *str, size_t size, size_t *len, char **errstr);
   99 
  100 /*
  101  * net_puts()
  102  *
  103  * Writes 'len' characters from the string 's' to 'fd'.
  104  * Used error codes: NET_EIO
  105  */
  106 int net_puts(int fd, const char *s, size_t len, char **errstr);
  107 
  108 /*
  109  * net_close_socket()
  110  *
  111  * Closes a socket.
  112  */
  113 void net_close_socket(int fd);
  114 
  115 /*
  116  * net_get_canonical_hostname()
  117  *
  118  * Get a canonical name of this host. This means that the name is meaningful to
  119  * other hosts. Usually, it is the fully qualified domain name of this host.
  120  */
  121 char *net_get_canonical_hostname(void);
  122 
  123 /*
  124  * net_get_srv_query()
  125  *
  126  * Construct a SRV record query for the given service at the given domain.
  127  * For example, with service "pop3s" and domain "example.com", this function
  128  * returns the SRV query "_pop3._tcp.example.com" as an allocated string.
  129  */
  130 char* net_get_srv_query(const char *domain, const char *service);
  131 
  132 /*
  133  * net_get_srv()
  134  *
  135  * Fetches a SRV record for the given query string (typically constructed with
  136  * net_get_srv_query()), and returns its hostname and port.
  137  * If more than one matching SRV record exists, this chooses the record based
  138  * on its priority and weight.
  139  * Used error codes:
  140  * - NET_ELIBFAILED: libresolv is missing so we cannot get SRV records
  141  * - NET_ESRVNOTFOUND: the SRV record was not found
  142  * - NET_EIO: a SRV record was found but could not be interpreted
  143  */
  144 int net_get_srv_record(const char* query, char **hostname, int *port);
  145 
  146 /*
  147  * net_lib_deinit()
  148  *
  149  * Deinit networking library
  150  */
  151 void net_lib_deinit(void);
  152 
  153 /*
  154  * net_exitcode()
  155  *
  156  * Translate NET_* error code to an error code from sysexits.h
  157  */
  158 int net_exitcode(int net_error_code);
  159 
  160 #endif