1
/* tcp.h: header file for NT/Unix TCP access layer */
10
/* include this for htons() and its siblings */
11
#include <netinet/in.h>
14
typedef unsigned int IP32bit;
15
#define NULL_IP (IP32bit)(-1)
17
/* Unix/Linux has a max absolute path length of 256, I think. */
20
/* Name of the current machine, as in tuvok.intellivoice.com */
21
extern char tcp_thisMachineName[];
23
/* IP address of the current machine, packed and displayable. */
24
extern char tcp_thisMachineDots[]; /* "192.128.25.1" */
25
extern IP32bit tcp_thisMachineIP; /* pack the above string */
26
extern char tcp_farMachineDots[]; /* like the above, but for the far machine */
27
extern IP32bit tcp_farMachineIP;
28
extern short tcp_farMachinePort;
30
/* Set up the TCP stack and initialize the above variables */
31
/* Returns 0 (ok) or -1 (with errno set) */
34
/* routines to convert between names and IP addresses */
35
int tcp_isDots(const char *s);
36
IP32bit tcp_name_ip(const char *name);
37
char *tcp_ip_name(IP32bit packed_ip);
38
char *tcp_name_dots(const char *name);
39
char *tcp_dots_name(const char *displayable_ip);
40
char *tcp_ip_dots(IP32bit packed_ip);
41
IP32bit tcp_dots_ip(const char *displayable_ip);
43
/* Connect to a far machine. Use one of the above routines to
44
* convert to the packed IP address of the far machine.
45
* Returns the socket handle, or -1 if there was a problem. */
46
int tcp_connect(IP32bit far_ip, int far_portnum, int timeout);
48
/* Listen for an incoming connection.
49
* We expect only one such connection at a time.
50
* Returns the socket handle, or -1 if there was a problem. */
51
int tcp_listen(int portnum, int once);
52
void tcp_unlisten(void);
54
/* Read and write data on the socket.
55
* returns the number of bytes read, or -1 if there was a problem. */
56
int tcp_read(int handle, char *buf, int buflen);
57
int tcp_readFully(int handle, char *buf, int buflen);
58
int tcp_write(int handle, const char *buf, int buflen);
60
/* Close the socket */
61
void tcp_close(int handle);
63
/* Routines to establish, read, and write secure sockets. */
64
extern char *sslCerts; /* ssl certificates to validate the secure server */
65
extern int verifyCertificates; /* is a certificate required for the ssl connection? */
67
void ssl_verify_setting(void);
68
int ssl_newbind(int fd);
70
int ssl_read(char *buf, int len);
71
int ssl_write(const char *buf, int len);
72
int ssl_readFully(char *buf, int len);