Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libdvbpsi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
libdvbpsi
Commits
8ba1a707
Commit
8ba1a707
authored
Jan 17, 2008
by
Thierry Thomas
Committed by
Jean-Paul Saman
Jan 17, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FreeBSD buildfix for examples/connect.c
parent
ea6adee5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
111 deletions
+113
-111
examples/connect.c
examples/connect.c
+113
-111
No files found.
examples/connect.c
View file @
8ba1a707
/*****************************************************************************
* connect.c: Routines for establishing a network connection.
*----------------------------------------------------------------------------
* Copyright (c) 2005 M2X
* $Id: connect.c 104 2005-03-21 13:38:56Z massiot $
*
* Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*----------------------------------------------------------------------------
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <net/if.h>
#if defined(WIN32)
# include <netinet/if_ether.h>
#endif
#include <netdb.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <arpa/inet.h>
int
create_tcp_connection
(
const
char
*
ipaddress
,
int
port
)
{
struct
sockaddr_in
addr_ctl
;
int
s_ctl
=
-
1
;
int
result
=
-
1
;
if
(
!
ipaddress
)
return
-
1
;
s_ctl
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
s_ctl
<=
0
)
{
perror
(
"tcp socket error"
);
return
-
1
;
}
addr_ctl
.
sin_family
=
AF_INET
;
addr_ctl
.
sin_addr
.
s_addr
=
inet_addr
(
ipaddress
);
addr_ctl
.
sin_port
=
htons
(
port
);
result
=
connect
(
s_ctl
,
(
struct
sockaddr
*
)
&
addr_ctl
,
sizeof
(
addr_ctl
)
);
if
(
result
<
0
)
{
perror
(
"tcp connect error"
);
return
-
1
;
}
return
s_ctl
;
}
int
close_connection
(
int
socket_fd
)
{
int
result
=
0
;
result
=
shutdown
(
socket_fd
,
2
);
if
(
result
<
0
)
perror
(
"shutdown error"
);
return
result
;
}
int
create_udp_connection
(
const
char
*
ipaddress
,
int
port
)
{
struct
sockaddr_in
addr_ctl
;
int
s_ctl
=
-
1
;
int
result
=
-
1
;
if
(
!
ipaddress
)
return
-
1
;
s_ctl
=
socket
(
PF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
if
(
s_ctl
<=
0
)
{
perror
(
"udp socket error"
);
return
-
1
;
}
addr_ctl
.
sin_family
=
AF_INET
;
addr_ctl
.
sin_addr
.
s_addr
=
inet_addr
(
ipaddress
);
addr_ctl
.
sin_port
=
htons
(
port
);
result
=
bind
(
s_ctl
,
(
struct
sockaddr
*
)
&
addr_ctl
,
sizeof
(
addr_ctl
));
if
(
result
<
0
)
{
perror
(
"udp bind error"
);
return
-
1
;
}
return
s_ctl
;
}
/*****************************************************************************
* connect.c: Routines for establishing a network connection.
*----------------------------------------------------------------------------
* Copyright (c) 2005 M2X
* $Id: connect.c 104 2005-03-21 13:38:56Z massiot $
*
* Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*----------------------------------------------------------------------------
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <net/if.h>
#if defined(WIN32)
# include <netinet/if_ether.h>
#endif
#include <netdb.h>
#ifndef __FreeBSD__
# include <netinet/ip.h>
#endif
#include <netinet/udp.h>
#include <arpa/inet.h>
int
create_tcp_connection
(
const
char
*
ipaddress
,
int
port
)
{
struct
sockaddr_in
addr_ctl
;
int
s_ctl
=
-
1
;
int
result
=
-
1
;
if
(
!
ipaddress
)
return
-
1
;
s_ctl
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
s_ctl
<=
0
)
{
perror
(
"tcp socket error"
);
return
-
1
;
}
addr_ctl
.
sin_family
=
AF_INET
;
addr_ctl
.
sin_addr
.
s_addr
=
inet_addr
(
ipaddress
);
addr_ctl
.
sin_port
=
htons
(
port
);
result
=
connect
(
s_ctl
,
(
struct
sockaddr
*
)
&
addr_ctl
,
sizeof
(
addr_ctl
)
);
if
(
result
<
0
)
{
perror
(
"tcp connect error"
);
return
-
1
;
}
return
s_ctl
;
}
int
close_connection
(
int
socket_fd
)
{
int
result
=
0
;
result
=
shutdown
(
socket_fd
,
2
);
if
(
result
<
0
)
perror
(
"shutdown error"
);
return
result
;
}
int
create_udp_connection
(
const
char
*
ipaddress
,
int
port
)
{
struct
sockaddr_in
addr_ctl
;
int
s_ctl
=
-
1
;
int
result
=
-
1
;
if
(
!
ipaddress
)
return
-
1
;
s_ctl
=
socket
(
PF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
if
(
s_ctl
<=
0
)
{
perror
(
"udp socket error"
);
return
-
1
;
}
addr_ctl
.
sin_family
=
AF_INET
;
addr_ctl
.
sin_addr
.
s_addr
=
inet_addr
(
ipaddress
);
addr_ctl
.
sin_port
=
htons
(
port
);
result
=
bind
(
s_ctl
,
(
struct
sockaddr
*
)
&
addr_ctl
,
sizeof
(
addr_ctl
));
if
(
result
<
0
)
{
perror
(
"udp bind error"
);
return
-
1
;
}
return
s_ctl
;
}
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