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
/* Name of the current machine, as in tuvok.intellivoice.com */
18
extern char tcp_thisMachineName[];
20
/* IP address of the current machine, packed and displayable. */
21
extern char tcp_thisMachineDots[]; /* "192.128.25.1" */
22
extern IP32bit tcp_thisMachineIP; /* pack the above string */
23
extern char tcp_farMachineDots[]; /* like the above, but for the far machine */
24
extern IP32bit tcp_farMachineIP;
25
extern short tcp_farMachinePort;
27
/* Set up the TCP stack and initialize the above variables */
28
/* Returns 0 (ok) or -1 (with errno set) */
31
/* routines to convert between names and IP addresses */
32
int tcp_isDots(const char *s);
33
IP32bit tcp_name_ip(const char *name);
34
char *tcp_ip_name(IP32bit packed_ip);
35
char *tcp_name_dots(const char *name);
36
char *tcp_dots_name(const char *displayable_ip);
37
char *tcp_ip_dots(IP32bit packed_ip);
38
IP32bit tcp_dots_ip(const char *displayable_ip);
40
/* Connect to a far machine. Use one of the above routines to
41
* convert to the packed IP address of the far machine.
42
* Returns the socket handle, or -1 if there was a problem. */
43
int tcp_connect(IP32bit far_ip, int far_portnum, int timeout);
45
/* Listen for an incoming connection.
46
* We expect only one such connection at a time.
47
* Returns the socket handle, or -1 if there was a problem. */
48
int tcp_listen(int portnum, int once);
49
void tcp_unlisten(void);
51
/* Read and write data on the socket.
52
* returns the number of bytes read, or -1 if there was a problem. */
53
int tcp_read(int handle, char *buf, int buflen);
54
int tcp_readFully(int handle, char *buf, int buflen);
55
int tcp_write(int handle, const char *buf, int buflen);
57
/* Close the socket */
58
void tcp_close(int handle);