Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
80194503
Commit
80194503
authored
Mar 31, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement tcp_server_socket.
parent
0b4cbdf8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
net.c
net.c
+50
-0
net.h
net.h
+1
-0
No files found.
net.c
View file @
80194503
...
...
@@ -24,7 +24,9 @@ THE SOFTWARE.
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
...
...
@@ -152,3 +154,51 @@ babel_send(int s,
}
return
rc
;
}
int
tcp_server_socket
(
int
port
,
int
local
)
{
struct
sockaddr_in6
sin6
;
int
s
,
rc
,
saved_errno
;
int
one
=
1
;
s
=
socket
(
PF_INET6
,
SOCK_STREAM
,
0
);
if
(
s
<
0
)
return
-
1
;
rc
=
setsockopt
(
s
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
one
,
sizeof
(
one
));
if
(
rc
<
0
)
goto
fail
;
rc
=
fcntl
(
s
,
F_GETFL
,
0
);
if
(
rc
<
0
)
goto
fail
;
rc
=
fcntl
(
s
,
F_SETFL
,
(
rc
|
O_NONBLOCK
));
if
(
rc
<
0
)
goto
fail
;
memset
(
&
sin6
,
0
,
sizeof
(
sin6
));
sin6
.
sin6_family
=
AF_INET6
;
sin6
.
sin6_port
=
htons
(
port
);
if
(
local
)
{
rc
=
inet_pton
(
AF_INET6
,
"::1"
,
&
sin6
.
sin6_addr
);
if
(
rc
<
0
)
goto
fail
;
}
rc
=
bind
(
s
,
(
struct
sockaddr
*
)
&
sin6
,
sizeof
(
sin6
));
if
(
rc
<
0
)
goto
fail
;
rc
=
listen
(
s
,
2
);
if
(
rc
<
0
)
goto
fail
;
return
s
;
fail:
saved_errno
=
errno
;
close
(
s
);
errno
=
saved_errno
;
return
-
1
;
}
net.h
View file @
80194503
...
...
@@ -25,3 +25,4 @@ int babel_recv(int s, void *buf, int buflen, struct sockaddr *sin, int slen);
int
babel_send
(
int
s
,
const
void
*
buf1
,
int
buflen1
,
const
void
*
buf2
,
int
buflen2
,
const
struct
sockaddr
*
sin
,
int
slen
);
int
tcp_server_socket
(
int
port
,
int
local
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment