Index: /pjproject/trunk/pjlib/include/pj/sock.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/sock.h	(revision 5443)
+++ /pjproject/trunk/pjlib/include/pj/sock.h	(revision 5444)
@@ -277,4 +277,17 @@
 
 
+/** IPV6_TCLASS optname in setsockopt(). @see pj_IPV6_TCLASS() */
+extern const pj_uint16_t PJ_IPV6_TCLASS;
+
+
+#if defined(PJ_DLL)
+    /** Get #PJ_IPV6_TCLASS constant */
+    PJ_DECL(int) pj_IPV6_TCLASS(void);
+#else
+    /** Get #PJ_IPV6_TCLASS constant */
+#   define pj_IPV6_TCLASS()	PJ_IPV6_TCLASS
+#endif
+
+
 /**
  * Values to be specified as \c optname when calling #pj_sock_setsockopt() 
Index: /pjproject/trunk/pjlib/src/pj/sock_bsd.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_bsd.c	(revision 5443)
+++ /pjproject/trunk/pjlib/src/pj/sock_bsd.c	(revision 5444)
@@ -132,4 +132,12 @@
 
 
+/* IPV6_TCLASS */
+#ifdef IPV6_TCLASS
+const pj_uint16_t PJ_IPV6_TCLASS = IPV6_TCLASS;
+#else
+const pj_uint16_t PJ_IPV6_TCLASS = 0xFFFF;
+#endif
+
+
 /* optname values. */
 const pj_uint16_t PJ_SO_TYPE    = SO_TYPE;
Index: /pjproject/trunk/pjlib/src/pj/sock_common.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_common.c	(revision 5443)
+++ /pjproject/trunk/pjlib/src/pj/sock_common.c	(revision 5444)
@@ -1245,4 +1245,9 @@
 }
 
+PJ_DEF(int) pj_IPV6_TCLASS(void)
+{
+    return PJ_IPV6_TCLASS;
+}
+
 PJ_DEF(pj_uint16_t) pj_SO_TYPE(void)
 {
Index: /pjproject/trunk/pjlib/src/pj/sock_qos_bsd.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_qos_bsd.c	(revision 5443)
+++ /pjproject/trunk/pjlib/src/pj/sock_qos_bsd.c	(revision 5444)
@@ -23,5 +23,5 @@
 
 /* This is the implementation of QoS with BSD socket's setsockopt(),
- * using IP_TOS and SO_PRIORITY
+ * using IP_TOS/IPV6_TCLASS and SO_PRIORITY
  */ 
 #if !defined(PJ_QOS_IMPLEMENTATION) || PJ_QOS_IMPLEMENTATION==PJ_QOS_BSD
@@ -42,8 +42,28 @@
     /* Set TOS/DSCP */
     if (param->flags & PJ_QOS_PARAM_HAS_DSCP) {
+	/* We need to know if the socket is IPv4 or IPv6 */
+	pj_sockaddr sa;
+	int salen = sizeof(salen);
+
 	/* Value is dscp_val << 2 */
 	int val = (param->dscp_val << 2);
-	status = pj_sock_setsockopt(sock, pj_SOL_IP(), pj_IP_TOS(), 
-				    &val, sizeof(val));
+
+	status = pj_sock_getsockname(sock, &sa, &salen);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	if (sa.addr.sa_family == pj_AF_INET()) {
+	    /* In IPv4, the DS field goes in the TOS field */
+	    status = pj_sock_setsockopt(sock, pj_SOL_IP(), pj_IP_TOS(), 
+					&val, sizeof(val));
+	} else if (sa.addr.sa_family == pj_AF_INET6()) {
+	    /* In IPv6, the DS field goes in the Traffic Class field */
+	    status = pj_sock_setsockopt(sock, pj_SOL_IPV6(),
+					pj_IPV6_TCLASS(),
+					&val, sizeof(val));
+	} else {
+	    status = PJ_EINVAL;
+	}
+
 	if (status != PJ_SUCCESS) {
 	    param->flags &= ~(PJ_QOS_PARAM_HAS_DSCP);
@@ -85,4 +105,6 @@
     pj_status_t last_err = PJ_ENOTSUP;
     int val, optlen;
+    pj_sockaddr sa;
+    int salen = sizeof(salen);
     pj_status_t status;
 
@@ -90,10 +112,24 @@
 
     /* Get DSCP/TOS value */
-    optlen = sizeof(val);
-    status = pj_sock_getsockopt(sock, pj_SOL_IP(), pj_IP_TOS(), 
-				&val, &optlen);
+    status = pj_sock_getsockname(sock, &sa, &salen);
     if (status == PJ_SUCCESS) {
-	p_param->flags |= PJ_QOS_PARAM_HAS_DSCP;
-	p_param->dscp_val = (pj_uint8_t)(val >> 2);
+	optlen = sizeof(val);
+	if (sa.addr.sa_family == pj_AF_INET()) {
+	    status = pj_sock_getsockopt(sock, pj_SOL_IP(), pj_IP_TOS(), 
+					&val, &optlen);
+	} else if (sa.addr.sa_family == pj_AF_INET6()) {
+	    status = pj_sock_getsockopt(sock, pj_SOL_IPV6(),
+					pj_IPV6_TCLASS(),
+					&val, &optlen);
+	} else {
+	    status = PJ_EINVAL;
+	}
+
+        if (status == PJ_SUCCESS) {
+    	    p_param->flags |= PJ_QOS_PARAM_HAS_DSCP;
+	    p_param->dscp_val = (pj_uint8_t)(val >> 2);
+	} else {
+	    last_err = status;
+	}
     } else {
 	last_err = status;
