diff -ru vic-2.8ucl-1.1.3.orig/common/mbus_config.h vic-2.8ucl-1.1.3/common/mbus_config.h
--- vic-2.8ucl-1.1.3.orig/common/mbus_config.h	Thu Feb 17 12:59:36 2000
+++ vic-2.8ucl-1.1.3/common/mbus_config.h	Tue Mar  7 18:00:44 2000
@@ -66,7 +66,7 @@
 void mbus_unlock_config_file(struct mbus_config *m);
 void mbus_get_encrkey(struct mbus_config *m, struct mbus_key *key);
 void mbus_get_hashkey(struct mbus_config *m, struct mbus_key *key);
-void mbus_get_net_addr(struct mbus_config *m, char *net_addr, uint16_t *net_port, int *net_scope);
+void mbus_get_net_addr(struct mbus_config *m, char *net_addr, u_int16_t *net_port, int *net_scope);
 int  mbus_get_version(struct mbus_config *m);
 struct mbus_config *mbus_create_config(void);
diff -ru vic-2.8ucl-1.1.3.orig/vic/Makefile.in vic-2.8ucl-1.1.3/vic/Makefile.in
--- vic-2.8ucl-1.1.3.orig/vic/Makefile.in	Thu Feb 17 12:59:08 2000
+++ vic-2.8ucl-1.1.3/vic/Makefile.in	Thu Mar 16 16:06:05 2000
@@ -118,8 +118,8 @@
 	codec/h263/idctenc.o codec/h263/sac.o
 
 # .c objects
-OBJ1 =	net/inet.o net/inet6.o codec/cellb_tables.o tkStripchart.o md5c.o random.o \
-	$(H263_OBJS)
+OBJ1 =	net/inet.o net/inet6.o codec/cellb_tables.o tkStripchart.o md5c.o \
+	random.o net/tos-set.o net/tos-recv.o $(H263_OBJS)
 #	session-rtpv1.o session-nv.o session-ivs.o # Not supported anymore
 # .cpp objects
 OBJ2 =	main.o iohandler.o timer.o idlecallback.o media-timer.o \
diff -ru vic-2.8ucl-1.1.3.orig/vic/config.h vic-2.8ucl-1.1.3/vic/config.h
--- vic-2.8ucl-1.1.3.orig/vic/config.h	Fri Dec 10 16:25:31 1999
+++ vic-2.8ucl-1.1.3/vic/config.h	Thu Mar 16 16:05:00 2000
@@ -87,7 +87,8 @@
 #include <stdlib.h>
 #include <time.h>		/* For clock_t */
 
-
+/* Compile with ECN features? */
+#define ECN_AWARE
 
 #if defined(NEED_SUNOS_PROTOS)
 #if defined(__cplusplus)
diff -ru vic-2.8ucl-1.1.3.orig/vic/net/net-ip.cpp vic-2.8ucl-1.1.3/vic/net/net-ip.cpp
--- vic-2.8ucl-1.1.3.orig/vic/net/net-ip.cpp	Fri Nov  5 11:17:50 1999
+++ vic-2.8ucl-1.1.3/vic/net/net-ip.cpp	Thu Mar 16 18:31:17 2000
@@ -54,6 +54,9 @@
 #include "vic_tcl.h"
 
 #include "net-addr.h"
+#ifdef ECN_AWARE
+#include "ecn.h"
+#endif
 
 #ifndef INET_ADDRSTRLEN
 #define INET_ADDRSTRLEN (16)
@@ -100,7 +103,7 @@
 	virtual int command(int argc, const char*const* argv);
 	virtual void reset();
     protected:
-	virtual int dorecv(u_char* buf, int len, Address &from, int fd);
+	virtual int dorecv(u_char* buf, int len, Address &from, int fd, int *tos);
 	int open(const char * host, int port, int ttl);
 	int close();
 	int localname(sockaddr_in*);
@@ -285,6 +288,10 @@
 	u_int32_t addri = (IPAddress&)addr;
 	u_int32_t locali = (IPAddress&)local;
 
+	/* and1000 */
+	printf ("IPNetwork::openrsock: %08x %08x\n",
+		ntohl (addri), ntohl (locali));
+
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
 		perror("socket");
@@ -383,6 +390,13 @@
 				sizeof(bufsize)) < 0)
 			perror("SO_RCVBUF");
 	}
+
+#ifdef ECN_AWARE
+	/* We want to receive TOS bytes with our data, please. */
+	if (socket_setrecvtos (fd, TRUE) < 0)
+	    perror ("socket_setrecvtos");
+#endif /* ECN_AWARE */
+
 	return (fd);
 }
 
@@ -393,6 +407,8 @@
 
 	u_int32_t addri = (IPAddress&)addr;
 
+	printf ("IPNetwork::openssock: %08x\n", ntohl(addri));
+
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
 		perror("socket");
@@ -465,12 +481,33 @@
 			       sizeof(bufsize)) < 0)
 			perror("SO_SNDBUF");
 	}
+
+#ifdef ECN_AWARE
+	/* Turn on ECT (ECN Capable Transport) bit in TOS byte on all
+         * the stuff we send out. */
+	if (socket_settos (fd, TOS_ECN_ECT) < 0)
+	    perror ("socket_settos");
+#endif /* ECN_AWARE */
+	    
+
 	return (fd);
 }
 
 
 
-int IPNetwork::dorecv(u_char* buf, int len, Address & from, int fd)
+static void
+dump (unsigned char *buf, int len)
+{
+    int i;
+
+    for(i=0; i<len; i++)
+	printf ("%02x%s%s", buf[i],
+		i&1? " " : "",
+		(i%16)==15? "\n" : "");
+}
+
+
+int IPNetwork::dorecv(u_char* buf, int len, Address & from, int fd, int *tos)
 {
 	sockaddr_in sfrom;
 #ifndef WIN32
@@ -478,8 +515,16 @@
 #else
 	int fromlen = sizeof(sfrom);
 #endif
+
+#ifdef ECN_AWARE
+	int cc = ::recvfrom_withtos(fd, (char*)buf, len, 0,
+				    (sockaddr*)&sfrom, &fromlen, tos);
+#else
 	int cc = ::recvfrom(fd, (char*)buf, len, 0,
 			    (sockaddr*)&sfrom, &fromlen);
+	*tos = 0;
+#endif /* ECN_AWARE */
+
 	if (cc < 0) {
 		if (errno != EWOULDBLOCK)
 			perror("recvfrom");
diff -ru vic-2.8ucl-1.1.3.orig/vic/net/net.cpp vic-2.8ucl-1.1.3/vic/net/net.cpp
--- vic-2.8ucl-1.1.3.orig/vic/net/net.cpp	Fri Nov  5 11:17:50 1999
+++ vic-2.8ucl-1.1.3/vic/net/net.cpp	Thu Mar 16 17:40:25 2000
@@ -387,17 +387,17 @@
 }
 
 
-int Network::recv(u_char* buf, int len, Address & from)
+int Network::recv(u_char* buf, int len, Address & from, int *tos)
 {
 	if (crypt_) {
 		if (len > wrkbuflen_)
 			expand_wrkbuf(len);
-		int cc = dorecv(wrkbuf_, len, from, rsock_);
+		int cc = dorecv(wrkbuf_, len, from, rsock_, tos);
 		if (cc!=0) {
 			return (crypt_->Decrypt(wrkbuf_, cc, buf));
 		} else return 0;
 	}
-	return (dorecv(buf, len, from, rsock_));
+	return (dorecv(buf, len, from, rsock_, tos));
 }
 
 void Network::reset()
diff -ru vic-2.8ucl-1.1.3.orig/vic/net/net.h vic-2.8ucl-1.1.3/vic/net/net.h
--- vic-2.8ucl-1.1.3.orig/vic/net/net.h	Fri Nov  5 11:17:50 1999
+++ vic-2.8ucl-1.1.3/vic/net/net.h	Thu Mar 16 17:46:29 2000
@@ -82,7 +82,7 @@
 	//virtual void send(const msghdr& mh);
 	virtual void send(const pktbuf* );
 	virtual int recv(u_char* buf, int len, u_int32_t& from);
-	virtual int recv(u_char* buf, int len, Address &from);
+	virtual int recv(u_char* buf, int len, Address &from, int *tos);
 	inline int rchannel() const { return (rsock_); }
 	inline int schannel() const { return (ssock_); }
 	inline const Address & addr() const { return (addr_); }
@@ -96,7 +96,7 @@
     protected:
 	virtual void dosend(u_char* buf, int len, int fd);
         virtual int dorecv(u_char* buf, int len, u_int32_t& from, int fd);
-	virtual int dorecv(u_char* buf, int len, Address &from, int fd) {UNUSED(buf); UNUSED(len); UNUSED(from); UNUSED(fd); return (0);}
+	virtual int dorecv(u_char* buf, int len, Address &from, int fd, int *tos) {UNUSED(buf); UNUSED(len); UNUSED(from); UNUSED(fd); UNUSED(tos); return (0);}
 
 	Address & addr_;
 	Address & local_;
diff -ru vic-2.8ucl-1.1.3.orig/vic/rtp/session.cpp vic-2.8ucl-1.1.3/vic/rtp/session.cpp
--- vic-2.8ucl-1.1.3.orig/vic/rtp/session.cpp	Fri Nov  5 11:24:16 1999
+++ vic-2.8ucl-1.1.3/vic/rtp/session.cpp	Fri Mar 17 15:47:54 2000
@@ -48,6 +48,9 @@
 #include "timer.h"
 #include "ntp-time.h"
 #include "session.h"
+#ifdef ECN_AWARE
+#include "ecn.h"
+#endif /* ECN_AWARE */
 
 /* added to support the mbus 
 #include "mbus_handler.h"*/
@@ -203,6 +206,8 @@
 sdes_seq_(0),
 rtcp_inv_bw_(0.),
 rtcp_avg_size_(128.), 
+ecn_marks_(0),
+ecn_marks_tot_(0),
 confid_(-1), mb_(mbus_handler_engine, NULL), lipSyncEnabled_(0)
 {
 	/*XXX For adios() to send bye*/
@@ -216,7 +221,7 @@
 	/*XXX*/
 	pktbuf_ = new u_char[2 * RTP_MTU];
 	pool_ = new BufferPool;
-	
+
 	/*
 	* schedule a timer for our first report using half the
 	* min rtcp interval.  This gives us some time before
@@ -603,6 +608,16 @@
 		sl.sns(sl.ns());
 		u_int32_t v;
 		int lost = expected - received;
+		struct timeval tv;
+
+		::gettimeofday (&tv, NULL);
+		printf ("%d.%06d ECN rx: dropped %4d     marked %3d\n",
+			tv.tv_sec, tv.tv_usec,
+			lost, ecn_marks_);
+
+		lost += ecn_marks_;
+		ecn_marks_tot_ += ecn_marks_;
+		ecn_marks_ = 0;
 		if (lost <= 0)
 			v = 0;
 		else
@@ -610,7 +625,7 @@
 			v = ((lost << 8) / expected) << 24;
 		/* XXX should saturate on over/underflow */
 		//		v |= (sp->ns() - sp->np()) & 0xffffff;
-		v |= (sl.ns() - sl.np()) & 0xffffff;
+		v |= (sl.ns() - sl.np() + ecn_marks_tot_) & 0x00ffffff;
 		rr->rr_loss = htonl(v);
 		//		rr->rr_ehsr = htonl(sp->ehs());
 		rr->rr_ehsr = htonl(sl.ehs());
@@ -695,18 +710,27 @@
 	int layer = dh - dh_;
 	pktbuf* pb = pool_->alloc(layer);
 	Address * addrp;
+	int tos;
 	/* leave room in case we need to expand rtpv1 into an rtpv2 header */
 	/* XXX the free mem routine didn't like it ... */
 	//u_char* bp = &pktbuf_[4];
 	//u_char* bp = pktbuf_;
 	
-	int cc = dh->recv(pb->data, sizeof(pb->data), addrp);
+	int cc = dh->recv(pb->data, sizeof(pb->data), addrp, &tos);
 	//int cc = dh->recv(bp, 2 * RTP_MTU - 4, addrp);
 	if (cc <= 0) {
 		pb->release();
 		return;
 	}
-	
+
+#ifdef ECN_AWARE
+	if ((tos & TOS_ECN_ECT) && (tos & TOS_ECN_CE))
+	{
+	    ecn_marks_++;
+	    ecn_marks_tot_++;
+	}
+#endif /* ECN_AWARE */
+
 	//rtphdr* rh = (rtphdr*)pb->data;
 	int version = pb->data[0] >> 6;
 	//int version = *(u_char*)rh >> 6;
@@ -890,11 +914,47 @@
 
 }
 
-void SessionManager::parse_rr_records(u_int32_t, rtcp_rr*, int,
+void SessionManager::parse_rr_records(u_int32_t, rtcp_rr *rr, int,
 				      const u_char*, Address &)
 {
+    u_int32_t loss;
+    int old_kbps;
+    int new_kbps;
+    struct timeval tv;
+    Tcl& tcl = Tcl::instance();
+
+#if 0
+    printf ("SessionManager::parse_rr_records: ssrc=%08x loss=%08x\n"
+	    "   hiseq=%08x jitter=%08x lsr=%08x dlsr=%08x\n",
+	    ntohl (rr->rr_srcid), ntohl (rr->rr_loss),
+	    ntohl (rr->rr_ehsr),  ntohl (rr->rr_dv),
+	    ntohl (rr->rr_lsr),   ntohl (rr->rr_dlsr));
+#endif
+
+    /* get the loss fraction since last report */
+    loss = ntohl (rr->rr_loss);
+    loss >>= 24;
+    loss &= 0xff;
+
+    /* find the current bandwidth limit */
+    tcl.evalc ("$bps_slider get");
+    sscanf (tcl.result(), "%d", &old_kbps);
+
+    /* Over 50% loss and we cut back the bandwidth, otherwise probe
+     * upwards. */
+    new_kbps = (loss > 128)?
+	old_kbps * 3 / 4 : /* backoff exponentially */
+	old_kbps + 5;      /* additive increase */
+
+    ::gettimeofday (&tv, NULL);
+    printf ("%d.%06d got RR: LossFrac= %2d %%  setting kbps= %4d\n",
+	    tv.tv_sec, tv.tv_usec,
+	    loss * 100 / 255,
+	    new_kbps);
+
+    tcl.evalf ("$bps_slider set %d", new_kbps);
 }
-				      
+
 
 void SessionManager::parse_sr(rtcphdr* rh, int flags, u_char*ep,
 							  Source* ps, Address & addr, int layer)
@@ -905,7 +965,7 @@
 	if (ps->srcid() != ssrc)
 		s = SourceManager::instance().lookup(ssrc, ssrc, addr);
 	else
-		s = ps;
+	s = ps;
 	
 	Source::Layer& sl = s->layer(layer);
 	
@@ -1034,7 +1094,9 @@
 void SessionManager::recv(CtrlHandler* ch)
 {
 	Address * srcp;
-	int cc = ch->recv(pktbuf_, 2 * RTP_MTU, srcp);
+	int tos;
+
+	int cc = ch->recv(pktbuf_, 2 * RTP_MTU, srcp, &tos);
 	if (cc <= 0)
 		return;
 
diff -ru vic-2.8ucl-1.1.3.orig/vic/rtp/session.h vic-2.8ucl-1.1.3/vic/rtp/session.h
--- vic-2.8ucl-1.1.3.orig/vic/rtp/session.h	Fri Nov  5 11:24:16 1999
+++ vic-2.8ucl-1.1.3/vic/rtp/session.h	Fri Mar 17 11:43:53 2000
@@ -60,8 +60,8 @@
 		if (addrp_) delete addrp_;
 		addrp_ = net->addr().copy(); // get right type of address
 	}
-	inline int recv(u_char* bp, int len, Address*& addrp) {
-		return (net_->recv(bp, len, *(addrp = addrp_)));
+	inline int recv(u_char* bp, int len, Address*& addrp, int *tos) {
+		return (net_->recv(bp, len, *(addrp = addrp_), tos));
 	}
 	inline void send(u_char* bp, int len) {
 		net_->send(bp, len);
@@ -167,6 +167,8 @@
 	u_int badfmt_;
 	u_int badext_;
 	u_int nrunt_;
+	u_int ecn_marks_;
+	u_int ecn_marks_tot_;
 
 	u_int32_t last_np_;
 	u_int32_t sdes_seq_;
diff -ru vic-2.8ucl-1.1.3.orig/vic/tcl/ui-ctrlmenu.tcl vic-2.8ucl-1.1.3/vic/tcl/ui-ctrlmenu.tcl
--- vic-2.8ucl-1.1.3.orig/vic/tcl/ui-ctrlmenu.tcl	Thu Feb 17 12:59:29 2000
+++ vic-2.8ucl-1.1.3/vic/tcl/ui-ctrlmenu.tcl	Fri Mar 17 11:15:41 2000
@@ -433,6 +433,7 @@
 }
 
 proc set_fps { w value } {
+	warn "set_fps, w is $w, value is $value"
 	grabber fps $value
 	$w configure -text "$value fps"
 }
