2013-05-30 81 views
0

因此,我開始使用SCTP並編寫了SCTP服務器應用程序(我打算修改它以使其成爲點對點應用程序)的基礎知識。代碼是不完整的,但我編譯並運行它來測試套接字選項,並且第一個setsockopt返回錯誤10042(協議不支持)。我確定這是setsockopt()的第一個調用返回一個錯誤。因此,這裏是不完整的代碼:Setsockopt()返回錯誤號10042

#include "stdafx.h" 
#include <iostream> 
#include <iostream> 
#include <string.h> 
#include <stdlib.h> 

#ifndef UNICODE 
#define UNICODE 
#endif 

#define WIN32_LEAN_AND_MEAN 

#include <WinSock2.h> 
#include <WS2tcpip.h> 
#include <WS2spi.h> 
#include <ws2sctp.h> 
#include <wsipv6ok.h> 
#include <if.h> 
#include "ws2isatap.h" 
#include "if_tunnel.h" 





#pragma comment(lib, "ws2_32.lib") 
#pragma comment(lib, "sctpsp.lib") 


using namespace std; 
using namespace System; 

static int LISTENQ = 5; 

void isatap_enable(void); 

int main(int argc, char* argv[]){ 



WSADATA wsaData; 
    int iResult; 
    int optv = 10; 
    u_long imode = 1; 
    bool connected = false; 
    char *optval = (char*)&optv; 
    int optlen = sizeof(optval); 
    sockaddr_in6 servAddr; 
    sctp_sndrcvinfo sr; 
    sctp_event_subscribe evnts; 
    sctp_initmsg init; 



    memset(&sr,0,sizeof(sr)); 
    memset(&evnts,0,sizeof(evnts)); 
    memset(&init,0,sizeof(init)); 
    memset(&servAddr,0,sizeof(servAddr)); 



    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); 
    if (iResult != NO_ERROR) { 
     wprintf(L"WSAStartup function failed with error: %d\n", iResult); 
     return 1; 
    } 




    SOCKET servSock = socket(AF_INET6,SOCK_STREAM,IPPROTO_SCTP); 
    if(servSock==INVALID_SOCKET){ 
     printf("Socket function failed with error: %d\n",GetLastError()); 
     return 1; 
    } 


    if(setsockopt(servSock,IPPROTO_IPV6,IPV6_PROTECTION_LEVEL,optval,sizeof(optval))<0){ 
     printf("setsockopt function failed with error: %d\n", GetLastError()); 
     return 1; 
    } 





    u_int servPort = 5000; 
    servAddr.sin6_family = AF_INET6; 
    servAddr.sin6_addr = in6addr_any; 
    servAddr.sin6_port = htons(servPort); 



    if(setsockopt(servSock,IPPROTO_SCTP,SCTP_EVENTS,(const char*)&evnts,sizeof(evnts)) < 0){ 
     printf("setsockopt function failed with error: %d\n", GetLastError()); 
     return 1; 
    } 




    ioctlsocket(servSock,FIONBIO, &imode); 

    if(bind(servSock,(struct sockaddr*)&servAddr,sizeof(servAddr))<0){ 
     printf("Bind function failed with error: %d\n", GetLastError()); 
     return 1; 
    } 

    evnts.sctp_data_io_event = 1; 
    evnts.sctp_association_event = *(u_char*)optval; 

    for(;;){ 

     if(listen(servSock,LISTENQ) < 0){ 
     printf("Listen function failed with error: %d/n",GetLastError()); 
     return 1; 
     }else{ 

      printf("Listening on port %d\n",servPort); 
     } 














    } 


} 

回答

0

好球員,我固定它(現在笑)。我所做的是用IPPROTO_SCTP替代IPPROTO_IPV6,它似乎工作。

1

如果它涉及到Python包菇/海帶/ AMQP,那麼它在這裏Issue with 2.1.4 version報道。

臨時解決方案:將版本回滾到2.1.3,直到它被修復。