windows socket ipv6 SOCK_RAW
Posted yanhc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了windows socket ipv6 SOCK_RAW相关的知识,希望对你有一定的参考价值。
bind处一直报错WSAEADDRNOTAVAIL10049,不知道为什么?
|
|
#include <stdio.h> #include <winsock2.h> #include <ws2ipdef.h> #pragma comment(lib, "ws2_32.lib") #define BUF_SIZE 30 int main() { int iResult = 0; WSADATA wsaData; SOCKET sock; char message[BUF_SIZE]; int strlen; int addrsize; SOCKADDR_IN6 addrto, addrfrom; iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); sock = socket(AF_INET6, SOCK_RAW, 89); /*需要管理员权限*/ if (sock == INVALID_SOCKET) printf("sock err = %d ", WSAGetLastError()); addrto.sin6_family = AF_INET6; addrto.sin6_addr.u.Byte[0] = 0xfc; addrto.sin6_addr.u.Byte[1] = 0x00; addrto.sin6_addr.u.Byte[2] = 0x00; addrto.sin6_addr.u.Byte[3] = 0x00; addrto.sin6_addr.u.Byte[4] = 0x00; addrto.sin6_addr.u.Byte[5] = 0x00; addrto.sin6_addr.u.Byte[6] = 0x0d; addrto.sin6_addr.u.Byte[7] = 0x41; addrto.sin6_addr.u.Byte[8] = 0x00; addrto.sin6_addr.u.Byte[9] = 0x00; addrto.sin6_addr.u.Byte[10] = 0x00; addrto.sin6_addr.u.Byte[11] = 0x00; addrto.sin6_addr.u.Byte[12] = 0x0d; addrto.sin6_addr.u.Byte[13] = 0x41; addrto.sin6_addr.u.Byte[14] = 0x00; addrto.sin6_addr.u.Byte[15] = 0x02; addrto.sin6_port = 89; iResult = bind(sock, (SOCKADDR *)&addrto, sizeof(SOCKADDR_IN6)); if (iResult == SOCKET_ERROR) printf("bind err = %d ", WSAGetLastError()); while (1) { addrsize = sizeof(addrfrom); strlen = recvfrom(sock, message, BUF_SIZE, 0, (SOCKADDR*)&addrfrom, &addrsize); } }
以上是关于windows socket ipv6 SOCK_RAW的主要内容,如果未能解决你的问题,请参考以下文章