FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
emscripten/tests/799.cpp at incoming · JavaScriptIOT/emscripten · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
JavaScriptIOT
/
emscripten
Public
forked from
emscripten-core/emscripten
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
emscripten
/
tests
/
799.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (71 loc) · 1.89 KB
Breadcrumbs
emscripten
/
tests
/
799.cpp
Copy path
File metadata and controls
83 lines (71 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
83
#
include
<
netdb.h
>
#
include
<
stdint.h
>
#
include
<
string.h
>
#
include
<
assert.h
>
#
include
<
stdio.h
>
#
include
<
sys/socket.h
>
#
include
<
netinet/in.h
>
#
ifdef
__EMSCRIPTEN__
#
include
<
arpa/inet.h
>
#
endif
#
define
uint16
uint16_t
class
NetworkAddress
{
private:
sockaddr_storage address;
//
/< The resolved address
public:
/*
*
* Create a network address based on a unresolved host and port
* @param hostname the unresolved hostname
* @param port the port
* @param family the address family
*/
NetworkAddress
(
const
char
*hostname =
"
"
, uint16 port =
0
,
int
family =
AF_UNSPEC
)
{
memset
(&
this
->
address
,
0
,
sizeof
(
this
->
address
));
this
->
address
.
ss_family
= family;
this
->
SetPort
(port);
}
uint16
GetPort
()
const
;
void
SetPort
(uint16 port);
};
/*
*
* Get the port.
* @return the port.
*/
uint16
NetworkAddress::GetPort
()
const
{
printf
(
"
Get PORT family: %d
\n
"
,
this
->
address
.
ss_family
);
switch
(
this
->
address
.
ss_family
) {
case
AF_UNSPEC
:
case
AF_INET
:
return
ntohs
(((
const
struct
sockaddr_in
*)&
this
->
address
)->
sin_port
);
case
AF_INET6
:
return
ntohs
(((
const
struct
sockaddr_in6
*)&
this
->
address
)->
sin6_port
);
default
:
throw
0
;
}
}
/*
*
* Set the port.
* @param port set the port number.
*/
void
NetworkAddress::SetPort
(uint16 port)
{
printf
(
"
Set PORT family: %d, port: %d
\n
"
,
this
->
address
.
ss_family
, port);
switch
(
this
->
address
.
ss_family
) {
case
AF_UNSPEC
:
case
AF_INET
:
((
struct
sockaddr_in
*)&
this
->
address
)->
sin_port
=
htons
(port);
break
;
case
AF_INET6
:
((
struct
sockaddr_in6
*)&
this
->
address
)->
sin6_port
=
htons
(port);
break
;
default
:
throw
0
;
}
}
int
main
() {
NetworkAddress
na
(
"
127.0.0.1
"
,
3979
);
printf
(
"
PORT: %d
\n
"
, na.
GetPort
());
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL