-
Notifications
You must be signed in to change notification settings - Fork 2
/
sock.h
115 lines (96 loc) · 2.74 KB
/
sock.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* PXE daemon - enable the remote booting of PXE enabled machines.
* Copyright (C) 2000 Tim Hurman ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
/******************************************************************************
* sock.h - socket IO class *
******************************************************************************/
#ifndef _SOCK_H
#define _SOCK_H
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include "autoconf.h"
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif // HAVE_STROPTS_H
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif // HAVE_SYS_SOCKIO_H
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif // HAVE_IFADDRS_H
#include "sysexception.h"
#include "logfile.h"
struct _iflist_t
{
char *if_name;
in_addr if_addr;
struct _iflist_t *next;
};
typedef struct _iflist_t iflist_t;
class Sock
{
protected:
int *sockfds;
int ifnum;
uint16_t listenport;
uint16_t clientport;
int multi_sockfd;
int broad_sockfd;
int use_multi;
int use_broad;
struct sockaddr_in *bind_addrs;
struct sockaddr_in multicast;
int listen_multi;
struct sockaddr_in broadcast;
int listen_broad;
struct sockaddr_in default_addr;
LogFile *log;
public:
// constructors
Sock(LogFile *log, const char *interface, uint16_t port);
~Sock();
// methods
int JoinMulticast(uint32_t multi_addr);
int LeaveMulticast();
int Read(unsigned char *, int, struct sockaddr_in *, struct sockaddr_in *);
int Send(unsigned char *, int, struct sockaddr_in *, struct sockaddr_in *);
int AllowBroadcast();
int DenyBroadcast();
char *GetHostname(const struct sockaddr_in *address);
void SetDefAddr(uint32_t);
private:
int Open(iflist_t *local_addr_t, int listlen, const uint16_t port);
int Close();
iflist_t *GetIfList();
};
#endif