]> git.vomp.tv Git - vompclient.git/blob - tcp.h
Switch trunk code to new boxes
[vompclient.git] / tcp.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3     Copyright 2003-2004 University Of Bradford
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21
22 #ifndef TCP_H
23 #define TCP_H
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <ctype.h>
31
32 #ifndef WIN32
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <unistd.h>
36 #include <arpa/inet.h>
37 #include <sys/ioctl.h>
38 #include <net/if.h>
39 #else
40 #include <winsock2.h>
41 #include <errno.h>
42 #include <Ws2tcpip.h>
43 #endif
44
45 #include "defines.h"
46
47 class TCP
48 {
49   public:
50     TCP();
51     ~TCP();
52
53     int connectTo(char *host, unsigned short port);
54     void assignSocket(int tsocket);
55
56     int isConnected();
57     void disableTimeout();
58
59     int sendPacket(void *, size_t size);
60     UCHAR* receivePacket();
61     int getDataLength();
62
63     int readData(UCHAR* buffer, int totalBytes);
64
65     static void dump(unsigned char* data, ULONG size);
66
67     void getMAC(char* dest); // copies 6 MAC bytes to dest
68     void setReceiveWindow(size_t rxBufferSize);
69
70   private:
71     int sock;
72     int connected;
73     int timeoutEnabled;
74     int dataLength;
75
76     static UCHAR dcc(UCHAR c);
77 };
78
79 #endif