未验证 提交 f147aa58 编写于 作者: O openharmony_ci 提交者: Gitee

!1034 回退 支持默认的services功能

Merge pull request !1034 from zzulilyw/master
......@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <sys/socket.h>
#include "functionalext.h"
#define HTTP_PORT 80
const int INFO_RESULT = 0;
const int FAMILY_NOTSUPPORTED = -6;
......@@ -167,26 +166,6 @@ void getnameinfo_0700()
EXPECT_EQ("getnameinfo_0700", ret, FAMILY_NOTSUPPORTED);
}
void getnameinfo_0900()
{
int ret;
char *ptr = "127.0.0.1";
char hostname[128] = {0};
char servername[128] = {0};
struct sockaddr_in addrDst;
memset(&addrDst, 0, sizeof(addrDst));
addrDst.sin_family = AF_INET;
addrDst.sin_addr.s_addr = inet_addr(ptr);
addrDst.sin_port = htons(HTTP_PORT);
ret = getnameinfo((struct sockaddr *)&addrDst, sizeof(addrDst), hostname, sizeof(hostname),
servername, sizeof(servername), 0);
EXPECT_EQ("getnameinfo_0900", ret, 0);
EXPECT_STREQ("getnameinfo_0900 hostname", hostname, "localhost");
EXPECT_STREQ("getnameinfo_0900 hostname", servername, "http");
}
int main(int argc, char *argv[])
{
getnameinfo_0100();
......@@ -196,6 +175,5 @@ int main(int argc, char *argv[])
getnameinfo_0500();
getnameinfo_0600();
getnameinfo_0700();
getnameinfo_0900();
return t_status;
}
......@@ -15,8 +15,6 @@
#include <netdb.h>
#include "functionalext.h"
#define FTP_PORT 21
#define HTTP_PORT 80
/**
* @tc.name : getservbyname_0100
......@@ -47,35 +45,9 @@ void getservbyname_0200(void)
EXPECT_PTREQ("getservbyname_0200", se, NULL);
}
/**
* @tc.name : getservbyname_0300
* @tc.desc : Get the service information of the specified port
* @tc.level : Level 0
*/
void getservbyname_0300(void)
{
struct servent *se = getservbyname("ftp", "tcp");
EXPECT_NE("getservbyname_0300", se, NULL);
EXPECT_EQ("getservbyname_0300", ntohs(se->s_port), FTP_PORT);
}
/**
* @tc.name : getservbyname_0400
* @tc.desc : Get the service information of the specified port
* @tc.level : Level 0
*/
void getservbyname_0400(void)
{
struct servent *se = getservbyname("http", "tcp");
EXPECT_NE("getservbyname_0400", se, NULL);
EXPECT_EQ("getservbyname_0400", ntohs(se->s_port), HTTP_PORT);
}
int main(void)
{
getservbyname_0100();
getservbyname_0200();
getservbyname_0300();
getservbyname_0400();
return t_status;
}
\ No newline at end of file
......@@ -2087,7 +2087,6 @@ musl_src_porting_file = [
"src/internal/pthread_impl.h",
"src/internal/locale_impl.h",
"src/internal/syscall.h",
"src/internal/services.h",
"ldso/namespace.h",
"ldso/ns_config.h",
"ldso/strops.h",
......@@ -2109,7 +2108,6 @@ musl_src_porting_file = [
"src/malloc/realloc.c",
"src/network/inet_legacy.c",
"src/network/lookup_name.c",
"src/network/lookup_serv.c",
"src/network/resolvconf.c",
"src/network/socket.c",
"src/passwd/getspnam_r.c",
......
此差异已折叠。
......@@ -21,14 +21,6 @@
extern char fixed_hosts[FIXED_HOSTS_MAX_LENGTH][FIXED_HOSTS_STR_MAX_LENGTH];
char *g_fixedServices[] = {
#define PORT_DESC(a) a
#include "services.h"
#undef PORT_DESC(a)
};
#define FIXED_SERVICES_COUNT (sizeof(g_fixedServices) / sizeof(char*))
static char *itoa(char *p, unsigned x) {
p += 3*sizeof(int);
*--p = 0;
......@@ -111,27 +103,14 @@ static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, i
}
}
static inline int get_services_str(char *line, int length, FILE *f, int *indexPtr)
{
if (f) {
return fgets(line, sizeof line, f);
}
if (*indexPtr < FIXED_SERVICES_COUNT) {
memcpy(line, g_fixedServices[*indexPtr], strlen(g_fixedServices[*indexPtr]));
(*indexPtr)++;
return 1;
}
return NULL;
}
static void reverse_services(char *buf, int port, int dgram)
{
unsigned long svport;
char line[128], *p, *z;
unsigned char _buf[1032];
FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
int indexPtr = 0;
while (indexPtr < FIXED_SERVICES_COUNT && get_services_str(line, sizeof line, f, &indexPtr)) {
if (!f) return;
while (fgets(line, sizeof line, f)) {
if ((p=strchr(line, '#'))) *p++='\n', *p=0;
for (p=line; *p && !isspace(*p); p++);
......@@ -147,9 +126,7 @@ static void reverse_services(char *buf, int port, int dgram)
memcpy(buf, line, p-line);
break;
}
if (f) {
__fclose_ca(f);
}
__fclose_ca(f);
}
static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
......@@ -242,5 +219,3 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
return 0;
}
#undef FIXED_SERVICES_COUNT
\ No newline at end of file
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include "lookup.h"
#include "stdio_impl.h"
char *g_fixedServicesLookup[] = {
#define PORT_DESC(a) a
#include "services.h"
#undef PORT_DESC(a)
};
#define FIXED_SERVICES_COUNT (sizeof(g_fixedServicesLookup) / sizeof(char*))
static inline int get_services_str(char *line, int length, FILE *f, int *indexPtr)
{
if (f) {
return fgets(line, sizeof line, f);
}
if (*indexPtr < FIXED_SERVICES_COUNT) {
memcpy(line, g_fixedServicesLookup[*indexPtr], strlen(g_fixedServicesLookup[*indexPtr]));
(*indexPtr)++;
return 1;
}
return NULL;
}
int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags)
{
char line[128];
int cnt = 0;
char *p, *z = "";
unsigned long port = 0;
switch (socktype) {
case SOCK_STREAM:
switch (proto) {
case 0:
proto = IPPROTO_TCP;
case IPPROTO_TCP:
break;
default:
return EAI_SERVICE;
}
break;
case SOCK_DGRAM:
switch (proto) {
case 0:
proto = IPPROTO_UDP;
case IPPROTO_UDP:
break;
default:
return EAI_SERVICE;
}
case 0:
break;
default:
if (name) return EAI_SERVICE;
buf[0].port = 0;
buf[0].proto = proto;
buf[0].socktype = socktype;
return 1;
}
if (name) {
if (!*name) return EAI_SERVICE;
port = strtoul(name, &z, 10);
}
if (!*z) {
if (port > 65535) return EAI_SERVICE;
if (proto != IPPROTO_UDP) {
buf[cnt].port = port;
buf[cnt].socktype = SOCK_STREAM;
buf[cnt++].proto = IPPROTO_TCP;
}
if (proto != IPPROTO_TCP) {
buf[cnt].port = port;
buf[cnt].socktype = SOCK_DGRAM;
buf[cnt++].proto = IPPROTO_UDP;
}
return cnt;
}
if (flags & AI_NUMERICSERV) return EAI_NONAME;
size_t l = strlen(name);
unsigned char _buf[1032];
FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
int indexPtr = 0;
while (indexPtr < FIXED_SERVICES_COUNT && get_services_str(line, sizeof line, f, &indexPtr)) {
if ((p=strchr(line, '#'))) *p++='\n', *p=0;
/* Find service name */
for(p=line; (p=strstr(p, name)); p++) {
if (p>line && !isspace(p[-1])) continue;
if (p[l] && !isspace(p[l])) continue;
break;
}
if (!p) continue;
/* Skip past canonical name at beginning of line */
for (p=line; *p && !isspace(*p); p++);
port = strtoul(p, &z, 10);
if (port > 65535 || z==p) continue;
if (!strncmp(z, "/udp", 4)) {
if (proto == IPPROTO_TCP) continue;
buf[cnt].port = port;
buf[cnt].socktype = SOCK_DGRAM;
buf[cnt++].proto = IPPROTO_UDP;
}
if (!strncmp(z, "/tcp", 4)) {
if (proto == IPPROTO_UDP) continue;
buf[cnt].port = port;
buf[cnt].socktype = SOCK_STREAM;
buf[cnt++].proto = IPPROTO_TCP;
}
}
if (f) {
__fclose_ca(f);
}
return cnt > 0 ? cnt : EAI_SERVICE;
}
#undef FIXED_SERVICES_COUNT
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册