Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
ccbae9ea
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看板
未验证
提交
ccbae9ea
编写于
7月 28, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 28, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1005 Fix network & domain interface logic
Merge pull request !1005 from zzulilyw/OpenHarmony-4.0-Beta2
上级
19cfb5db
4d0184cc
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
252 addition
and
23 deletion
+252
-23
libc-test/src/functionalext/supplement/manual/network/gethostbyaddr.c
...c/functionalext/supplement/manual/network/gethostbyaddr.c
+1
-3
libc-test/src/functionalext/supplement/manual/network/gethostbyaddr_r.c
...functionalext/supplement/manual/network/gethostbyaddr_r.c
+1
-3
libc-test/src/functionalext/supplement/manual/network/gethostbyname2.c
.../functionalext/supplement/manual/network/gethostbyname2.c
+1
-4
libc-test/src/functionalext/supplement/manual/network/gethostbyname2_r.c
...unctionalext/supplement/manual/network/gethostbyname2_r.c
+4
-2
musl_src.gni
musl_src.gni
+1
-0
porting/linux/user/src/network/getnameinfo.c
porting/linux/user/src/network/getnameinfo.c
+219
-0
porting/linux/user/src/network/lookup_name.c
porting/linux/user/src/network/lookup_name.c
+25
-11
未找到文件。
libc-test/src/functionalext/supplement/manual/network/gethostbyaddr.c
浏览文件 @
ccbae9ea
...
...
@@ -36,9 +36,7 @@ void gethostbyaddre_0100(void)
t_error
(
"%s gethostbyaddr error:%s
\n
"
,
__func__
,
strerror
(
h_errno
));
}
EXPECT_TRUE
(
"gethostbyaddre_0100"
,
hptr
!=
NULL
);
if
(
strcmp
(
hptr
->
h_name
,
"localhost"
)
&&
strcmp
(
hptr
->
h_name
,
"127.0.0.1"
))
{
t_error
(
"gethostbyname2_0100"
);
}
EXPECT_STREQ
(
"gethostbyaddre_0100"
,
hptr
->
h_name
,
"localhost"
);
}
/**
...
...
libc-test/src/functionalext/supplement/manual/network/gethostbyaddr_r.c
浏览文件 @
ccbae9ea
...
...
@@ -32,9 +32,7 @@ void gethostbyaddr_r_0100(void)
in_addr_t
a
=
inet_addr
(
"127.0.0.1"
);
int
ret
=
gethostbyaddr_r
((
void
*
)
&
a
,
4
,
AF_INET
,
&
h
,
buf
,
sizeof
(
buf
),
&
res
,
&
err
);
EXPECT_EQ
(
"gethostbyaddr_r_0100"
,
ret
,
0
);
if
(
strcmp
(
h
.
h_name
,
"localhost"
)
&&
strcmp
(
h
.
h_name
,
"127.0.0.1"
))
{
t_error
(
"gethostbyname2_0100"
);
}
EXPECT_TRUE
(
"gethostbyaddr_r_0100"
,
strcmp
(
h
.
h_name
,
"localhost"
)
==
0
);
}
/**
...
...
libc-test/src/functionalext/supplement/manual/network/gethostbyname2.c
浏览文件 @
ccbae9ea
...
...
@@ -20,7 +20,6 @@
#include <stdio.h>
#include <sys/socket.h>
#include <stdbool.h>
#include <string.h>
#include "functionalext.h"
typedef
void
(
*
TEST_FUN
)();
...
...
@@ -39,9 +38,7 @@ void gethostbyname2_0100(void)
flag
=
true
;
}
EXPECT_TRUE
(
"gethostbyname2_0100"
,
flag
);
if
(
strcmp
(
hptr
->
h_name
,
"localhost"
)
&&
strcmp
(
hptr
->
h_name
,
"127.0.0.1"
))
{
t_error
(
"gethostbyname2_0100"
);
}
EXPECT_STREQ
(
"gethostbyname2_0100"
,
hptr
->
h_name
,
"127.0.0.1"
);
}
/**
...
...
libc-test/src/functionalext/supplement/manual/network/gethostbyname2_r.c
浏览文件 @
ccbae9ea
...
...
@@ -33,7 +33,7 @@ void gethostbyname2_r_0100(void)
char
*
name
=
"127.0.0.1"
;
int
ret
=
gethostbyname2_r
(
name
,
AF_INET
,
&
h
,
buf
,
sizeof
(
buf
),
&
res
,
&
err
);
EXPECT_EQ
(
"gethostbyname2_r_0100"
,
ret
,
0
);
EXPECT_
TRUE
(
"gethostbyname2_r_0100"
,
strcmp
(
h
.
h_name
,
"127.0.0.1"
)
==
0
);
EXPECT_
STREQ
(
"gethostbyname2_r_0100"
,
h
.
h_name
,
"127.0.0.1"
);
}
/**
...
...
@@ -80,7 +80,8 @@ void gethostbyname2_r_0400(void)
int
err
=
0
;
char
*
name
=
"localhost"
;
int
ret
=
gethostbyname2_r
(
name
,
0
,
&
h
,
buf
,
sizeof
(
buf
),
&
res
,
&
err
);
EXPECT_NE
(
"gethostbyname2_r_0400"
,
ret
,
0
);
EXPECT_EQ
(
"gethostbyname2_r_0400"
,
ret
,
0
);
EXPECT_STREQ
(
"gethostbyname2_r_0400"
,
"localhost"
,
h
.
h_name
);
}
int
main
(
int
argc
,
char
*
argv
[])
...
...
@@ -88,5 +89,6 @@ int main(int argc, char *argv[])
gethostbyname2_r_0100
();
gethostbyname2_r_0200
();
gethostbyname2_r_0300
();
gethostbyname2_r_0400
();
return
t_status
;
}
musl_src.gni
浏览文件 @
ccbae9ea
...
...
@@ -2101,6 +2101,7 @@ musl_src_porting_file = [
"src/malloc/stats.c",
"src/malloc/calloc.c",
"src/malloc/free.c",
"src/network/getnameinfo.c",
"src/malloc/libc_calloc.c",
"src/malloc/realloc.c",
"src/network/inet_legacy.c",
...
...
porting/linux/user/src/network/getnameinfo.c
0 → 100644
浏览文件 @
ccbae9ea
#include <netdb.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <ctype.h>
#include <resolv.h>
#include "lookup.h"
#include "stdio_impl.h"
#define PTR_MAX (64 + sizeof ".in-addr.arpa")
#define RR_PTR 12
#define BREAK 0
#define CONTINUE 1
extern
char
fixed_hosts
[][
23
];
static
char
*
itoa
(
char
*
p
,
unsigned
x
)
{
p
+=
3
*
sizeof
(
int
);
*--
p
=
0
;
do
{
*--
p
=
'0'
+
x
%
10
;
x
/=
10
;
}
while
(
x
);
return
p
;
}
static
void
mkptr4
(
char
*
s
,
const
unsigned
char
*
ip
)
{
sprintf
(
s
,
"%d.%d.%d.%d.in-addr.arpa"
,
ip
[
3
],
ip
[
2
],
ip
[
1
],
ip
[
0
]);
}
static
void
mkptr6
(
char
*
s
,
const
unsigned
char
*
ip
)
{
static
const
char
xdigits
[]
=
"0123456789abcdef"
;
int
i
;
for
(
i
=
15
;
i
>=
0
;
i
--
)
{
*
s
++
=
xdigits
[
ip
[
i
]
&
15
];
*
s
++
=
'.'
;
*
s
++
=
xdigits
[
ip
[
i
]
>>
4
];
*
s
++
=
'.'
;
}
strcpy
(
s
,
"ip6.arpa"
);
}
static
inline
int
get_hosts_str
(
char
*
line
,
int
length
,
FILE
*
f
,
int
*
i
)
{
if
(
f
)
{
return
fgets
(
line
,
sizeof
line
,
f
);
}
if
(
*
i
<
2
)
{
memcpy
(
line
,
fixed_hosts
[
*
i
],
strlen
(
fixed_hosts
[
*
i
]));
(
*
i
)
++
;
return
1
;
}
return
NULL
;
}
static
void
reverse_hosts
(
char
*
buf
,
const
unsigned
char
*
a
,
unsigned
scopeid
,
int
family
)
{
char
line
[
512
],
*
p
,
*
z
;
unsigned
char
_buf
[
1032
],
atmp
[
16
];
struct
address
iplit
;
FILE
_f
,
*
f
=
__fopen_rb_ca
(
"/etc/hosts"
,
&
_f
,
_buf
,
sizeof
_buf
);
if
(
family
==
AF_INET
)
{
memcpy
(
atmp
+
12
,
a
,
4
);
memcpy
(
atmp
,
"
\0\0\0\0\0\0\0\0\0\0\xff\xff
"
,
12
);
a
=
atmp
;
}
int
i
=
0
;
while
(
i
<
2
&&
get_hosts_str
(
line
,
sizeof
line
,
f
,
&
i
))
{
if
((
p
=
strchr
(
line
,
'#'
)))
*
p
++=
'\n'
,
*
p
=
0
;
for
(
p
=
line
;
*
p
&&
!
isspace
(
*
p
);
p
++
);
*
p
++
=
0
;
if
(
__lookup_ipliteral
(
&
iplit
,
line
,
AF_UNSPEC
)
<=
0
)
continue
;
if
(
iplit
.
family
==
AF_INET
)
{
memcpy
(
iplit
.
addr
+
12
,
iplit
.
addr
,
4
);
memcpy
(
iplit
.
addr
,
"
\0\0\0\0\0\0\0\0\0\0\xff\xff
"
,
12
);
iplit
.
scopeid
=
0
;
}
if
(
memcmp
(
a
,
iplit
.
addr
,
16
)
||
iplit
.
scopeid
!=
scopeid
)
continue
;
for
(;
*
p
&&
isspace
(
*
p
);
p
++
);
for
(
z
=
p
;
*
z
&&
!
isspace
(
*
z
);
z
++
);
*
z
=
0
;
if
(
z
-
p
<
256
)
{
memcpy
(
buf
,
p
,
z
-
p
+
1
);
break
;
}
}
if
(
f
)
{
__fclose_ca
(
f
);
}
}
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
);
if
(
!
f
)
return
;
while
(
fgets
(
line
,
sizeof
line
,
f
))
{
if
((
p
=
strchr
(
line
,
'#'
)))
*
p
++=
'\n'
,
*
p
=
0
;
for
(
p
=
line
;
*
p
&&
!
isspace
(
*
p
);
p
++
);
if
(
!*
p
)
continue
;
*
p
++
=
0
;
svport
=
strtoul
(
p
,
&
z
,
10
);
if
(
svport
!=
port
||
z
==
p
)
continue
;
if
(
dgram
&&
strncmp
(
z
,
"/udp"
,
4
))
continue
;
if
(
!
dgram
&&
strncmp
(
z
,
"/tcp"
,
4
))
continue
;
if
(
p
-
line
>
32
)
continue
;
memcpy
(
buf
,
line
,
p
-
line
);
break
;
}
__fclose_ca
(
f
);
}
static
int
dns_parse_callback
(
void
*
c
,
int
rr
,
const
void
*
data
,
int
len
,
const
void
*
packet
)
{
if
(
rr
!=
RR_PTR
)
return
0
;
if
(
__dn_expand
(
packet
,
(
const
unsigned
char
*
)
packet
+
512
,
data
,
c
,
256
)
<=
0
)
*
(
char
*
)
c
=
0
;
return
0
;
}
int
getnameinfo
(
const
struct
sockaddr
*
restrict
sa
,
socklen_t
sl
,
char
*
restrict
node
,
socklen_t
nodelen
,
char
*
restrict
serv
,
socklen_t
servlen
,
int
flags
)
{
char
ptr
[
PTR_MAX
];
char
buf
[
256
],
num
[
3
*
sizeof
(
int
)
+
1
];
int
af
=
sa
->
sa_family
;
unsigned
char
*
a
;
unsigned
scopeid
;
switch
(
af
)
{
case
AF_INET
:
a
=
(
void
*
)
&
((
struct
sockaddr_in
*
)
sa
)
->
sin_addr
;
if
(
sl
<
sizeof
(
struct
sockaddr_in
))
return
EAI_FAMILY
;
mkptr4
(
ptr
,
a
);
scopeid
=
0
;
break
;
case
AF_INET6
:
a
=
(
void
*
)
&
((
struct
sockaddr_in6
*
)
sa
)
->
sin6_addr
;
if
(
sl
<
sizeof
(
struct
sockaddr_in6
))
return
EAI_FAMILY
;
if
(
memcmp
(
a
,
"
\0\0\0\0\0\0\0\0\0\0\xff\xff
"
,
12
))
mkptr6
(
ptr
,
a
);
else
mkptr4
(
ptr
,
a
+
12
);
scopeid
=
((
struct
sockaddr_in6
*
)
sa
)
->
sin6_scope_id
;
break
;
default:
return
EAI_FAMILY
;
}
if
(
node
&&
nodelen
)
{
buf
[
0
]
=
0
;
if
(
!
(
flags
&
NI_NUMERICHOST
))
{
reverse_hosts
(
buf
,
a
,
scopeid
,
af
);
}
if
(
!*
buf
&&
!
(
flags
&
NI_NUMERICHOST
))
{
unsigned
char
query
[
18
+
PTR_MAX
],
reply
[
512
];
int
qlen
=
__res_mkquery
(
0
,
ptr
,
1
,
RR_PTR
,
0
,
0
,
0
,
query
,
sizeof
query
);
query
[
3
]
=
0
;
/* don't need AD flag */
int
rlen
=
__res_send
(
query
,
qlen
,
reply
,
sizeof
reply
);
buf
[
0
]
=
0
;
if
(
rlen
>
0
)
__dns_parse
(
reply
,
rlen
,
dns_parse_callback
,
buf
);
}
if
(
!*
buf
)
{
if
(
flags
&
NI_NAMEREQD
)
return
EAI_NONAME
;
inet_ntop
(
af
,
a
,
buf
,
sizeof
buf
);
if
(
scopeid
)
{
char
*
p
=
0
,
tmp
[
IF_NAMESIZE
+
1
];
if
(
!
(
flags
&
NI_NUMERICSCOPE
)
&&
(
IN6_IS_ADDR_LINKLOCAL
(
a
)
||
IN6_IS_ADDR_MC_LINKLOCAL
(
a
)))
p
=
if_indextoname
(
scopeid
,
tmp
+
1
);
if
(
!
p
)
p
=
itoa
(
num
,
scopeid
);
*--
p
=
'%'
;
strcat
(
buf
,
p
);
}
}
if
(
strlen
(
buf
)
>=
nodelen
)
return
EAI_OVERFLOW
;
strcpy
(
node
,
buf
);
}
if
(
serv
&&
servlen
)
{
char
*
p
=
buf
;
int
port
=
ntohs
(((
struct
sockaddr_in
*
)
sa
)
->
sin_port
);
buf
[
0
]
=
0
;
if
(
!
(
flags
&
NI_NUMERICSERV
))
reverse_services
(
buf
,
port
,
flags
&
NI_DGRAM
);
if
(
!*
p
)
p
=
itoa
(
num
,
port
);
if
(
strlen
(
p
)
>=
servlen
)
return
EAI_OVERFLOW
;
strcpy
(
serv
,
p
);
}
return
0
;
}
porting/linux/user/src/network/lookup_name.c
浏览文件 @
ccbae9ea
...
...
@@ -14,11 +14,17 @@
#include "lookup.h"
#include "stdio_impl.h"
#include "syscall.h"
#define BREAK 0
#define CONTINUE 1
#if OHOS_PERMISSION_INTERNET
uint8_t
is_allow_internet
(
void
);
#endif
char
fixed_hosts
[][
23
]
=
{
"127.0.0.1 localhost
\r\n\0
"
,
"::1 ip6-localhost
\r\n\0
"
};
static
int
is_valid_hostname
(
const
char
*
host
)
{
const
unsigned
char
*
s
;
...
...
@@ -50,6 +56,19 @@ static int name_from_numeric(struct address buf[static 1], const char *name, int
return
__lookup_ipliteral
(
buf
,
name
,
family
);
}
static
inline
int
get_hosts_str
(
char
*
line
,
int
length
,
FILE
*
f
,
int
*
i
)
{
if
(
f
)
{
return
fgets
(
line
,
sizeof
line
,
f
);
}
if
(
*
i
<
2
)
{
memcpy
(
line
,
fixed_hosts
[
*
i
],
strlen
(
fixed_hosts
[
*
i
]));
(
*
i
)
++
;
return
1
;
}
return
NULL
;
}
static
int
name_from_hosts
(
struct
address
buf
[
static
MAXADDRS
],
char
canon
[
static
256
],
const
char
*
name
,
int
family
)
{
char
line
[
512
];
...
...
@@ -57,15 +76,8 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati
int
cnt
=
0
,
badfam
=
0
,
have_canon
=
0
;
unsigned
char
_buf
[
1032
];
FILE
_f
,
*
f
=
__fopen_rb_ca
(
"/etc/hosts"
,
&
_f
,
_buf
,
sizeof
_buf
);
if
(
!
f
)
switch
(
errno
)
{
case
ENOENT
:
case
ENOTDIR
:
case
EACCES
:
return
0
;
default:
return
EAI_SYSTEM
;
}
while
(
fgets
(
line
,
sizeof
line
,
f
)
&&
cnt
<
MAXADDRS
)
{
int
i
=
0
;
while
(
i
<
2
&&
get_hosts_str
(
line
,
sizeof
line
,
f
,
&
i
)
&&
cnt
<
MAXADDRS
)
{
char
*
p
,
*
z
;
if
((
p
=
strchr
(
line
,
'#'
)))
*
p
++=
'\n'
,
*
p
=
0
;
...
...
@@ -98,7 +110,9 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati
memcpy
(
canon
,
p
,
z
-
p
+
1
);
}
}
__fclose_ca
(
f
);
if
(
f
)
{
__fclose_ca
(
f
);
}
return
cnt
?
cnt
:
badfam
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录