我想在python中停止Ipv6套接字,我这样做:
#!/usr/bin/env python
import sys
import struct
import socket
host = 'fe80::225:b3ff:fe26:576'
sa = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sa.bind((host , 50000))
Run Code Online (Sandbox Code Playgroud)
但它失败了:
socket.error: (22, 'Invalid argument') ?
Run Code Online (Sandbox Code Playgroud)
谁能帮我?谢谢!
我像这样重做它,但仍然无法工作
>>>host = 'fe80::225:b3ff:fe26:576'
>>>sa = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
>>>res = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_DGRAM, 0, socket.AI_PASSIVE)
>>>family, socktype, proto, canonname, sockaddr = res[0]
>>>print sockaddr
('fe80::225:b3ff:fe26:576', 50001, 0, 0)
>>>sa.bind(sockaddr)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1, in bind
socket.error: (22, 'Invalid argument')
Run Code Online (Sandbox Code Playgroud) 如果两个内核模块包含EXPORT_SYMBOL(a),则a定义为:int a,如果插入了两个模块会发生什么?哪个"a"会被使用?
为什么ipv6连接失败?
# python
>>> import socket
>>> s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
>>> sa = ('2000::1',2000,0,0)
>>> s.connect(sa)
>>> sa = ('fe80::21b:78ff:fe30:7c6', 2000, 0, 0)
>>> s.connect(sa)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1, in connect
socket.error: (22, 'Invalid argument')
Run Code Online (Sandbox Code Playgroud) > case WM_PAINT:
{
> hdc = BeginPaint(hWnd, &ps);
> // TODO: Add any drawing code here...
> RECT rt;
> GetClientRect(hWnd, &rt);
> HDC myHdc = CreateCompatibleDC(hdc);
>
> DrawText(myHdc, szHello, strlen(szHello), &rt, DT_CENTER);
> BitBlt(hdc,0,0,rt.right-rt.left,rt.bottom-rt.top,myHdc,0,0,SRCCOPY);
>
> EndPaint(hWnd, &ps);
}
>
> break;
Run Code Online (Sandbox Code Playgroud)
为什么文字无法在窗口显示?
我看到了这样的代码:为什么同时使用MultiByteToWideChar和WideCharToMultiByte?
char szLine[MAX_LENGTH_STRING] = {0}
... //some operate to szLine
char *szUtf8string;
wchar_t *szUnicodeString;
int size;
int room;
size = strlen(szLine)+1;
room = MultiByteToWideChar(CP_ACP, 0, szLine, -1, NULL, 0);
szUnicodeString = (wchar_t*) malloc((sizeof(wchar_t))*room);
MultiByteToWideChar(CP_ACP, 0, szLine, -1, szUnicodeString, room);
room = WideCharToMultiByte(CP_UTF8, 0, szUnicodeString, -1, NULL, 0, NULL, NULL);
szUtf8string = (char*) malloc(room);
WideCharToMultiByte(CP_UTF8, 0, szUnicodeString, -1, szUtf8string, room, NULL, NULL);
Run Code Online (Sandbox Code Playgroud) 我有一段这样的代码:
set<string>::iterator it1;
set<string>::iterator it2;
pair<set<string>::iterator,bool> ret;
set<string> s;
ret = s.insert("bbbb1");
it1 = ret.first;
ret = s.insert("bbbb2");
it2 = ret.first;
map<set<string>::iterator, set<string>::iterator> m;
m.insert(make_pair(it1,it2));
Run Code Online (Sandbox Code Playgroud)
但最后一行"m.insert(make_pair(it1,it2));" 失败..