PERFORCE change 108718 for review
Michael Bushkov
bushman at FreeBSD.org
Mon Oct 30 09:29:09 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=108718
Change 108718 by bushman at bushman_nss_ldap_cached on 2006/10/30 09:28:15
IFC
Affected files ...
.. //depot/projects/soc2006/nss_ldap_cached/src/etc/defaults/rc.conf#10 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/etc/network.subr#5 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/etc/rc.firewall#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/gmon/Makefile.inc#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/inet.3#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/Makefile#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwcontrol.8#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwcontrol.c#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwdv.c#2 integrate
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwmethods.h#1 branch
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwmpegts.c#1 branch
Differences ...
==== //depot/projects/soc2006/nss_ldap_cached/src/etc/defaults/rc.conf#10 (text+ko) ====
@@ -15,7 +15,7 @@
# For a more detailed explanation of all the rc.conf variables, please
# refer to the rc.conf(5) manual page.
#
-# $FreeBSD: src/etc/defaults/rc.conf,v 1.300 2006/10/15 15:55:00 ceri Exp $
+# $FreeBSD: src/etc/defaults/rc.conf,v 1.301 2006/10/28 20:08:12 phk Exp $
##############################################################
### Important initial Boot-time options ####################
@@ -104,6 +104,16 @@
firewall_quiet="NO" # Set to YES to suppress rule display
firewall_logging="NO" # Set to YES to enable events logging
firewall_flags="" # Flags passed to ipfw when type is a file
+firewall_myservices="" # List of TCP ports on which this host
+ # offers services
+firewall_allowservices="" # List of IPs which has access to
+ # $firewall_myservices
+firewall_trusted="" # List of IPs which has full access to this host
+firewall_logdeny="NO" # Set to YES to log default denied incoming
+ # packets.
+firewall_nologports="135-139,445 1026,1027 1433,1434" # List of TCP/UDP ports
+ # for which denied incoming packets are not
+ # logged.
ip_portrange_first="NO" # Set first dynamically allocated port
ip_portrange_last="NO" # Set last dynamically allocated port
ike_enable="NO" # Enable IKE daemon (usually racoon or isakmpd)
==== //depot/projects/soc2006/nss_ldap_cached/src/etc/network.subr#5 (text+ko) ====
@@ -22,7 +22,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $FreeBSD: src/etc/network.subr,v 1.175 2006/10/07 15:45:56 ume Exp $
+# $FreeBSD: src/etc/network.subr,v 1.176 2006/10/29 13:29:49 mlaier Exp $
#
#
@@ -690,7 +690,7 @@
if [ ${rtsol_available} = yes -a ${rtsol_interface} = yes ]
then
case ${i} in
- lo0|gif[0-9]*|stf[0-9]*|faith[0-9]*|lp[0-9]*|sl[0-9]*|tun[0-9]*)
+ lo0|gif[0-9]*|stf[0-9]*|faith[0-9]*|lp[0-9]*|sl[0-9]*|tun[0-9]*|pflog[0-9]*|pfsync[0-9]*)
;;
*)
rtsol_interfaces="${rtsol_interfaces} ${i}"
==== //depot/projects/soc2006/nss_ldap_cached/src/etc/rc.firewall#2 (text+ko) ====
@@ -23,7 +23,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $FreeBSD: src/etc/rc.firewall,v 1.48 2005/11/18 02:23:59 ume Exp $
+# $FreeBSD: src/etc/rc.firewall,v 1.49 2006/10/28 20:08:12 phk Exp $
#
#
@@ -42,12 +42,14 @@
############
# Define the firewall type in /etc/rc.conf. Valid values are:
-# open - will allow anyone in
-# client - will try to protect just this machine
-# simple - will try to protect a whole network
-# closed - totally disables IP services except via lo0 interface
-# UNKNOWN - disables the loading of firewall rules.
-# filename - will load the rules in the given filename (full path required)
+# open - will allow anyone in
+# client - will try to protect just this machine
+# simple - will try to protect a whole network
+# closed - totally disables IP services except via lo0 interface
+# workstation - will try to protect just this machine using statefull
+# firewalling. See below for rc.conf variables used
+# UNKNOWN - disables the loading of firewall rules.
+# filename - will load the rules in the given filename (full path required)
#
# For ``client'' and ``simple'' the entries below should be customized
# appropriately.
@@ -107,6 +109,8 @@
#
${fwcmd} -f flush
+setup_loopback
+
############
# Network Address Translation. All packets are passed to natd(8)
# before they encounter your remaining rules. The firewall rules
@@ -140,7 +144,6 @@
#
case ${firewall_type} in
[Oo][Pp][Ee][Nn])
- setup_loopback
${fwcmd} add 65000 pass all from any to any
;;
@@ -155,8 +158,6 @@
mask="255.255.255.0"
ip="192.0.2.1"
- setup_loopback
-
# Allow any traffic to or from my own net.
${fwcmd} add pass all from ${ip} to ${net}:${mask}
${fwcmd} add pass all from ${net}:${mask} to ${ip}
@@ -168,19 +169,19 @@
${fwcmd} add pass all from any to any frag
# Allow setup of incoming email
- ${fwcmd} add pass tcp from any to ${ip} 25 setup
+ ${fwcmd} add pass tcp from any to me 25 setup
# Allow setup of outgoing TCP connections only
- ${fwcmd} add pass tcp from ${ip} to any setup
+ ${fwcmd} add pass tcp from me to any setup
# Disallow setup of all other TCP connections
${fwcmd} add deny tcp from any to any setup
# Allow DNS queries out in the world
- ${fwcmd} add pass udp from ${ip} to any 53 keep-state
+ ${fwcmd} add pass udp from me to any 53 keep-state
# Allow NTP queries out in the world
- ${fwcmd} add pass udp from ${ip} to any 123 keep-state
+ ${fwcmd} add pass udp from me to any 123 keep-state
# Everything else is denied by default, unless the
# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
@@ -206,8 +207,6 @@
imask="255.255.255.240"
iip="192.0.2.17"
- setup_loopback
-
# Stop spoofing
${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}
@@ -289,8 +288,100 @@
# config file.
;;
+[Ww][Oo][Rr][Kk][Ss][Tt][Aa][Tt][Ii][Oo][Nn])
+ # Configuration:
+ # firewall_myservices: List of TCP ports on which this host
+ # offers services.
+ # firewall_allowservices: List of IPs which has access to
+ # $firewall_myservices.
+ # firewall_trusted: List of IPs which has full access
+ # to this host. Be very carefull
+ # when setting this. This option can
+ # seriously degrade the level of
+ # protection provided by the firewall.
+ # firewall_logdeny: Boolean (YES/NO) specifying if the
+ # default denied packets should be
+ # logged (in /var/log/security).
+ # firewall_nologports: List of TCP/UDP ports for which
+ # denied incomming packets are not
+ # logged.
+
+ # Allow packets for which a state has been built.
+ ${fwcmd} add check-state
+
+ # For services permitted below.
+ ${fwcmd} add pass tcp from me to any established
+
+ # Allow any connection out, adding state for each.
+ ${fwcmd} add pass tcp from me to any setup keep-state
+ ${fwcmd} add pass udp from me to any keep-state
+ ${fwcmd} add pass icmp from me to any keep-state
+
+ # Allow DHCP.
+ ${fwcmd} add pass udp from 0.0.0.0 68 to 255.255.255.255 67 out
+ ${fwcmd} add pass udp from any 67 to me 68 in
+ ${fwcmd} add pass udp from any 67 to 255.255.255.255 68 in
+ # Some servers will ping the IP while trying to decide if it's
+ # still in use.
+ ${fwcmd} add pass icmp from any to any icmptype 8
+
+ # Allow "mandatory" ICMP in.
+ ${fwcmd} add pass icmp from any to any icmptype 3,4,11
+
+ # Add permits for this workstations published services below
+ # Only IPs and nets in firewall_allowservices is allowed in.
+ # If you really wish to let anyone use services on your
+ # workstation, then set "firewall_allowservices='any'" in /etc/rc.conf
+ #
+ # Note: We don't use keep-state as that would allow DoS of
+ # our statetable.
+ # You can add 'keep-state' to the lines for slightly
+ # better performance if you fell that DoS of your
+ # workstation won't be a problem.
+ #
+ for i in ${firewall_allowservices} ; do
+ for j in ${firewall_myservices} ; do
+ ${fwcmd} add pass tcp from $i to me $j
+ done
+ done
+
+ # Allow all connections from trusted IPs.
+ # Playing with the content of firewall_trusted could seriously
+ # degrade the level of protection provided by the firewall.
+ for i in ${firewall_trusted} ; do
+ ${fwcmd} add pass ip from $i to me
+ done
+
+ ${fwcmd} add 65000 count ip from any to any
+
+ # Drop packets to ports where we don't want logging
+ for i in ${firewall_nologports} ; do
+ ${fwcmd} add deny { tcp or udp } from any to any $i in
+ done
+
+ # Broadcasts and muticasts
+ ${fwcmd} add deny ip from any to 255.255.255.255
+ ${fwcmd} add deny ip from any to 224.0.0.0/24 in # XXX
+
+ # Noise from routers
+ ${fwcmd} add deny udp from any to any 520 in
+
+ # Noise from webbrowsing.
+ # The statefull filter is a bit agressive, and will cause some
+ # connection teardowns to be logged.
+ ${fwcmd} add deny tcp from any 80,443 to any 1024-65535 in
+
+ # Deny and (if wanted) log the rest unconditionally.
+ log=""
+ if [ ${firewall_logdeny:-x} = "YES" -o ${firewall_logdeny:-x} = "yes" ] ; then
+ log="log logamount 500" # The default of 100 is too low.
+ sysctl net.inet.ip.fw.verbose=1 >/dev/null
+ fi
+ ${fwcmd} add deny $log ip from any to any
+ ;;
+
[Cc][Ll][Oo][Ss][Ee][Dd])
- setup_loopback
+ ${fwcmd} add 65000 deny ip from any to any
;;
[Uu][Nn][Kk][Nn][Oo][Ww][Nn])
;;
==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/gmon/Makefile.inc#2 (text+ko) ====
@@ -1,5 +1,5 @@
# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
-# $FreeBSD: src/lib/libc/gmon/Makefile.inc,v 1.11 2006/03/13 01:14:56 deischen Exp $
+# $FreeBSD: src/lib/libc/gmon/Makefile.inc,v 1.12 2006/10/28 13:34:35 bde Exp $
# gmon sources
.PATH: ${.CURDIR}/gmon
@@ -12,12 +12,6 @@
MLINKS+=moncontrol.3 monstartup.3
-.if ${MACHINE_ARCH} == amd64
-# mcount needs to be compiled with frame pointers and without profiling
-mcount.po: mcount.c
- ${CC} ${CFLAGS} -fno-omit-frame-pointer -c ${.IMPSRC} -o ${.TARGET}
-.else
# mcount cannot be compiled with profiling
mcount.po: mcount.o
cp mcount.o mcount.po
-.endif
==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/inet.3#2 (text+ko) ====
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.30 2005/02/13 22:25:12 ru Exp $
+.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.31 2006/10/28 13:05:10 ru Exp $
.\"
.Dd June 14, 2004
.Dt INET 3
@@ -299,5 +299,7 @@
.Fn inet_ntoa
resides in a static memory area.
.Pp
-Inet_addr should return a
+The
+.Fn inet_addr
+function should return a
.Fa struct in_addr .
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/Makefile#2 (text+ko) ====
@@ -1,8 +1,9 @@
-# $FreeBSD: src/usr.sbin/fwcontrol/Makefile,v 1.4 2003/04/30 03:39:25 simokawa Exp $
+# $FreeBSD: src/usr.sbin/fwcontrol/Makefile,v 1.5 2006/10/26 22:33:38 imp Exp $
PROG= fwcontrol
-SRCS= fwcontrol.c fwcrom.c fwdv.c
+SRCS= fwcontrol.c fwcrom.c fwdv.c fwmpegts.c
MAN= fwcontrol.8
+WARNS= 3
.PATH: ${.CURDIR}/../../sys/dev/firewire
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwcontrol.8#2 (text+ko) ====
@@ -22,9 +22,9 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.8,v 1.16 2005/01/18 20:02:34 ru Exp $
+.\" $FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.8,v 1.17 2006/10/26 22:33:38 imp Exp $
.\"
-.Dd December 14, 2004
+.Dd October 24, 2006
.Dt FWCONTROL 8
.Os
.Sh NAME
@@ -41,6 +41,7 @@
.Op Fl l Ar file
.Op Fl g Ar gap_count
.Op Fl b Ar pri_req
+.Op Fl M Ar mode
.Op Fl R Ar filename
.Op Fl S Ar filename
.Op Fl m Ar EUI64 | hostname
@@ -84,8 +85,18 @@
Set the
.Dv PRIORITY_BUDGET
register on all supported nodes.
+.It Fl M Ar mode
+Explicitly specify either
+.Ar dv
+or
+.Ar mpeg
+mode for the incoming stream.
+Only meaningful in case of and must preceed the
+.Fl R
+option. If not specified, the program will try to guess. If you get
+an error complaining about "format 0x20", try to force the "mpeg" mode.
.It Fl R Ar filename
-Receive DV stream and dump it to a file.
+Receive DV or MPEG TS stream and dump it to a file.
Use Ctrl-C to stop the receiving.
Some DV cameras seem not to send the stream if a bus manager exits.
If you cannot get the stream, try the following commands:
@@ -100,7 +111,14 @@
.Nm libdv
in the
.Fx
-Ports Collection.
+Ports Collection. Resulting MPEG TS stream can be played and sent over a
+network using the VideoLAN
+.Nm vlc
+tool in the
+.Fx
+Ports Collection. The stream can be piped directly to
+.Nm vlc,
+see EXAMPLES.
.It Fl S Ar filename
Send a DV file as isochronous stream.
.It Fl m Ar EUI64 | hostname
@@ -117,7 +135,7 @@
.Pp
.Dl "fwcontrol -R original.dv"
.Pp
-Receive stream.
+Receive a DV stream with DV camera attached.
.Pp
.Dl "dd if=original.dv of=first.dv bs=120000 count=30"
.Pp
@@ -135,12 +153,42 @@
.Dq Li bs=120000
with
.Dq Li bs=144000 .
+.Pp
+.Dl "fwcontrol -R file.m2t
+.Pp
+Receive an MPEG TS stream from a camera producing MPEG transport stream. This
+has been tested with SONY HDR-FX1E camera that produces HD MPEG-2 stream at
+25 Mbps bandwidth.
+.Pp
+To send the stream from the camera over the network using TCP (which supprisingly works better with vlc), you can use
+.Dl "fwcontrol -R - | nc 192.168.10.11 9000
+with
+.Nm netcat
+from ports and to receive the stream, use
+.Dl nc -l -p 9000 | vlc -
+.Pp
+To netcast via UDP, you need to use
+.Nm buffer
+program from ports, since vlc is not fast enough to read UDP packets from
+buffers and thus it experiences dropouts when run directly. The sending side
+can use
+.Dl "fwcontrol -R - | nc 192.168.10.11 9000
+and to receive the stream, use
+.Dl nc -l -u -p 9000 | buffer -s 10k -b 1000 -m 20m -p 5 | vlc -
+.Pp
+
+.Pp
+For more information on how to work with
+.Nm vlc
+see its docs.
.Sh SEE ALSO
.Xr firewire 4 ,
.Xr fwe 4 ,
.Xr fwip 4 ,
.Xr fwohci 4 ,
-.Xr sbp 4
+.Xr sbp 4 ,
+.Xr mplayer 1 ,
+.Xr vlc 1
.Sh HISTORY
The
.Nm
@@ -148,5 +196,9 @@
.Fx 5.0 .
.Sh AUTHORS
.An Hidetoshi Shimokawa Aq simokawa at FreeBSD.org
+.An Petr Holub Aq hopet at ics.muni.cz
+- MPEG TS mode.
.Sh BUGS
This utility is still under development and provided for debugging purposes.
+Especially MPEG TS reception support is very rudimental and supports only
+high-bandwidth MPEG-2 streams (fn field in CIP header equals 3).
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwcontrol.c#2 (text+ko) ====
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.c,v 1.22 2005/05/20 12:50:47 charnier Exp $");
+__FBSDID("$FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.c,v 1.23 2006/10/26 22:33:38 imp Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
@@ -46,6 +46,7 @@
#include <dev/firewire/firewire.h>
#include <dev/firewire/iec13213.h>
#include <dev/firewire/fwphyreg.h>
+#include <dev/firewire/iec68113.h>
#include <netinet/in.h>
#include <fcntl.h>
@@ -53,12 +54,11 @@
#include <err.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
+#include "fwmethods.h"
-extern int dvrecv(int, char *, char, int);
-extern int dvsend(int, char *, char, int);
-
-int sysctl_set_int(const char *, int);
+static void sysctl_set_int(const char *, int);
static void
usage(void)
@@ -77,10 +77,10 @@
"\t-t: read topology map\n"
"\t-d: hex dump of configuration ROM\n"
"\t-l: load and parse hex dump file of configuration ROM\n"
- "\t-R: Receive DV stream\n"
+ "\t-R: Receive DV or MPEG TS stream\n"
"\t-S: Send DV stream\n"
"\t-m: set fwmem target\n");
- exit(0);
+ exit(EX_USAGE);
}
static void
@@ -276,7 +276,7 @@
}
static void
-set_pri_req(int fd, int pri_req)
+set_pri_req(int fd, u_int32_t pri_req)
{
struct fw_devlstreq *data;
struct fw_devinfo *devinfo;
@@ -296,7 +296,7 @@
eui64_ntoa(&eui, addr, sizeof(addr));
printf("%d %s, %08x",
devinfo->dst, addr, reg);
- if (reg > 0 && pri_req >= 0) {
+ if (reg > 0) {
old = (reg & 0x3f);
max = (reg & 0x3f00) >> 8;
if (pri_req > max)
@@ -311,7 +311,7 @@
}
static void
-parse_bus_info_block(u_int32_t *p, int info_len)
+parse_bus_info_block(u_int32_t *p)
{
char addr[EUI64_SIZ];
struct bus_info *bi;
@@ -392,7 +392,7 @@
printf("(OK)\n");
else
printf("(NG)\n");
- parse_bus_info_block(crom_buf+1, hdr->info_len);
+ parse_bus_info_block(crom_buf+1);
crom_init_context(&cc, crom_buf);
dir = cc.stack[0].dir;
@@ -603,21 +603,71 @@
}
}
-int
+static void
sysctl_set_int(const char *name, int val)
{
if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0)
err(1, "sysctl %s failed.", name);
}
+static fwmethod *
+detect_recv_fn(int fd, char ich)
+{
+ char *buf;
+ struct fw_isochreq isoreq;
+ struct fw_isobufreq bufreq;
+ int len;
+ u_int32_t *ptr;
+ struct ciphdr *ciph;
+ fwmethod *retfn;
+
+ bufreq.rx.nchunk = 8;
+ bufreq.rx.npacket = 16;
+ bufreq.rx.psize = 1024;
+ bufreq.tx.nchunk = 0;
+ bufreq.tx.npacket = 0;
+ bufreq.tx.psize = 0;
+
+ if (ioctl(fd, FW_SSTBUF, &bufreq) < 0)
+ err(1, "ioctl FW_SSTBUF");
+
+ isoreq.ch = ich & 0x3f;
+ isoreq.tag = (ich >> 6) & 3;
+
+ if (ioctl(fd, FW_SRSTREAM, &isoreq) < 0)
+ err(1, "ioctl FW_SRSTREAM");
+
+ buf = (char *)malloc(1024*16);
+ len = read(fd, buf, 1024*16);
+ ptr = (u_int32_t *) buf;
+ ciph = (struct ciphdr *)(ptr + 1);
+
+ switch(ciph->fmt) {
+ case CIP_FMT_DVCR:
+ fprintf(stderr, "Detected DV format on input.\n");
+ retfn = dvrecv;
+ break;
+ case CIP_FMT_MPEG:
+ fprintf(stderr, "Detected MPEG TS format on input.\n");
+ retfn = mpegtsrecv;
+ break;
+ default:
+ errx(1, "Unsupported format for receiving: fmt=0x%x", ciph->fmt);
+ }
+ free(buf);
+ return retfn;
+}
+
int
main(int argc, char **argv)
{
u_int32_t crom_buf[1024/4];
char devbase[1024] = "/dev/fw0";
- int fd, tmp, ch, len=1024;
+ int fd, ch, len=1024;
+ long tmp;
struct fw_eui64 eui;
struct eui64 target;
+ fwmethod *recvfn = NULL;
fd = -1;
@@ -626,10 +676,12 @@
list_dev(fd);
}
- while ((ch = getopt(argc, argv, "g:m:o:s:b:prtc:d:l:u:R:S:")) != -1)
+ while ((ch = getopt(argc, argv, "M:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1)
switch(ch) {
case 'b':
tmp = strtol(optarg, NULL, 0);
+ if (tmp < 0 || tmp > (long)0xffffffff)
+ errx(EX_USAGE, "invalid number: %s", optarg);
open_dev(&fd, devbase);
set_pri_req(fd, tmp);
break;
@@ -657,7 +709,7 @@
case 'm':
if (eui64_hostton(optarg, &target) != 0 &&
eui64_aton(optarg, &target) != 0)
- errx(1, "invalid target: %s", optarg);
+ errx(EX_USAGE, "invalid target: %s", optarg);
eui.hi = ntohl(*(u_int32_t*)&(target.octet[0]));
eui.lo = ntohl(*(u_int32_t*)&(target.octet[4]));
sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi);
@@ -688,7 +740,7 @@
break;
case 'u':
tmp = strtol(optarg, NULL, 0);
- snprintf(devbase, sizeof(devbase), "/dev/fw%d", tmp);
+ snprintf(devbase, sizeof(devbase), "/dev/fw%ld", tmp);
if (fd > 0) {
close(fd);
fd = -1;
@@ -700,9 +752,27 @@
break;
#define TAG (1<<6)
#define CHANNEL 63
+ case 'M':
+ switch (optarg[0]) {
+ case 'm':
+ recvfn = mpegtsrecv;
+ break;
+ case 'd':
+ recvfn = dvrecv;
+ break;
+ default:
+ errx(EX_USAGE, "unrecognized method: %s",
+ optarg);
+ }
+ break;
case 'R':
open_dev(&fd, devbase);
- dvrecv(fd, optarg, TAG | CHANNEL, -1);
+ if (recvfn == NULL) /* guess... */
+ recvfn = detect_recv_fn(fd, TAG | CHANNEL);
+ close(fd);
+ fd = -1;
+ open_dev(&fd, devbase);
+ (*recvfn)(fd, optarg, TAG | CHANNEL, -1);
break;
case 'S':
open_dev(&fd, devbase);
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/fwcontrol/fwdv.c#2 (text+ko) ====
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2003
* Hidetoshi Shimokawa. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -18,7 +18,7 @@
* 4. Neither the name of the author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -30,8 +30,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.sbin/fwcontrol/fwdv.c,v 1.5 2003/04/17 03:38:03 simokawa Exp $
+ *
+ * $FreeBSD: src/usr.sbin/fwcontrol/fwdv.c,v 1.6 2006/10/26 22:33:38 imp Exp $
*/
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -50,15 +50,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <dev/firewire/firewire.h>
#include <dev/firewire/iec68113.h>
+#include "fwmethods.h"
+
#define DEBUG 0
#define FIX_FRAME 1
struct frac {
- int n,d;
+ int n,d;
};
struct frac frame_cycle[2] = {
@@ -88,8 +91,8 @@
#define MAXBLOCKS (300)
#define CYCLE_FRAC 0xc00
-int
-dvrecv(int d, char *filename, char ich, int count)
+void
+dvrecv(int d, const char *filename, char ich, int count)
{
struct fw_isochreq isoreq;
struct fw_isobufreq bufreq;
@@ -102,9 +105,15 @@
int nblocks[] = {250 /* NTSC */, 300 /* PAL */};
struct iovec wbuf[NPACKET_R];
- fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660);
- buf = (char *)malloc(RBUFSIZE);
- pad = (char *)malloc(DSIZE*MAXBLOCKS);
+ if(strcmp(filename, "-") == 0) {
+ fd = STDOUT_FILENO;
+ } else {
+ fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660);
+ if (fd == -1)
+ err(EX_NOINPUT, filename);
+ }
+ buf = malloc(RBUFSIZE);
+ pad = malloc(DSIZE*MAXBLOCKS);
memset(pad, 0xff, DSIZE*MAXBLOCKS);
bzero(wbuf, sizeof(wbuf));
@@ -114,14 +123,13 @@
bufreq.tx.nchunk = 0;
bufreq.tx.npacket = 0;
bufreq.tx.psize = 0;
- if (ioctl(d, FW_SSTBUF, &bufreq) < 0) {
- err(1, "ioctl");
- }
+ if (ioctl(d, FW_SSTBUF, &bufreq) < 0)
+ err(1, "ioctl FW_SSTBUF");
isoreq.ch = ich & 0x3f;
isoreq.tag = (ich >> 6) & 3;
- if( ioctl(d, FW_SRSTREAM, &isoreq) < 0)
+ if (ioctl(d, FW_SRSTREAM, &isoreq) < 0)
err(1, "ioctl");
k = m = 0;
@@ -147,7 +155,7 @@
tlen = len = read(d, buf, RBUFSIZE);
if (len < 0) {
if (errno == EAGAIN) {
- fprintf(stderr, "(EAGAIN)\n");
+ fprintf(stderr, "(EAGAIN) - push 'Play'?\n");
fflush(stderr);
if (len <= 0)
continue;
@@ -158,7 +166,7 @@
vec = 0;
ptr = (u_int32_t *) buf;
again:
- pkt = (struct fw_pkt *) ptr;
+ pkt = (struct fw_pkt *) ptr;
#if DEBUG
fprintf(stderr, "%08x %08x %08x %08x\n",
htonl(ptr[0]), htonl(ptr[1]),
@@ -186,7 +194,7 @@
if (dv->sct == DV_SCT_HEADER && dv->dseq == 0) {
if (system < 0) {
system = ciph->fdf.dv.fs;
- printf("%s\n", system_name[system]);
+ fprintf(stderr, "%s\n", system_name[system]);
}
/* Fix DSF bit */
@@ -237,21 +245,22 @@
if (vec > 0)
writev(fd, wbuf, vec);
}
- close(fd);
+ if(fd != STDOUT_FILENO) {
+ close(fd);
+ }
fprintf(stderr, "\n");
- return 0;
}
-int
-dvsend(int d, char *filename, char ich, int count)
+void
+dvsend(int d, const char *filename, char ich, int count)
{
struct fw_isochreq isoreq;
struct fw_isobufreq bufreq;
struct dvdbc *dv;
struct fw_pkt *pkt;
int len, tlen, header, fd, frames, packets, vec, offset, nhdr, i;
- int system=-1, pad_acc, cycle_acc, cycle, f_cycle, f_frac;
+ int system=-1, pad_acc, cycle_acc, cycle, f_cycle, f_frac;
struct iovec wbuf[TNBUF*2 + NEMPTY];
char *pbuf;
u_int32_t iso_data, iso_empty, hdr[TNBUF + NEMPTY][3];
@@ -260,7 +269,10 @@
double rtime;
fd = open(filename, O_RDONLY);
- pbuf = (char *)malloc(DSIZE * TNBUF);
+ if (fd == -1)
+ err(EX_NOINPUT, filename);
+
+ pbuf = malloc(DSIZE * TNBUF);
bzero(wbuf, sizeof(wbuf));
bufreq.rx.nchunk = 0;
@@ -269,15 +281,14 @@
bufreq.tx.nchunk = NCHUNK;
bufreq.tx.npacket = NPACKET_T;
bufreq.tx.psize = PSIZE;
- if (ioctl(d, FW_SSTBUF, &bufreq) < 0) {
- err(1, "ioctl");
- }
+ if (ioctl(d, FW_SSTBUF, &bufreq) < 0)
+ err(1, "ioctl FW_SSTBUF");
isoreq.ch = ich & 0x3f;
isoreq.tag = (ich >> 6) & 3;
- if( ioctl(d, FW_STSTREAM, &isoreq) < 0)
- err(1, "ioctl");
+ if (ioctl(d, FW_STSTREAM, &isoreq) < 0)
+ err(1, "ioctl FW_STSTREAM");
iso_data = 0;
pkt = (struct fw_pkt *) &iso_data;
@@ -298,9 +309,8 @@
ciph->eoh1 = 1;
ciph->fdf.dv.cyc = 0xffff;
- for (i = 1; i < TNBUF; i++) {
+ for (i = 1; i < TNBUF; i++)
bcopy(hdr[0], hdr[i], sizeof(hdr[0]));
- }
gettimeofday(&start, NULL);
#if DEBUG
@@ -320,7 +330,7 @@
if (len < 0)
warn("read");
else
- printf("\nend of file\n");
+ fprintf(stderr, "\nend of file\n");
goto send_end;
}
tlen += len;
@@ -391,8 +401,7 @@
len = writev(d, wbuf, vec);
if (len < 0) {
if (errno == EAGAIN) {
- fprintf(stderr, "(EAGAIN)\n");
- fflush(stderr);
+ fprintf(stderr, "(EAGAIN) - push 'Play'?\n");
goto again;
}
err(1, "write failed");
@@ -402,9 +411,8 @@
fprintf(stderr, "\n");
send_end:
gettimeofday(&end, NULL);
- rtime = end.tv_sec - start.tv_sec
+ rtime = end.tv_sec - start.tv_sec
+ (end.tv_usec - start.tv_usec) * 1e-6;
fprintf(stderr, "%d frames, %.2f secs, %.2f frames/sec\n",
frames, rtime, frames/rtime);
- return 0;
}
More information about the p4-projects
mailing list