Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
9cdc61ca
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9cdc61ca
编写于
8月 21, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 21, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1023 支持默认的services功能
Merge pull request !1023 from zzulilyw/master
上级
4a672a91
08329b66
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
784 addition
and
3 deletion
+784
-3
libc-test/src/functionalext/supplement/manual/network/getnameinfo.c
...src/functionalext/supplement/manual/network/getnameinfo.c
+22
-0
libc-test/src/functionalext/supplement/network/getservbyname.c
...test/src/functionalext/supplement/network/getservbyname.c
+28
-0
musl_src.gni
musl_src.gni
+2
-0
porting/linux/user/src/internal/services.h
porting/linux/user/src/internal/services.h
+573
-0
porting/linux/user/src/network/getnameinfo.c
porting/linux/user/src/network/getnameinfo.c
+28
-3
porting/linux/user/src/network/lookup_serv.c
porting/linux/user/src/network/lookup_serv.c
+131
-0
未找到文件。
libc-test/src/functionalext/supplement/manual/network/getnameinfo.c
浏览文件 @
9cdc61ca
...
...
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <sys/socket.h>
#include "functionalext.h"
#define HTTP_PORT 80
const
int
INFO_RESULT
=
0
;
const
int
FAMILY_NOTSUPPORTED
=
-
6
;
...
...
@@ -166,6 +167,26 @@ 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
();
...
...
@@ -175,5 +196,6 @@ int main(int argc, char *argv[])
getnameinfo_0500
();
getnameinfo_0600
();
getnameinfo_0700
();
getnameinfo_0900
();
return
t_status
;
}
libc-test/src/functionalext/supplement/network/getservbyname.c
浏览文件 @
9cdc61ca
...
...
@@ -15,6 +15,8 @@
#include <netdb.h>
#include "functionalext.h"
#define FTP_PORT 21
#define HTTP_PORT 80
/**
* @tc.name : getservbyname_0100
...
...
@@ -45,9 +47,35 @@ 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
musl_src.gni
浏览文件 @
9cdc61ca
...
...
@@ -2087,6 +2087,7 @@ 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",
...
...
@@ -2108,6 +2109,7 @@ 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",
...
...
porting/linux/user/src/internal/services.h
0 → 100644
浏览文件 @
9cdc61ca
此差异已折叠。
点击以展开。
porting/linux/user/src/network/getnameinfo.c
浏览文件 @
9cdc61ca
...
...
@@ -21,6 +21,14 @@
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
;
...
...
@@ -103,14 +111,27 @@ 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
);
i
f
(
!
f
)
return
;
while
(
fgets
(
line
,
sizeof
line
,
f
))
{
i
nt
indexPtr
=
0
;
while
(
indexPtr
<
FIXED_SERVICES_COUNT
&&
get_services_str
(
line
,
sizeof
line
,
f
,
&
indexPtr
))
{
if
((
p
=
strchr
(
line
,
'#'
)))
*
p
++=
'\n'
,
*
p
=
0
;
for
(
p
=
line
;
*
p
&&
!
isspace
(
*
p
);
p
++
);
...
...
@@ -126,7 +147,9 @@ static void reverse_services(char *buf, int port, int dgram)
memcpy
(
buf
,
line
,
p
-
line
);
break
;
}
__fclose_ca
(
f
);
if
(
f
)
{
__fclose_ca
(
f
);
}
}
static
int
dns_parse_callback
(
void
*
c
,
int
rr
,
const
void
*
data
,
int
len
,
const
void
*
packet
)
...
...
@@ -219,3 +242,5 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
return
0
;
}
#undef FIXED_SERVICES_COUNT
\ No newline at end of file
porting/linux/user/src/network/lookup_serv.c
0 → 100644
浏览文件 @
9cdc61ca
#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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录