aboutsummaryrefslogtreecommitdiffstats
path: root/util/dvbnet/dvbnet.c
diff options
context:
space:
mode:
authoretobi <git@e-tobi.net>2013-09-03 09:48:41 +0200
committeretobi <git@e-tobi.net>2013-09-03 09:48:41 +0200
commitab959d7b4194715870128e616b8e29d4a101e488 (patch)
tree61a746231d30817be73416a7d67763fd677a1042 /util/dvbnet/dvbnet.c
parent6b350466c4902c5b137e0efaf1d189128a7f18f5 (diff)
downloadlinux-dvb-apps-ab959d7b4194715870128e616b8e29d4a101e488.tar.gz
Imported Upstream version 1.1.1+rev1207upstream/1.1.1+rev1207
Diffstat (limited to 'util/dvbnet/dvbnet.c')
-rw-r--r--util/dvbnet/dvbnet.c106
1 files changed, 54 insertions, 52 deletions
diff --git a/util/dvbnet/dvbnet.c b/util/dvbnet/dvbnet.c
index a58f156..53aa719 100644
--- a/util/dvbnet/dvbnet.c
+++ b/util/dvbnet/dvbnet.c
@@ -1,26 +1,29 @@
-/*
+/*
* dvbnet.c
*
* Copyright (C) 2003 TV Files S.p.A
* L.Y.Mesentsev <lymes@tiscalinet.it>
*
+ * Ported to use new DVB libraries:
+ * Copyright (C) 2006 Andrew de Quincey <adq_dvb@lidskialf.net>
+ *
* 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.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
- *
+ *
*/
#include <stdio.h>
@@ -33,19 +36,10 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
-
-#include <linux/dvb/net.h>
-#include <version.h>
-
-#ifndef VERSION_INFO
-#define VERSION_INFO "1.1.1"
-#endif
+#include <libdvbapi/dvbnet.h>
#define OK 0
#define FAIL -1
-#define DVB_NET_DEVICE "/dev/dvb/adapter%d/net%d"
-#define DVB_NET_DEVICES_MAX 10
-#define IFNAME_DVB "dvb"
enum Mode {
@@ -57,14 +51,15 @@ enum Mode {
static int adapter = 0;
static int netdev = 0;
-static struct dvb_net_if net_data;
static void hello(void);
static void usage(char *);
static void parse_args(int, char **);
-static int queryInterface(int, int);
+static void queryInterface(int);
-static char dvb_net_device[40];
+int ifnum;
+int pid;
+int encapsulation;
int main(int argc, char **argv)
{
@@ -74,40 +69,36 @@ int main(int argc, char **argv)
parse_args(argc, argv);
- sprintf(dvb_net_device, DVB_NET_DEVICE, adapter, netdev);
-
- printf("Device: %s\n", dvb_net_device);
-
- if ((fd_net = open(dvb_net_device, O_RDWR | O_NONBLOCK)) < 0) {
- fprintf(stderr, "Error: couldn't open device %s: %d %m\n",
- dvb_net_device, errno);
+ if ((fd_net = dvbnet_open(adapter, netdev)) < 0) {
+ fprintf(stderr, "Error: couldn't open device %d: %d %m\n",
+ netdev, errno);
return FAIL;
}
switch (op_mode) {
case DEL_INTERFACE:
- if (ioctl(fd_net, NET_REMOVE_IF, net_data.if_num))
+ if (dvbnet_remove_interface(fd_net, ifnum))
fprintf(stderr,
"Error: couldn't remove interface %d: %d %m.\n",
- net_data.if_num, errno);
+ ifnum, errno);
else
printf("Status: device %d removed successfully.\n",
- net_data.if_num);
+ ifnum);
break;
case ADD_INTERFACE:
- if (ioctl(fd_net, NET_ADD_IF, &net_data))
+ if ((ifnum = dvbnet_add_interface(fd_net, pid, encapsulation)) < 0)
fprintf(stderr,
"Error: couldn't add interface for pid %d: %d %m.\n",
- net_data.pid, errno);
+ pid, errno);
else
printf
("Status: device dvb%d_%d for pid %d created successfully.\n",
- adapter, net_data.if_num, net_data.pid);
+ adapter, ifnum, pid);
break;
case LST_INTERFACE:
- queryInterface(fd_net, 0);
+ queryInterface(fd_net);
break;
default:
@@ -120,39 +111,48 @@ int main(int argc, char **argv)
}
-int queryInterface(int fd_net, int dev)
+void queryInterface(int fd_net)
{
- struct dvb_net_if data;
- int IF, nIFaces = 0, ret = FAIL;
+ int IF, nIFaces = 0;
+ char *encap;
printf("Query DVB network interfaces:\n");
printf("-----------------------------\n");
- for (IF = 0; IF < DVB_NET_DEVICES_MAX; IF++) {
- data.if_num = IF;
- if (ioctl(fd_net, NET_GET_IF, &data))
+ for (IF = 0; IF < DVBNET_MAX_INTERFACES; IF++) {
+ uint16_t _pid;
+ enum dvbnet_encap _encapsulation;
+ if (dvbnet_get_interface(fd_net, IF, &_pid, &_encapsulation))
continue;
- if (dev == data.if_num)
- ret = OK;
+ encap = "???";
+ switch(_encapsulation) {
+ case DVBNET_ENCAP_MPE:
+ encap = "MPE";
+ break;
+ case DVBNET_ENCAP_ULE:
+ encap = "ULE";
+ break;
+ }
printf("Found device %d: interface dvb%d_%d, "
- "listening on PID %d\n",
- IF, adapter, data.if_num, data.pid);
+ "listening on PID %d, encapsulation %s\n",
+ IF, adapter, IF, _pid, encap);
nIFaces++;
}
printf("-----------------------------\n");
printf("Found %d interface(s).\n\n", nIFaces);
- return ret;
}
void parse_args(int argc, char **argv)
{
- char c, *s;
+ int c;
+ char *s;
op_mode = UNKNOWN;
- while ((c = getopt(argc, argv, "a:n:p:d:lvh")) != EOF) {
+ encapsulation = DVBNET_ENCAP_MPE;
+ while ((c = getopt(argc, argv, "a:n:p:d:lUvh")) != EOF) {
switch (c) {
case 'a':
adapter = strtol(optarg, NULL, 0);
@@ -161,16 +161,19 @@ void parse_args(int argc, char **argv)
netdev = strtol(optarg, NULL, 0);
break;
case 'p':
- net_data.pid = strtol(optarg, NULL, 0);
+ pid = strtol(optarg, NULL, 0);
op_mode = ADD_INTERFACE;
break;
case 'd':
- net_data.if_num = strtol(optarg, NULL, 0);
+ ifnum = strtol(optarg, NULL, 0);
op_mode = DEL_INTERFACE;
break;
case 'l':
op_mode = LST_INTERFACE;
break;
+ case 'U':
+ encapsulation = DVBNET_ENCAP_ULE;
+ break;
case 'v':
exit(OK);
case 'h':
@@ -187,12 +190,12 @@ void usage(char *prog_name)
{
fprintf(stderr, "Usage: %s [options]\n", prog_name);
fprintf(stderr, "Where options are:\n");
- fprintf(stderr, "\t-a AD : Adapter card AD (default 0)\n");
- fprintf(stderr, "\t-n NET : Net demux NET (default 0)\n");
+ fprintf(stderr, "\t-a AD : Adapter card (default 0)\n");
+ fprintf(stderr, "\t-n DD : Demux (default 0)\n");
fprintf(stderr, "\t-p PID : Add interface listening on PID\n");
- fprintf(stderr, "\t-d NUM : Remove interface dvbAD_NUM\n");
- fprintf(stderr,
- "\t-l : List currently available interfaces\n");
+ fprintf(stderr, "\t-d NUM : Remove interface NUM\n");
+ fprintf(stderr, "\t-l : List currently available interfaces\n");
+ fprintf(stderr, "\t-U : use ULE framing (default: MPE)\n" );
fprintf(stderr, "\t-v : Print current version\n\n");
}
@@ -200,6 +203,5 @@ void usage(char *prog_name)
void hello(void)
{
printf("\nDVB Network Interface Manager\n");
- printf("Version %s\n", VERSION_INFO);
printf("Copyright (C) 2003, TV Files S.p.A\n\n");
}