0

所以我开始使用 SCTP 并编写了 SCTP 服务器应用程序的基础知识(我打算对其进行修改以使其成为点对点应用程序)。代码不完整,但我编译并运行它以测试套接字选项,第一个 setsockopt 返回错误 10042(不支持协议)。我已经确定这是第一次调用 setsockopt() 返回错误。所以这里是不完整的代码:

#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);
        }














    }


}
4

2 回答 2

1

如果它与python 包 nameko/kombu/amqp 相关,则在此处报告Issue with 2.1.4 version

临时解决方案:回滚版本2.1.3直到它被修复。

于 2017-01-05T10:00:59.473 回答
0

好的,伙计们,我修好了(现在哈哈)。我所做的是用 IPPROTO_SCTP 替换 IPPROTO_IPV6,它似乎可以工作。

于 2013-05-30T17:49:08.547 回答