-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsdb.c
53 lines (43 loc) · 1.09 KB
/
wsdb.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
// wsdb.c - missing netdb stuff for windows ce
//
// Time-stamp: <28/01/01 21:23:58 keuchel@lightning>
#include <windows.h>
#include <winsock.h>
#include "celib.h"
struct servent *
xcegetservbyname(const char *sname, const char *sproto)
{
static struct servent serv;
static char name[64];
static char proto[64];
FILE *f;
char path[MAX_PATH];
int port;
char buf[512];
strcpy(path, XCEGetUnixPath("/etc/services"));
if((f = xcefopen(path, "r")) == NULL)
{
XCEShowMessageA("Cannot open %s", path);
return NULL;
}
while(fgets(buf, sizeof(buf), f))
{
if(buf[0] == '#' || buf[0] == '\n')
continue;
if(sscanf(buf, "%s %d/%s", name, &port, proto) == 3)
{
if(strcmp(sname, name) == 0 && strcmp(sproto, proto) == 0)
{
serv.s_name = name;
serv.s_aliases = NULL;
serv.s_port = htons((unsigned short) port);
serv.s_proto = proto;
xcefclose(f);
return &serv;
}
}
}
XCEShowMessageA("Cannot find service %s", sname);
errno = ENOENT;
return NULL;
}