Index: pjproject/trunk/pjlib/src/pj/ioqueue_symbian.cpp
===================================================================
--- pjproject/trunk/pjlib/src/pj/ioqueue_symbian.cpp	(revision 1384)
+++ pjproject/trunk/pjlib/src/pj/ioqueue_symbian.cpp	(revision 1601)
@@ -233,4 +233,8 @@
     PJ_ASSERT_RETURN(pending_data_.common_.op_key_==NULL, PJ_EBUSY);
 
+    // addrlen must be specified if local or remote is specified
+    PJ_ASSERT_RETURN((!local && !remote) ||
+    		     (addrlen && *addrlen), PJ_EINVAL);
+    
     pending_data_.accept_.op_key_ = op_key;
     pending_data_.accept_.new_sock_ = new_sock;
@@ -255,11 +259,9 @@
 void CIoqueueCallback::HandleReadCompletion() 
 {
-    if (pending_data_.read_.addr_) {
+    if (pending_data_.read_.addr_ && pending_data_.read_.addrlen_) {
 	PjSymbianOS::Addr2pj(aAddress_, 
-			     *(pj_sockaddr_in*)pending_data_.read_.addr_);
+			     *(pj_sockaddr*)pending_data_.read_.addr_,
+			     pending_data_.read_.addrlen_);
 	pending_data_.read_.addr_ = NULL;
-    }
-    if (pending_data_.read_.addrlen_) {
-	*pending_data_.read_.addrlen_ = sizeof(pj_sockaddr_in);
 	pending_data_.read_.addrlen_ = NULL;
     }
@@ -274,6 +276,8 @@
 CPjSocket *CIoqueueCallback::HandleAcceptCompletion() 
 {
-	CPjSocket *pjNewSock = new CPjSocket(blank_sock_);
-
+	CPjSocket *pjNewSock = new CPjSocket(get_pj_socket()->GetAf(), 
+					     blank_sock_);
+	int addrlen = 0;
+	
 	if (pending_data_.accept_.new_sock_) {
 	    *pending_data_.accept_.new_sock_ = (pj_sock_t)pjNewSock;
@@ -283,9 +287,10 @@
 	if (pending_data_.accept_.local_) {
 	    TInetAddr aAddr;
-	    pj_sockaddr_in *ptr_sockaddr;
-
+	    pj_sockaddr *ptr_sockaddr;
+	    
 	    blank_sock_.LocalName(aAddr);
-	    ptr_sockaddr = (pj_sockaddr_in*)pending_data_.accept_.local_;
-	    PjSymbianOS::Addr2pj(aAddr, *ptr_sockaddr);
+	    ptr_sockaddr = (pj_sockaddr*)pending_data_.accept_.local_;
+	    addrlen = *pending_data_.accept_.addrlen_;
+	    PjSymbianOS::Addr2pj(aAddr, *ptr_sockaddr, &addrlen);
 	    pending_data_.accept_.local_ = NULL;
 	}
@@ -293,14 +298,24 @@
 	if (pending_data_.accept_.remote_) {
 	    TInetAddr aAddr;
-	    pj_sockaddr_in *ptr_sockaddr;
+	    pj_sockaddr *ptr_sockaddr;
 
 	    blank_sock_.RemoteName(aAddr);
-	    ptr_sockaddr = (pj_sockaddr_in*)pending_data_.accept_.remote_;
-	    PjSymbianOS::Addr2pj(aAddr, *ptr_sockaddr);
+	    ptr_sockaddr = (pj_sockaddr*)pending_data_.accept_.remote_;
+	    addrlen = *pending_data_.accept_.addrlen_;
+	    PjSymbianOS::Addr2pj(aAddr, *ptr_sockaddr, &addrlen);
 	    pending_data_.accept_.remote_ = NULL;
 	}
 
 	if (pending_data_.accept_.addrlen_) {
-	    *pending_data_.accept_.addrlen_ = sizeof(pj_sockaddr_in);
+	    if (addrlen == 0) {
+	    	if (pjNewSock->GetAf() == PJ_AF_INET)
+	    	    addrlen = sizeof(pj_sockaddr_in);
+	    	else if (pjNewSock->GetAf() == PJ_AF_INET6)
+	    	    addrlen = sizeof(pj_sockaddr_in6);
+	    	else {
+	    	    pj_assert(!"Unsupported address family");
+	    	}
+	    }
+	    *pending_data_.accept_.addrlen_ = addrlen;
 	    pending_data_.accept_.addrlen_ = NULL;
 	}
@@ -606,11 +621,16 @@
 					int addrlen )
 {
-    PJ_ASSERT_RETURN(addrlen == sizeof(pj_sockaddr_in), PJ_EINVAL);
-
+    pj_status_t status;
+    
     RSocket &rSock = key->cbObj->get_pj_socket()->Socket();
     TInetAddr inetAddr;
-    PjSymbianOS::pj2Addr(*(const pj_sockaddr_in*)addr, inetAddr);
     TRequestStatus reqStatus;
 
+    // Convert address
+    status = PjSymbianOS::pj2Addr(*(const pj_sockaddr*)addr, addrlen, 
+    				  inetAddr);
+    if (status != PJ_SUCCESS)
+    	return status;
+    
     // We don't support async connect for now.
     PJ_TODO(IOQUEUE_SUPPORT_ASYNC_CONNECT);
@@ -675,7 +695,20 @@
 					 int *addrlen)
 {
+    CPjSocket *sock = key->cbObj->get_pj_socket();
+    
+    // If address is specified, check that the length match the
+    // address family
+    if (addr || addrlen) {
+    	PJ_ASSERT_RETURN(addr && addrlen && *addrlen, PJ_EINVAL);
+    	if (sock->GetAf() == PJ_AF_INET) {
+    	    PJ_ASSERT_RETURN(*addrlen >= sizeof(pj_sockaddr_in), PJ_EINVAL);
+    	} else if (sock->GetAf() == PJ_AF_INET6) {
+    	    PJ_ASSERT_RETURN(*addrlen >= sizeof(pj_sockaddr_in6), PJ_EINVAL);
+    	}
+    }
+    
     // If socket has reader, delete it.
-    if (key->cbObj->get_pj_socket()->Reader())
-    	key->cbObj->get_pj_socket()->DestroyReader();
+    if (sock->Reader())
+    	sock->DestroyReader();
     
     if (key->cbObj->IsActive())
@@ -737,4 +770,5 @@
     TInetAddr inetAddr;
     TSockXfrLength aLen;
+    pj_status_t status;
     
     PJ_UNUSED_ARG(op_key);
@@ -743,12 +777,14 @@
     PJ_ASSERT_RETURN((flags & PJ_IOQUEUE_ALWAYS_ASYNC)==0, PJ_EINVAL);
 
-    // Must be pj_sockaddr_in for now.
-    PJ_ASSERT_RETURN(addrlen == sizeof(pj_sockaddr_in), PJ_EINVAL);
-
+    // Convert address
+    status = PjSymbianOS::pj2Addr(*(const pj_sockaddr*)addr, addrlen, 
+    				  inetAddr);
+    if (status != PJ_SUCCESS)
+    	return status;
+    
     // Clear flag
     flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC;
 
     aBuffer.Set((const TUint8*)data, (TInt)*length);
-    PjSymbianOS::pj2Addr(*(const pj_sockaddr_in*)addr, inetAddr);
     CPjSocket *pjSock = key->cbObj->get_pj_socket();
 
