File: net.h

package info (click to toggle)
qftp 0.97-1.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 204 kB
  • ctags: 168
  • sloc: cpp: 1,336; makefile: 61
file content (69 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 *  qftp
 *  Copyright (C) 1997,1998 Peter Strand
 *  Distributed under the GNU Pulic Licence
 */

#ifndef _NET_H
#define _NET_H

#include <arpa/inet.h>
#include <netinet/in.h>

class Host {
	char name[512];
	struct hostent *hp;
	struct in_addr addr;
public:
	Host();
	Host(char *h);
	~Host();

	int Lookup();
	struct in_addr GetAddr();
	void SetAddr(struct in_addr);
	char *GetHost();
	void SetHost(char *);
};

class Socket {
	int s;
	struct sockaddr_in laddr, raddr;
	char *rhost;
	char *error;
	long status;

	char *msgLostConn;
public:
	Socket();
	Socket(Socket *sock);
	Socket(int s, sockaddr_in naddr);
	~Socket();
	
	int Connect(Host &h);
	int Listen();
	Socket *Accept();
	void Close();
	const char *GetError();

	char *GetRHost();
	int GetLPort();
	long GetLAddr();
	struct sockaddr_in GetRSAddr();
	struct sockaddr_in GetLSAddr();
	long GetStatus();
	
	int Read(char *buf, int len = -1);
	int Write(char *buf, int len);
	int Readln(char *buf);
	int Writeln(char *buf);
};


#endif