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