-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceirda.c
82 lines (64 loc) · 1.35 KB
/
ceirda.c
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
// ceirda.c
//
// Time-stamp: <03/01/02 22:16:02 [email protected]>
#if UNDER_CE > 201
#include <af_irda.h>
#include "ceirda.h"
int
xceirda_getaddr(const char *hostname, const char *servicename,
SOCKADDR_IRDA *addr)
{
int len;
int retry = 0;
SOCKET s;
int i;
DEVICELIST *pirda_devlist = NULL;
int status;
len = 1024;
pirda_devlist = malloc(len);
pirda_devlist->numDevice = 0;
if((s = socket(AF_IRDA, SOCK_STREAM, 0)) == SOCKET_ERROR)
return -1;
while(retry++ < 5)
{
len = 1024;
if(getsockopt(s, SOL_IRLMP, IRLMP_ENUMDEVICES,
(char *) pirda_devlist, &len) == SOCKET_ERROR)
{
goto bad;
}
if(pirda_devlist->numDevice != 0)
{
break;
}
Sleep(200);
}
if(pirda_devlist->numDevice == 0)
{
goto bad;
}
for(i = 0; i < pirda_devlist->numDevice; i++)
{
if(xcestricmp(pirda_devlist->Device[i].irdaDeviceName, hostname) == 0)
{
break;
}
}
if(i == pirda_devlist->numDevice)
{
goto bad;
}
addr->irdaAddressFamily = AF_IRDA;
memcpy(addr->irdaDeviceID,
pirda_devlist->Device[i].irdaDeviceID, 4);
strcpy(addr->irdaServiceName, servicename);
status = 0;
goto done;
bad:
status = -1;
done:
free(pirda_devlist);
closesocket(s);
return status;
}
#endif