-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDPSocket.cpp
More file actions
111 lines (96 loc) · 2.15 KB
/
UDPSocket.cpp
File metadata and controls
111 lines (96 loc) · 2.15 KB
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
#include <linux/ioctl.h>
#include "UDPSocket.h"
static UDPSocket *me=0;
bool UDPSocket::bindx(SCDVBDevice *pSCDVBDevice)
{
me=new UDPSocket(pSCDVBDevice);
if(me->bint)
me->Start();
return me->bint;
}
UDPSocket::~UDPSocket()
{
bint=false;
close(sock);
}
UDPSocket::UDPSocket(SCDVBDevice *pSCDVBDevice)
{
isyslog("DVBAPI: UDPSocket::UDPSocket");
sCDVBDevice=pSCDVBDevice;
struct sockaddr_in socketAddr;
memset(&socketAddr,0,sizeof(sockaddr_in));
const struct hostent * const hostaddr=gethostbyname("127.0.0.1");
if(hostaddr)
{
unsigned int port;
port = 9000 + sCDVBDevice->adapter;
isyslog("DVBAPI: Adapter %d\n",sCDVBDevice->adapter);
isyslog("DVBAPI: UDPSocket hostaddr port %d",port);
socketAddr.sin_family=AF_INET;
socketAddr.sin_port=htons(port);
socketAddr.sin_addr.s_addr=((struct in_addr *)hostaddr->h_addr)->s_addr;
const struct protoent * const ptrp=getprotobyname("udp");
if(ptrp)
{
isyslog("DVBAPI: UDPSocket ptrp");
sock=socket(PF_INET,SOCK_DGRAM,ptrp->p_proto);
if(sock>0)
{
bint=(bind(sock,(struct sockaddr *)&socketAddr,sizeof(socketAddr))>=0);
if(bint>=0)
isyslog("DVBAPI: UDPSocket bint=%d",bint);
}
}
}
}
void UDPSocket::unbind(void)
{
delete(me);
}
void UDPSocket::Action(void)
{
isyslog("DVBAPI: UDPSocket Action");
while(bint)
{ unsigned int r=0;
int request=0;
while(r<sizeof(request))
{
int cRead=read(sock,(&request)+r,sizeof(request));
if(cRead<=0)
break;
r=+cRead;
}
if(request==CA_SET_DESCR)
{
while(r<sizeof(ca_descr_t))
{
r=0;
int cRead=read(sock,(&ca_descr)+r,sizeof(ca_descr_t));
if(cRead<=0)
break;
r=+cRead;
}
if(r==sizeof(ca_descr_t))
{
isyslog("DVBAPI: UDPSocket Got CW");
sCDVBDevice->SetCaDescr(&ca_descr);
}
}
if(request==CA_SET_PID)
{
r=0;
while(r<sizeof(ca_pid_t))
{
int cRead=read(sock,(&ca_pid)+r,sizeof(ca_pid_t));
if(cRead<=0)
break;
r=+cRead;
}
if(r==sizeof(ca_pid_t))
{
isyslog("DVBAPI: UDPSocket Got CPID");
sCDVBDevice->SetCaPid(&ca_pid);
}
}
}
}