linux netlink因为协议号,内核socket总是创建失败 [问题点数:20分]

Bbs1
本版专家分:0
结帖率 0%
Bbs1
本版专家分:36
Bbs1
本版专家分:0
android ndk创建socket总是失败
android ndk 有网络权限 也给了root权限rnsock = <em>socket</em>(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))<em>总是</em>返回-1rn求解啊
linux中与内核通信的Netlink机制
本文主要介绍<em>linux</em>中<em>内核</em>态与用户态通信的<em>netlink</em>机制。介绍了<em>netlink</em>的程序流程,特点,和具体实现代码
netlink怎么与内核通信?
<em>netlink</em>是在用户与<em>内核</em>之间传递消息的rn比如 获取IP地址什么的rnrn我在用户态通过<em>netlink</em>把命令传给<em>内核</em> 然后交给<em>内核</em>执行 然后再返回回来rn那么<em>内核</em>是如何获取<em>netlink</em>传递过来的信息的?rn主要是通过那个函数?请高手指教一下
用户空间与内核的交互---NETLINK
http://blog.chinaunix.net/uid-20786208-id-3684152.html   关于<em>netlink</em>,相信玩过上层开发的人并不陌生,尤其是经常穿梭于用户空间和<em>内核</em>之间的开发,前面我们说过在用户空间与<em>内核</em>空间的交互有ioctl 、proc 等,而<em>netlink</em>又有它独特的地位和作用.   我开始接触<em>netlink</em>是开始于去实现一个恢复出厂值的按键.当然先要
linux netlink 编程示例(一)内核
Netlink是一种<em>内核</em>层与应用层通信的一种机制,比如说在做一个<em>内核</em>模块的时候,往往会需要应用层提供一些配置信息,这时候就可以使用<em>netlink</em>。<em>netlink</em>包括内<em>内核</em>层和应用层,<em>内核</em>层注册一个<em>netlink</em><em>协议</em>,然后定义一些消息类型,之后就可以等待来自应用层的消息了。这篇博文给出一个简单的<em>netlink</em><em>内核</em>模块使用例子,应用层会在接下来的博文中给出。<em>内核</em>版本:3.4.39。 不同<em>内核</em>版本可能带...
Linux 24 内核和用户通信之netlink
Netlink的通信地址和<em>协议</em> 一般来说用户空间和<em>内核</em>空间的通信方式有三种:/proc、ioctl、Netlink。而前两种都是单向的,而Netlink可以实现双工通信。 所有<em>socket</em>之间的通信,必须有个地址结构,Netlink也不例外。我们最熟悉的就是IPV4的地址了,<em>netlink</em>的地址结构如下: struct sockaddr_nl { sa_family_t nl_fa...
linux socket CAN设置波特率总是失败
如题,有谁知道是什么原因吗?rnrn
linux netlink
通过<em>netlink</em>检测设备热插拔, gcc -o <em>netlink</em>_test.c <em>netlink</em>编译
创建原始套接字总是失败!!!
WSADATA wsa;rn WSAStartup(MAKEWORD(2,2),&wsa);rn char szResult[10];rn SOCKET s=<em>socket</em>(AF_INET,SOCK_RAW,IPPROTO_IP);//或者IPPROTO_RAWrn if(INVALID_SOCKET==s)rn rn int dwErr=WSAGetLastError();rn sprintf(szResult,"%ld",dwErr);rn AfxMessageBox(CString(szResult));rn rn上述代码<em>总是</em>返回错误10013,上网查说是权限问题,不解,我用的是VS2005,Vista操作系统,求指教!!!
创建QueueConnection总是失败
以下的例子很是简单,不过试过多个例子,都是同样的<em>失败</em>。请教。rn public static final String qcfLookup="EXAMPLEQCF1";rn public static final String qLookup="EXAMPLEQL1";rn public static final String icf = "com.sun.jndi.fscontext.RefFSContextFactory";rn public String url ="file:/d:";rn private String QMGR = "QM_EXAMPLE";rn rn public void sampleInit() throws Exception rn Hashtable environment = new Hashtable();rn environment.put(Context.INITIAL_CONTEXT_FACTORY, icf);rn environment.put(Context.PROVIDER_URL, url);rn environment.put(Context.REFERRAL, "throw");rn Context ctx=new InitialDirContext(environment);rn factory = (QueueConnectionFactory)ctx.lookup(qcfLookup);rn Queue q1=null;rn q1=(Queue)ctx.lookup(qLookup);rn connection = factory.createQueueConnection();rnrn[color=#FF0000]在最后一句,<em>创建</em>connection时,会有以下的错误rnjavax.jms.JMSException: MQJMS2005: 'localhost:' の MQQueueManager の作成に失敗しましたrn at com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:586)rn at com.ibm.mq.jms.MQConnection.createQM(MQConnection.java:2110)rn at com.ibm.mq.jms.MQConnection.createQMNonXA(MQConnection.java:1532)rn at com.ibm.mq.jms.MQQueueConnection.(MQQueueConnection.java:150)rn at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:185)rn at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:112)rn at jms.example.Sample.sampleInit(Sample.java:34)rn at jms.example.Sample.main(Sample.java:60)[/color]rnrndebug窗口会有以下提示:rn [color=#FF0000] Cannot make a static reference to the non-static field factory[/color]rnrn如有奉告,不胜感激。 rn
[Copy] Netlink Socket
源代码包 博文链接:https://cloudhe.iteye.com/blog/147518
netlink socket programming
<em>netlink</em> <em>socket</em> programming howto
socket创建失败
#include rn#include rn#include rn#include rn#include rn#include rn#include rn#include rn#pragma comment(lib,"ws2_32.lib")rntypedef struct ip_hdr //定义IP首部 rn rnUCHAR h_verlen; //4位首部长度,4位IP版本号 rnUCHAR tos; //8位服务类型TOS rnUSHORT total_len; //16位总长度(字节) rnUSHORT ident; //16位标识 rnUSHORT frag_and_flags; //3位标志位 rnUCHAR ttl; //8位生存时间 TTL rnUCHAR proto; //8位<em>协议</em> (TCP, UDP 或其他) rnUSHORT checksum; //16位IP首部校验和 rnULONG sourceIP; //32位源IP地址 rnULONG destIP; //32位目的IP地址 rnIP_HEADER; rnrntypedef struct tsd_hdr //定义TCP伪首部 rn rnULONG saddr; //源地址rnULONG daddr; //目的地址 rnUCHAR mbz; //没用rnUCHAR ptcl; //<em>协议</em>类型 rnUSHORT tcpl; //TCP长度 rnPSD_HEADER; rnrntypedef struct tcp_hdr //定义TCP首部 rn rnUSHORT th_sport; //16位源端口 rnUSHORT th_dport; //16位目的端口 rnULONG th_seq; //32位序列号 rnULONG th_ack; //32位确认号 rnUCHAR th_lenres; //4位首部长度/6位保留字 rnUCHAR th_flag; //6位标志位 rnUSHORT th_win; //16位窗口大小 rnUSHORT th_sum; //16位校验和 rnUSHORT th_urp; //16位紧急数据偏移量 rn//以下是伪首部定义rnULONG saddr; //源地址rnULONG daddr; //目的地址 rnUCHAR mbz; //没用rnUCHAR ptcl; //<em>协议</em>类型 rnUSHORT tcpl; //TCP长度 rnTCP_HEADER; rnrn//CheckSum:计算校验和的子函数 rnUSHORT checksum(USHORT *buffer, int size) rn rn unsigned long cksum=0; rn while(size >1) rn rn cksum+=*buffer++; rn size -=sizeof(USHORT); rn rn if(size) rn rn cksum += *(UCHAR*)buffer; rn rnrn cksum = (cksum >> 16) + (cksum & 0xffff); rn cksum += (cksum >>16); rn return (USHORT)(~cksum); rn rnrnint main(int argc, char* argv[]) rn rn WSADATA WSAData; rn SOCKET sock; rn rn IP_HEADER ip_hdr; rn TCP_HEADER tcp_hdr; rn // PSD_HEADER tcp_hdr; rnrn char Sendto_Buff[40000]; //发送缓冲区 //发送缓冲区最大值rn unsigned short check_Buff[40000]; //检验和缓冲区rn const char tcp_send_data[]="This is my homework of networt,I am happy!";rnrn BOOL flag; rn int rect,nTimeOver; rnrn if (argc!= 5) rn rn printf("Useage: SendTcp soruce_ip source_port dest_ip dest_port \n"); rn return false; rn rnrn if (WSAStartup(MAKEWORD(2,2), &WSAData)!=0) rn rn printf("WSAStartup Error!\n"); rn return false; rn rn sock=WSASocket(AF_INET,SOCK_RAW,IPPROTO_TCP,NULL,0,WSA_FLAG_OVERLAPPED);rn flag=true; rn setsockopt(sock,IPPROTO_IP,IP_HDRINCL,(char*)&flag,sizeof(flag));rn nTimeOver=1000; rn setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char*)&nTimeOver, sizeof(nTimeOver));rn //填充IP首部 rn ip_hdr.h_verlen=(4<<); rn close<em>socket</em>(sock); rn WSACleanup(); rn return 1; rnrnrn各位大神,这是发送TCP报文的程序,程序输入 SendTcp soruce_ip source_port dest_ip dest_port,我想问这里面<em>socket</em><em>创建</em><em>失败</em>报send error!:10038错误是怎么回事,要怎么修改使程序正确输出send OK!rn
android socket创建失败
实现功能:点击按键,向某个网址的某个端口,发送数据[code=java] class textDisitListener implements OnClickListenerrn rn public void onClick(View v) rn rn new textDisThread().start();rn rn rn class textDisThread extends Threadrn rn public void run()rn rn String str11 = new String("asdfasdf");rn Log.i("<em>socket</em>","loading...");rn try rn Socket <em>socket</em>Test = new Socket(SERVERIP,SERVERPORT);rn Log.i("<em>socket</em>","load.");rn PrintWriter outw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(<em>socket</em>Test.getOutputStream(),"GB2312")),true);rn outw.println(str11);rn Log.i("TextSend","textsend");rn outw.flush();rn outw.close();rn <em>socket</em>Test.close();rn catch (UnknownHostException e) rn // TODO 自动生成的 catch 块rn e.printStackTrace();rn catch (IOException e) rn // TODO 自动生成的 catch 块rn e.printStackTrace();rn rn rn [/code]rn在adb上运行没有问题,但是到了手机上调试时候发现Socket <em>socket</em>Test = new Socket(SERVERIP,SERVERPORT);这一行根本就过不去。rnrn后来做了测试。[code=java] class btnListener implements OnClickListenerrn rn public void onClick(View v) rn rn new textDisThread().start();rn rn rn class textDisThread extends Thread rn rn Socket <em>socket</em>1 = new Socket(SERVERIP,SERVERPORT);rn [/code]rn只有新建,什么都不做,一样报错。rn缺省构造函数不能处理隐式超构造函数抛出的异常类型 IOException。必须定义显式构造函数。rn这个怎么处理呢?
NDK socket 创建失败
第一次 使用 NDK 开发 <em>socket</em> 程序 SOCKET hs = <em>socket</em>( AF_INET, SOCK_STREAM, IPPROTO_TCP ); // IPPROTO_TCP; if ( hs == INVALID_SOCKET ) { dbg_printf( 1, "permission denied !" ); err
创建Socket失败
运行后显示<em>创建</em>Socket<em>失败</em>,然后用管理员cmd,显示setsockopt操作<em>失败</em>。rn怎么办。。。rnrn源代码:rn//IP数据包的捕获与解析rn#define _WINSOCK_DEPRECATED_NO_WARNINGSrn#include rn#include rn#include rn#include rn#include rn#pragma comment(lib,"ws2_32")rn#define IO_RCVALL _WSAIOW(IOC_VENDOR,1)rnusing namespace std;rnofstream outfile("e:\\logfile.txt", ios::out);rntypedef struct IP_HEAD //定义IP数据包数据结构rnrn unionrn rn unsigned char Version;rn unsigned char HeadLen;rn ;rn unsigned char ServiceType;rn unsigned short TotalLen;rn unsigned short Identifier;rn unionrn rn unsigned short Flags;rn unsigned short FragOffset;rn ;rn unsigned char TimeToLive;rn unsigned char Protocol;rn unsigned short HeadChecksum;rn unsigned int SourceAddr;rn unsigned int DestinAddr;rn unsigned char Options;rnip_head;rnvoid main(int argc, char *argv[]) //argv需要抓取的IP数据包的数量rnrn if (argc != 2) //检查命令行参数rn rn cout << endl << "请输入命令行:PackParse packet_sum" << endl;rn return;rn rn //启动winsockrn WSADATA WSAData;rn if (WSAStartup(MAKEWORD(2, 2), &WSAData) != 0)rn rn cout << endl << "WSASTartup初始化<em>失败</em>" << endl;rn return;rn rn //初始化<em>socket</em><em>创建</em>,原始套接字rn SOCKET sock = <em>socket</em>(AF_INET, SOCK_RAW, IPPROTO_IP);rn if (sock == INVALID_SOCKET)rn rn cout << endl << "<em>创建</em>Socket<em>失败</em>!" << endl;rn return;rn rn bool flag = true;rn if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, (char *)&flag, sizeof(flag)) == SOCKET_ERROR)rn rn cout << endl << "setsockopt操作<em>失败</em>" << endl;rn return;rn rn //获得本地主机名rn char hostName[128];rn if (gethostname(hostName, 100) == SOCKET_ERROR)rn rn cout << endl << "获取主机名操作<em>失败</em>" << endl;rn return;rn rn //获得本机IP地址rn hostent *pHostIP;rn if ((pHostIP = gethostbyname(hostName)) == NULL)rn rn cout << endl << "获取主机地址操作<em>失败</em>" << endl;rn return;rn rn //填充sockaddr_inrn sockaddr_in host_addr; //初始化<em>socket</em><em>创建</em>/绑定rn host_addr.sin_family = AF_INET;rn host_addr.sin_port = htons(6000);rn host_addr.sin_addr = *(in_addr *)pHostIP->h_addr_list[0];rn //<em>socket</em>绑定rn if (bind(sock, (PSOCKADDR)&host_addr, sizeof(host_addr)) == SOCKET_ERROR) //初始化<em>socket</em>(绑定)rn rn cout << endl << "bind操作<em>失败</em>" << endl;rn return;rn rn //将网卡模式调为混杂,捕获所有的IP数据包,网卡不能接收mac地址不是自己的IP数据包rn DWORD dwBufferLen[10];rn DWORD dwBufferInLen = 1;rn DWORD dwBytesReturned = 0;rn if (WSAIoctl(sock, IO_RCVALL, &dwBufferInLen, sizeof(dwBufferInLen), &dwBufferLen, sizeof(dwBufferLen), &dwBytesReturned, NULL, NULL) == SOCKET_ERROR)rn rn cout << endl << "WSAIoctl操作<em>失败</em>" << endl;rn return;rn rn cout << endl << "开始解析IP包:" << endl;rn char buffer[65535];rn int packsum = atoi(argv[1]);rn for (int i = 0; i0) //接收IP数据包rn rn ip_head ip = *(ip_head *)buffer; //解析IP包头部字段rn cout << "-----------------------" << endl;rn cout << "版本:" << (ip.Version >> 4) << endl;rn cout << "头部长度:" << ((ip.HeadLen & 0x0f) * 4) << endl;rn cout << "服务类型:Priority" << (ip.ServiceType >> 5) << ",Service" << ((ip.ServiceType >> 1) & 0x0f) << endl;rn cout << "总长度:" << ip.TotalLen << endl;rn cout << "标识符:" << ip.Identifier << endl;rn cout << "标志位:" << ((ip.Flags >> 15) & 0x01) << ",DF=" << ((ip.Flags >> 14) & 0x01) << ",Mf=" << ((ip.Flags >> 13) & 0x01) << endl;rn cout << "片偏移:" << (ip.FragOffset & 0x1fff) << endl;rn cout << "生存周期:" << (int)ip.TimeToLive << endl;rn cout << "<em>协议</em>:Protocol" << (int)ip.Protocol << endl;rn cout << "头部校验和:" << ip.HeadChecksum << endl;rn cout << "原地址:" << inet_ntoa(*(in_addr *)&ip.SourceAddr) << endl;rn cout << "目的IP地址:" << inet_ntoa(*(in_addr *)&ip.DestinAddr) << endl;rn rn rn getchar(); getchar();rn close<em>socket</em>(sock); //关闭<em>socket</em>rn WSACleanup(); //关闭winsockrn
Linux下创建socket失败
[code=c]rnreturn <em>socket</em>(AF_INET, SOCK_STREAM, 0);rn[/code]rn初次在<em>linux</em>下进行开发,但是调用以上代码始终返回-1,很奇怪!rn使用GDB调试<em>总是</em>返回-1,很奇怪.rnrn大家指点指点呀?没有道理呀!
win7创建socket失败?
本人发帖不多,各位请多帮忙。我的电脑是win7 旗舰版x64rn在进行网络编程时,遇到一个奇怪的现象 ,<em>创建</em>TCP的<em>socket</em><em>失败</em>。<em>创建</em>UDP的可以成功.rn如果先<em>创建</em>一个UDP的<em>socket</em>接着再<em>创建</em>一个TCP的<em>socket</em>也会成功。把代码贴出来:rn[code=C/C++]//============================================================================rn// Name : wtxregd.cpprn// Author : CHENQrn// Version :rn// Copyright : Your copyright noticern// Description : Hello World in C, Ansi-stylern//============================================================================rn#include "stdafx.h"rnrn#define WIN7_SOCKET_MYDEBUGrnrnstatic int WSAUnInit();rnstatic int WSAInit()rnrn WSADATA data;rn int ret = WSAStartup(0x0202, &data);rn if (ret != 0)rn rn WSAUnInit();rn printf ("Init Winsock2 Failed!\n");rn return __LINE__;rn rn return 0;rnrnrnint WSAUnInit()rnrn return WSACleanup();rnrnrnint Server(int port)rnrn WSAInit();rn SOCKET mListener = <em>socket</em>(AF_INET, SOCK_STREAM, 0);rnrn#ifdef WIN7_SOCKET_MYDEBUGrn SOCKET mUdpsock = <em>socket</em>(AF_INET, SOCK_DGRAM, 0);rn SOCKET mListener0 = <em>socket</em>(AF_INET, SOCK_STREAM, 0);rn#endifrnrn if (mListener == INVALID_SOCKET)rn rn printf ("creat listen <em>socket</em> failed, errno=%d\n", WSAGetLastError());rn rn#ifdef WIN7_SOCKET_MYDEBUGrn if (mUdpsock == INVALID_SOCKET)rn rn printf ("creat listen Udp <em>socket</em> failed, errno=%d\n", WSAGetLastError());rn rn if (mListener0 == INVALID_SOCKET)rn rn printf ("creat listen <em>socket</em>0 failed, errno=%d\n", WSAGetLastError());rn rn#endifrn //JUST for debugrn return __LINE__;rnrn int val;rn rn // Settings on <em>socket</em>rn BOOL sopt = TRUE;rn setsockopt(mListener, IPPROTO_TCP, TCP_NODELAY,rn (char *)&sopt, sizeof(BOOL));rn setsockopt(mListener, SOL_SOCKET, SO_DONTLINGER,rn (char *)&sopt, sizeof(BOOL));rnrn // Bind <em>socket</em> and listenrn SOCKADDR_IN addr;rn memset(&addr, 0, sizeof(SOCKADDR_IN));rn addr.sin_family = AF_INET;rn addr.sin_addr.s_addr = htonl(INADDR_ANY);rn addr.sin_port = htons(port);rn val = bind(mListener, (struct sockaddr*) &addr, sizeof(addr));rnrn if (val != 0)rn rn printf ("Bind port failed, errno=%d\n", WSAGetLastError());rn close<em>socket</em>(mListener);rn WSAUnInit();rn return __LINE__;rn rn rnrn rn // Put the <em>socket</em> into the listening statusrn val = listen(mListener, SOMAXCONN);rn if (val < 0)rn rn printf ("Listen failed, errno=%d\n", WSAGetLastError());rn rn rn SOCKADDR_IN saddr;rn int len = 0;rn SOCKET mAccepted = accept(mListener, (SOCKADDR *)&saddr, &len);rn if (mAccepted == INVALID_SOCKET)rn rn close<em>socket</em>(mListener);rn WSAUnInit();rn printf ("accept failed, errno=%d\n", WSAGetLastError());rn return __LINE__;rn rn#if 0rn SOCKET mAccepted = accepted;rn // Settings on <em>socket</em>rn BOOL sopt = TRUE;rn setsockopt(mAccepted, IPPROTO_TCP, TCP_NODELAY,rn (char *)&sopt, sizeof(BOOL));rn setsockopt(mAccepted, SOL_SOCKET, SO_DONTLINGER,rn (char *)&sopt, sizeof(BOOL));rn#endifrn char szBuf[512];rn for (;;)rn rn FD_SET rSet;rn FD_ZERO(&rSet);rn FD_SET(mAccepted ,&rSet);rn timeval val = 0;rn select(mAccepted+1, &rSet, NULL, NULL, &val);rn if (FD_ISSET(mAccepted, &rSet))rn rn memset (szBuf, 0, sizeof(szBuf));rn int ret = recv(mAccepted, szBuf, sizeof(szBuf), 0);rn if (ret > 0)rn printf ("Recv::%s\n", szBuf);rn if (strcmp(szBuf, "quit")==0)rn break;rn rn rnrnrn#if 0rn SOCKET <em>socket</em>( IN int af, IN int type, IN int protocol );rn af (AF_INET) ARPA因特网<em>协议</em>(UNIX网络套接字);rn type——SOCK_STREAM 流式套接字TCP;SOCK_DGRAM 数据报套接字UCPrn protocol——0为默认值,IPPROTO_TCP IP网的TCP<em>协议</em>rnrn int setsockopt(IN SOCKET s, IN int level, IN int optname, IN const char FAR * optval, IN int optlen);rn ——设置套接口的选项rn // TCP_NODELAY选项禁止Nagle算法rn //SO_DONTLINER BOOL 不要因为数据未发送就阻塞关闭操作。相当于将SO_LINGER的 l_onoff 元素置为零rnrn int bind(IN SOCKET s,IN const struct sockaddr FAR * name,IN int namelen);rn ——绑定<em>socket</em>和地址和端口监听因特网上的任意ip地址接入 INADDR_ANYrnrn int listen( IN SOCKET s,IN int backlog);rn ——backlog队列中可以容纳的未处理连接的最大数目限制rn ——listen函数为服务器程序<em>创建</em>一个队列来保存未处理的请求rn#endifrn close<em>socket</em>(mAccepted);rn close<em>socket</em>(mListener);rn return WSAUnInit();rnrnrnint main(void)rnrn Server(30232);rn return EXIT_SUCCESS;rnrnrn[/code]rnrn被宏WIN7_SOCKET_MYDEBUG包含的代码里的<em>socket</em>都是成功的,之外的是<em>失败</em>的。运行结果是rncreat listen <em>socket</em> failed, errno=0rnrn
内核netlink发送接收数据问题
RT!rnrn[code=C/C++]rn//kernelrnrnskb = skb_recv_datagram(nl_sk, 0, 0, &err); rnnlh = (struct nlmsghdr *)skb->data; rnprintk("%s: received <em>netlink</em> message payload:%s\n", __FUNCTION__, (char*)NLMSG_DATA(nlh)); rnrnpid = nlh->nlmsg_pid; /*pid of sending process */ rnNETLINK_CB(skb).groups = 0; /* not in mcast group */ rnNETLINK_CB(skb).pid = 0; /* from kernel */ rnNETLINK_CB(skb).dst_pid = pid; rnNETLINK_CB(skb).dst_groups = 0; /* unicast */ rnrn<em>netlink</em>_unicast(nl_sk, skb, pid, 1);rnrn//clientrnrnmsg.msg_name = (void *)&dest_addr; rnmsg.msg_namelen = sizeof(dest_addr); rn rnrnnlh=(struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));rnstrcpy(NLMSG_DATA(nlh), "Hello you!"); rnnlh->nlmsg_len = NLMSG_LENGTH(MAX_PAYLOAD); rnnlh->nlmsg_pid = getpid();rnnlh->nlmsg_flags = 0; rn rniov.iov_base = (void *)nlh; rniov.iov_len = nlh->nlmsg_len; rnmsg.msg_iov = &iov; rnmsg.msg_iovlen = 1; rn rnsendmsg(sock_fd, &msg, 0); rnrn[/code]rnrn发送一个"hello you"! 我向知道这个最大可以发送多大的数据,这个数据大小不能满足要求怎么办。
内核和用户空间通信—netlink源码
一、imp2源码 整个源码包含三个文件:imp2_k.c, imp2_u.c和imp2.h. 其中imp2_k.c为<em>内核</em>模块的源代码,imp2_u.c为应用程序,即测试代码,imp2.h为两个源文件都需要引用的头文件。其整体的功能是:注册一种新的<em>netlink</em><em>协议</em>,并注册一个新的NF hook函数。当有ping包发往当前主机或者经过当前主机转发时,<em>内核</em>向用户发送ping包的源IP和目的IP。各个文件的简单分析见下文。 1. imp2.h 该文件主要是定义了一种新的Netlink<em>协议</em>类型NL_IMP2(31)。新的<em>协议</em>类型的选值不能和当前<em>内核</em>中已经定义的<em>netlink</em><em>协议</em>类型重复。定义了基于该<em>协议</em>类型的消息类型,<em>内核</em>根据接收到消息的不同类型,进行不同的处理:IMP2_U_PID和IMP2_CLOSE分别为请求和关闭。IMP2_K_MSG代表<em>内核</em>空间发送的消息。 该头文件的源码如下: 2. imp2_k.c 该程序为<em>内核</em>模块程序。其完成的功能如下: (1)<em>创建</em>一种新的Netlink<em>协议</em>NL_IMP2,并注册该<em>协议</em>的回调函数kernel_receive。但用户空间通过建立且<em>协议</em>类型为NL_IMP2的<em>socket</em>套接字并调用sendto,sendmsg函数发送数据时,传送到<em>内核</em>空间的数据由kernel_receive进行处理。该函数主要是记录用户进程的ID,用于随后发送数据的时候指定目的。 (2)在Netfilter的hook点NF_IP_PRE_ROUTING注册hook函数get_icmp,对经过该hook点的ping包进行处理。get_icmp首先判断是否是ping包,如果不是,直接Accept。如果是,则记录该包的源IP和目的IP,然后调用send_to_user,将记录的信息发送给kernel_recieve函数中记录的用户进程ID。 该文件的源码如下: 3. imp2_u.c 该程序为用户空间的测试程序。该程序包括以下功能: (1)生成NL_IMP2<em>协议</em>的<em>socket</em>.然后通过调用sendto发送IMP2_U_PID类型的请求信息给<em>内核</em>。然后等待接受<em>内核</em>发回的信息。记住:仅当有ping包经过<em>内核</em>的NF时,<em>内核</em>才会向用户进程发送信息。 (2)当用户进程通过Ctrl+C来结束该程序时,调用信号处理函数sig_int,向<em>内核</em>发送IMP2_CLOSE的消息,结束<em>socket</em>。 该文件的源码如下: 二、编译和测试 1. 整个源文件编译的Makefile如下: all: gcc -O2 -DMODULE -D__KERNEL__ -W -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include -c -o imp2_k.o imp2_k.c gcc imp2_u.c -o imp2_u install: insmod imp2_k.o uninstall: rmmod imp2_k clean: rm -f imp2_k.o imp2_u 2. 加载<em>内核</em>模块,并执行测试程序。 #make install #./imp2_u 当没有ping包时,终端一直处于等待输出状态。通过另一台主机(192.168.1.100)向当前主机(192.168.1.101)发送ping包,则终端已经有输出: #./imp2_u [root@localhost imp2]# ./imp2_u src: 192.168.1.100, dest: 192.168.1.101 src: 192.168.1.100, dest: 192.168.1.101 src: 192.168.1.100, dest: 192.168.1.101 src: 192.168.1.100, dest: 192.168.1.101
有关netlink内核通信的讨论
rn用<em>netlink</em>时,具体的机制是什么呢,与底层的驱动有什么关系啊 ?rn
内核和用户空间的消息传递-netlink (3)
未做实验,待补充。 参考: http://blog.csdn.net/daydring/article/details/24000081
Linux 内核页表的创建
原文地址 jekton.github.io,未经允许,不得转载。 源码使用 Linux 2.6.24,基于 x86 平台;参考书是《深入理解 LINUX <em>内核</em>》第三版 <em>内核</em>跟普通的应用一样,为了使用虚拟内存,也需要一个给 CPU 设置一个页表。在这篇文章中,我们就一起来了解 Linux 是如何为<em>内核</em><em>创建</em>页表的。需要注意的是,这里我并不打算详细讲解页表的方方面面,硬件相关的基础知识,读者可以...
(Linux 内核创建双向循环链表
(Linux <em>内核</em>)<em>创建</em>双向循环链表
新手求教,跪求!内核如何使用netlink协议发送数据
我写了一个例子代码rnrn#include rn#include rn#include rn#include rnrnrn#define NETLINK_USER 31rnrnstruct sock *nl_sk = NULL;rnrnstatic void hello_nl_recv_msg(struct sk_buff *skb) rnrn struct nlmsghdr *nlh;rn int pid;rn struct sk_buff *skb_out;rn int msg_size;rn char *msg="Hello from kernel";rn int res;rnrn printk(KERN_INFO "Entering: %s\n", __FUNCTION__);rnrn msg_size=strlen(msg);rnrn nlh=(struct nlmsghdr*)skb->data;rn printk(KERN_INFO "Netlink received msg payload:%s\n",(char*)nlmsg_data(nlh));rn pid = nlh->nlmsg_pid; /*pid of sending process */rnrn skb_out = nlmsg_new(msg_size,0);rnrn if(!skb_out)rn rn printk(KERN_ERR "Failed to allocate new skb\n");rn return;rn rn nlh=nlmsg_put(skb_out,0,0,NLMSG_DONE,msg_size,0); rn NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */rn strncpy(nlmsg_data(nlh),msg,msg_size);rn rn res=nlmsg_unicast(nl_sk,skb_out,pid); /* 这里有一个pid是用户空间程序的pid */rnrn if(res);rnrnMakefile:rnrnobj-m := <em>netlink</em>_serv.ornKERNEL := $(shell uname -r)rnKERNEL_PATH := /lib/modules/$(shell uname -r)/buildrnCURRENT_PATH :=$(shell pwd)rnall:rnmake -C $(KERNEL_PATH) M=$(CURRENT_PATH) modulesrngcc -o <em>netlink</em>_user <em>netlink</em>_user.c rnclean:rnmake -C $(KERNEL_PATH) M=$(CURRENT_PATH) cleanrnrm -rf *.o <em>netlink</em>_userrnrnrnrn我疑问的地方:rn 我想在一个函数中发送数据给用户空间,怎么使用<em>netlink</em><em>协议</em>呢?如果上面不是一个模块而是一个<em>netlink</em>的初始化和释放函数,这里命名为<em>netlink</em>.c。我在send_data.c 中有一个函数int send(char *msg);rnrn请问我怎么在send_data.c中使用<em>netlink</em><em>协议</em>给用户空间发送数据呢?我是个新手这个问题一直折腾了一天。找不到相关资料啊?求例子代码。rnrn我知道这里放的是数据。rnstruct nlmsghdr rn_u32 nlmsg_len;rn_u32 nlmsg_type;rn_u16 nlmsg_flags;rn_u32 nlmsg_seq;rn_u32 nlmsg_pid; rn;rn可是不会用啊。[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/50.gif][/img]rnrn求教各位高人,指点下新手吧。求实例代码,跪求。rn
求解Win7 VS2008创建socket失败,错误号10106
真是奇怪呀,我用的是Win7 32旗舰版系统,刚打的VS2008 SP1补丁,rn以为打完SP1补丁后<em>创建</em><em>socket</em>就不会出现问题了,没打补丁之前,我<em>创建</em><em>socket</em>也是<em>失败</em>的。rn谁知道打完补丁问题依旧。[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/20.gif][/img]rn说下我的情况:rn无论是否以管理员身份运行VS2008,在VS2008中运行工程时,<em>创建</em><em>socket</em>都会<em>失败</em>,rn错误号为10106。rn而我直接到生成程序的Debug目录或Release目录,运行程序则<em>创建</em><em>socket</em>成功,一切正常。rn这真是奇怪了,我想问题是出在VS2008上面了,网上查了很久,无果。rn望知道原因的盆友给解释一二呀。[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/35.gif][/img]rn贴下,我<em>创建</em><em>socket</em>的代码:rn[code=c]rnWORD wVersionRequested;rn WSADATA wsaData;rn int err;rn wVersionRequested = MAKEWORD( 2, 2 );rn err = WSAStartup( wVersionRequested, &wsaData );rn if ( err != 0 ) rn rn return;rn rnrn /* Confirm that the WinSock DLL supports 2.2.*/rn /* Note that if the DLL supports versions greater */rn /* than 2.2 in addition to 2.2, it will still return */rn /* 2.2 in wVersion since that is the version we */rn /* requested. */rnrn if ( LOBYTE( wsaData.wVersion ) != 2 ||rn HIBYTE( wsaData.wVersion ) != 2 ) rn rn WSACleanup( );rn return; rn rn SOCKET sockSrv=<em>socket</em>(AF_INET,SOCK_STREAM,0);rn if (sockSrv==INVALID_SOCKET)rn rn CString err;rn err.Format(_T("新建Socket<em>失败</em>! WSAGetLastError=%d,GetLastError=%d"),WSAGetLastError(),::GetLastError());rn AfxMessageBox(err);rn WSACleanup();rn return;rn rn AfxMessageBox(_T("新建Socket成功!"));rn[/code]rnrn在VS2008中运行程序,错误截图如下:rn[img=https://img-bbs.csdn.net/upload/201310/04/1380862859_373122.png][/img]rnrn到生成程序的Debug目录直接运行程序,则成功:rn[img=https://img-bbs.csdn.net/upload/201310/04/1380862907_933264.png][/img]rnrn[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/50.gif][/img]rnrnrn
sql2005 创建维护计划总是失败
这样设置频率<em>总是</em><em>失败</em>:每 1 个月于 最后一个 天 的 23:59:59 执行。将从 2010-1-7 开始使用计划。rnrnrn提示“作业计划结束时间必须晚于开始时间”
为何创建Catalog总是失败
用以下方法<em>创建</em>Catalog对像,在多数机器上成功,可在少数机器上<em>总是</em><em>失败</em>,这么为什么呀rnrn_CatalogPtr m_pCatalog;rn m_pCatalog.CreateInstance(__uuidof(Catalog));
QFile创建总是失败????!!!!!!
我用QFile file("123.txt");rn调试的时候,file的值<em>总是</em>为空,请问这是为什么?我在项目的目录下放了相应的文件了,为啥<em>总是</em>读取不出来,我用的是最新的QT版本,请问是不是我哪里没设置好,还是文件不是放在项目的目录下?
mysql创建触发器总是失败
今天没事把触发器研究了一下,但<em>总是</em><em>创建</em><em>失败</em>,仔细检查了一下语法似乎没有任何问题,可<em>总是</em>提示语法错误 create trigger test_tre after insert on tbl1 for each row begin delete from tbl2; end; 就这么一个简单的语句困惑了我半天,后来才想明白,可能是mysql的delimiter结束符设置的问题,于是加上代
linux netlink 示例代码
eu<em>netlink</em>.c -用户程序源码 ek<em>netlink</em>.c -<em>内核</em>程序源码 <em>netlink</em>提供了一种很好很强大的的用户与<em>内核</em>之间的通讯机制,本文通过静态的新增一个<em>netlink</em><em>协议</em>类型,并使用这个新的<em>netlink</em>类型实现用户态和<em>内核</em>态的双向通讯,对<em>linux</em>的<em>netlink</em>通讯方式有了一个初步的认识。 说明:本文所含代码的运行环境为 android提供的 goldfish 模拟器平台, Linux <em>内核</em>版本为 2.6.29
Linux核心接口Netlink
///待写
linux netlink遇到的问题
1.  <em>netlink</em>_kernel_create<em>创建</em><em>失败</em>,返回NULL。 代码:nl_sk = <em>netlink</em>_kernel_create(&init_net, NETLINK_GENERIC, 0, nl_data_ready, NULL, THIS_MODULE); 原因:参数2 值为NETLINK_GENERIC,而该<em>协议</em>在系统已经被占用,可以使用下面命令查看: cat /proc/
Linux netlink机制及示例
 原理 Netlink是一种在<em>内核</em>态和用户态可以进行双向数据传输的通信机制,也就是说,用户进程既可以作为服务器端又可以作为客户端,<em>内核</em>也是如此。用户进程和<em>内核</em>谁是服务器端谁是客户端,这个问题与谁先主动发起数据交互会话有关。 用户进程主动向<em>内核</em>发起会话在Linux<em>内核</em>中很常见,比如系统调用、对/proc的操作等。本文通过详解一个简单的实例程序来说明用户进程通过<em>netlink</em>机制如何主动向内
公认协议号,预分配协议号和端口号文档(取自linux
公认<em>协议</em>号,预分配<em>协议</em>号和端口号文档,取自<em>linux</em>下的两个文件,文件路径和文件名见文件头注释。最新的<em>协议</em>和端口号获取地址见文件头注释。
紧急求助:为什么我总是创建Socket失败
m_pSocket->Create(9999)其中m_pSocket是一继承CSocket的类的指针对象。rn为什么其返回值<em>总是</em>0,我也改过端口号,可是还是不行,希望高手指点迷津。
linuxnetlink接口详解(下)
——<em>linux</em>版本: 3.14.38 <em>netlink</em>支持用户进程和<em>内核</em>相互交互(两边都可以主动发起),同时还支持用户进程之间相互交互(虽然这种应用通常都采用unix-sock) 但是有一点需要注意,<em>内核</em>不支持接收<em>netlink</em>组播消息 本文将从用户进程发送一个<em>netlink</em>消息开始,对整个<em>netlink</em>消息通信原理进行展开分析 用户进程一般都通过调用sendmsg来向<em>内核</em>或其他
关于创建SOCKET失败的问题。
/*连上时间服务器140.252.1.32得到时间*/rnrn#include rn#include rn#include rn#include rnrn#define BUFFSIZE 150rnrnint main()rnrn sockaddr_in serv;rn char buff[BUFFSIZE];rn int sockfd;rn int n;rn rn if((sockfd=<em>socket</em>(PF_INET,SOCK_DGRAM,0)),buff); //打印时间rn rn return(0);rnrnrn运行程序,<em>总是</em>“<em>socket</em> error!”,调试看到变量sockfd=-1。问题:rn<em>创建</em>SOCKET<em>失败</em>是我的程序的问题,还是系统问题??谢谢。rn系统:Windows XP and VC++6.0rn
紧急求助,创建socket失败!!
做一个ftpclient端,传输文件。整个任务要传输大约400左右个文件,所以会不断的打开关闭数据连接,可是传到200左右个就<em>失败</em>,原因是<em>socket</em>返回为-1。试图<em>失败</em>的时候在获取一次<em>socket</em>,这时无论循环几次都会获取不到,查了一下自己每次多是用close(sd)将<em>socket</em>关闭的。不知道这个是什么原因,难道solaris操作系统有限制吗,不知道是否有那位大侠遇到过,如何解决,谢谢指点了。
为什么SOCKET老是创建失败
////////////////////////////////////////////////rn m_<em>socket</em>=<em>socket</em>(AF_INET,SOCK_STREAM,0);rn if(m_<em>socket</em>==INVALID_SOCKET)rn MessageBox("<em>socket</em> error!");rn int i=WSAGetLastError();rn char p[8];rn sprintf(p,"%d",i);rn MessageBox(p);rn rn elsern MessageBox("<em>socket</em> successful");rn rnrn SOCKADDR_IN sockaddr;rn sockaddr.sin_addr .S_un .S_addr =inet_addr("192.168.0.18");rn sockaddr.sin_family =AF_INET;rn sockaddr.sin_port =htons(12345);rn if(SOCKET_ERROR==connect(m_<em>socket</em>,(SOCKADDR*)&sockaddr,sizeof(SOCKADDR)))rn MessageBox("connect error!");rn int i=WSAGetLastError();rn char p[8];rn sprintf(p,"%d",i);rn MessageBox(p);rn rnrn elsern MessageBox("successful");rn rn close<em>socket</em>(m_<em>socket</em>);rn return;rnrn//////////////////////////rn WSADATA wsadata;rn if(WSAStartup(MAKEWORD(2,2),&wsadata))rn AfxMessageBox("wsastartup error!");rn return FALSE;rn rn if(LOBYTE(wsadata.wVersion )!=2||rn HIBYTE(wsadata.wVersion )!=2)rn AfxMessageBox("wsa version error!");rn WSACleanup();rn return FALSE;rn rn//////////////////////////////rn为什么SOCKET 老是<em>创建</em><em>失败</em>rn用GetLastError() 得到的返回值都是0 为什么?
MFC中socket创建失败
<em>创建</em>一个基于对话框的MFC应用程序rn添加头文件#include;rn在APP中的InitInstance()函数中添加代码:rn if(!AfxSocketInit())rn rn AfxMessageBox(_T("套接字库加载<em>失败</em>"));rn rn在CDlg中的OnInitDialog()添加代码:rn m_<em>socket</em> = <em>socket</em>(AF_INET,SOCK_DGRAM,0);rn if(m_<em>socket</em> == INVALID_SOCKET )rn rn MessageBox(_T("套接字<em>创建</em><em>失败</em>"));rn return FALSE;rn rn为什么在运行的时候<em>总是</em>说“套接字<em>创建</em><em>失败</em>”rn
请教socket创建失败的问题
小弟是菜鸟一枚,刚接触<em>socket</em>,可在server运行时<em>socket</em><em>总是</em><em>创建</em><em>失败</em>,代码如下:Server:[code=c]#includern#includern#includern#includern#includern#includern#includern#includern#define backlog 1024rn#define MAX_DATA_SIZE 12rn#define server_port 3333rnrnint main()rnrn struct sockaddr_in server_sockaddr,client_sockaddr;rn int sockfd,client_sockfd,receve_bytes;rn int sin_size; rn char buf[MAX_DATA_SIZE];rn memset(buf,0,MAX_DATA_SIZE);rn rn if((sockfd = <em>socket</em>(AF_INET,SOCK_STREAM,0)) == -1);rn rn perror("<em>socket</em>");rn printf("create <em>socket</em> error...%s\n",strerror(errno));rn exit(1);rn rnrn printf("create <em>socket</em> success! <em>socket</em>fd:%d\n",sockfd);rnrn server_sockaddr.sin_family = AF_INET;rn server_sockaddr.sin_port =htons( server_port);rn server_sockaddr.sin_addr.s_addr = INADDR_ANY;rn bzero(&(server_sockaddr.sin_zero),8);rnrnrn if(bind(sockfd,(struct sockaddr *)&server_sockaddr,sizeof(struct sockaddr)) == -1)rn rn perror("bind");rn exit(1);rn rn printf("bind success\n");rnrn if(listen(sockfd,backlog) == -1)rnrn rn perror("listen");rn exit(1);rn rn rn printf("listening...\n");rnrn if((client_sockfd = accept(sockfd,(struct sockaddr*)&client_sockaddr,&sin_size)) == -1)rn rn perror("accept");rn exit(1);rn rnrnrn if((receve_bytes = recv(client_sockfd,buf,MAX_DATA_SIZE,0)) == -1)rn rn perror("recv");rn exit(1);rn rnrnrn printf("recv a connection\n");rnrn close(sockfd);rn return 0;rn rn rnrn rn[/code]rnrnclient:rn[code=c]#includern#includern#includern#includern#includern#includern#includern#includern#define SERVPORT 3333rn#define MAXDATASIZE 100rnrnint main(int argc,char*argv[])rnrn int <em>socket</em>fd, sendbytes;rn struct sockaddr_in cli_sockaddr;rnrn char buf[MAXDATASIZE];rn memset(buf,0,MAXDATASIZE);rn struct hostent *host;rn struct sockaddr_in serv_addr;rnrn if((<em>socket</em>fd = <em>socket</em>(AF_INET,SOCK_STREAM,0)) == -1)rn rn perror("<em>socket</em>");rn exit(1);rn rn printf("create client <em>socket</em> success\n");rn if(argc < 2)rn rn fprintf(stderr,"Please enter the server's hostname!\n");rn exit(1);rn rn rn serv_addr.sin_family = AF_INET;rn serv_addr.sin_port = htons(3333);rn bzero(&(serv_addr.sin_zero),8);rn rnrn if((host=gethostbyname(argv[1])) == NULL)rn rn perror("gethostbyname error!");rn exit(1);rn rn serv_addr.sin_addr=*((struct in_addr *)host->h_addr);rnrn printf("connect up\n");rn if((connect(<em>socket</em>fd,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr))) == -1)rn rn perror("connect");rn exit(1);rn rnrn if(send(<em>socket</em>fd,"hello",5,0) == -1)rn rn perror("send");rn exit(1);rn rn close(<em>socket</em>fd);rn return 0;rnrn[/code]rnrn运行server显示这样:rn[img=https://img-bbs.csdn.net/upload/201509/01/1441115392_737788.jpg][/img]rn运行client显示这样:rn[img=https://img-bbs.csdn.net/upload/201509/01/1441115742_314068.jpg][/img]rn不知道为什么server端<em>创建</em><em>socket</em><em>失败</em>,请大神指教!
为什么socket老是创建失败?????
SOCKET h;rnstruct sockaddr_in ds;rnint lport=3333;rnrnZeroMemory(&ds, sizeof(ds));rnds.sin_family = AF_INET;rnds.sin_port = htons(lport);rnds.sin_addr.s_addr = htonl(INADDR_ANY);rnrnh = <em>socket</em>( AF_INET, SOCK_STREAM, IPPROTO_TCP );rnif( h == INVALID_SOCKET )rnrn cout<; //这里<em>总是</em>说h<em>创建</em><em>失败</em>,为什么?????rn
linux创建分区表失败
[code=sql]drop table if exists tbInnoDBPartition1;rncreate table tbInnoDBPartition1 (rn id BIGINT auto_increment,rn adddate datetime,rn age int not null,rn price decimal(18, 2),rn title varchar(200) not NULL,rn primary key(id, adddate)rn) ENGINE = InnoDB PARTITION by range(year(adddate) * 100 + month(adddate))(rn PARTITION p201311 values less than (201311) data DIRECTORY = '/home/test/MySQLTestData/InnoDB' index DIRECTORY = '/home/test/MySQLTestData/InnoDB',rn PARTITION p201312 values less than (201312) data DIRECTORY = '/home/test/MySQLTestData/InnoDB' index DIRECTORY = '/home/test/MySQLTestData/InnoDB'rn);rnrndrop table if exists tbMyISAMPartition1;rncreate table tbMyISAMPartition1 (rn id BIGINT auto_increment,rn adddate datetime,rn age int not null,rn price decimal(18, 2),rn title varchar(200) not NULL,rn primary key(id, adddate)rn) ENGINE = MyISAM PARTITION by range(year(adddate) * 100 + month(adddate))(rn PARTITION p201311 values less than (201311) data DIRECTORY = '/home/test/MySQLTestData/MyISAM' index DIRECTORY = '/home/test/MySQLTestData/MyISAM',rn PARTITION p201312 values less than (201312) data DIRECTORY = '/home/test/MySQLTestData/MyISAM' index DIRECTORY = '/home/test/MySQLTestData/MyISAM'rn);rnrn[/code]rnrn1、前者使用 InnoDB,提示 [Err] 1030 - Got error -1 from storage enginernrn2、后者使用 MyISAM,提示目录没有权限:[Err] 1 - Can't create/write to file '/home/test/MySQLTestData/MyISAM/tbMyISAMPartition1#P#p201311.MYI' (Errcode: 13 - Permission denied)rn但是我已经把这个目录权限设为 777 了:chmod 777 MyISAM
linux tcp协议创建
该文件主要是<em>创建</em>tcp客户端和服务端的连接
Linux网络编程之socket创建
对于用户态编程的第一个函数是 fd=<em>socket</em>(AF_INET,SOCK_STREAM,0); 该函数会通过系统调用进入<em>内核</em>,<em>内核</em>的实现如下: kernel\net\Socket.c SYSCALL_DEFINE3(<em>socket</em>, int, family, int, type, int, protocol) { int retval; struct <em>socket</em> *so
linux netlink 示例代码: 通过net link 进行 内核和用户空间的数据通讯
eu<em>netlink</em>.c -用户程序源码 ek<em>netlink</em>.c -<em>内核</em>程序源码 <em>netlink</em>提供了一种很好很强大的的用户与<em>内核</em>之间的通讯机制,本文通过静态的新增一个<em>netlink</em><em>协议</em>类型,并使用这个新的<em>netlink</em>类型实现用户态和<em>内核</em>态的双向通讯,对<em>linux</em>的<em>netlink</em>通讯方式有了一个初步的认识。 说明:本文所含代码的运行环境为 android提供的 goldfish 模拟器平台, Linux <em>内核</em>版本为 2.6.29
Linux Kernel 学习笔记9:内核与用户层通信之netlink
(本章基于:Linux-4.4.0-37) <em>内核</em>与用户空间通信有很多种通信方式,<em>netlink</em>是其中一种,其余的还有/proc、ioctl、sockopt、共享内存等等。<em>netlink</em>的特点是异步全双工。 <em>netlink</em>使用32位端口寻址,称为pid(与进程号没有关系),其中<em>内核</em>的pid地址为0,。<em>netlink</em>主要特性如下: ① 支持全双工、异步通信(当然同步也支持) ② 用
uevent内核事件与netlink机制的交互 -Linux Kernel实现欣赏
整理后一并上传
Linux中Netlink实现热插拔监控——内核与用户空间通信
1、什么是NetLink?  它 是一种特殊的 <em>socket</em>,它是 Linux 所特有的,由于传送的消息是暂存在<em>socket</em>接收缓存中,并不被接收者立即处理,所以<em>netlink</em>是一种异步通信机制。 系统调用和 ioctl 则是同步通信机制。Netlink是面向数据包的服务,为<em>内核</em>与用户层搭建了一个高速通道。 用户空间进程可以通过标准<em>socket</em> API来实现消息的发送、接收。进程间通信的方式有...
Generic Netlink内核实现分析(二):通信
前一篇博文中分析了Generic Netlink的消息结构及<em>内核</em>初始化流程,本文中通过一个示例程序来了解Generic Netlink Family的注册初始化以及<em>内核</em>和应用层之间的通信流程。
linux2.6.25版本netlink造成内核panic
我用的是<em>linux</em>2.6.25<em>内核</em>的基础上自己增加了个自定义的<em>netlink</em>。<em>内核</em>态和用户态可以进行通信,但是在执行完通信后,系统会发生如下的错误:rnipencrypt init <em>netlink</em>rnReceive <em>netlink</em> message beginrnReceive <em>netlink</em> message payload miss here!rnReceive <em>netlink</em> message, skb address:c70411e0, nlh address:c7bcf400rnsend <em>netlink</em> message beginrnsend <em>netlink</em> message 1rnsend <em>netlink</em> message skb address:c70410a0, nlh address:c7bcf200,msg adddress:c7bcf210rnsend <em>netlink</em> message 2rnfailure send <em>netlink</em>rnReceive <em>netlink</em> message endrnUnable to handle kernel paging request for data at address 0x3c31323ernFaulting instruction address: 0xc006bc34rnOops: Kernel access of bad area, sig: 11 [#1]rnFreescale MPC8272 ADSrnModules linked in: ipencrypt_<em>netlink</em>rnNIP: c006bc34 LR: c006bc08 CTR: c022ff00rnREGS: c7bcbba0 TRAP: 0300 Not tainted (2.6.25)rnMSR: 00001032 CR: 28002284 XER: 20000000rnDAR: 3c31323e, DSISR: 20000000rnTASK = c78477c0[778] 'klogd' THREAD: c7bca000rnGPR00: 00000000 c7bcbc50 c78477c0 c03194c8 000004d0 c01c5998 ffffffff c7bcbe48 rnGPR08: c7bcbddc c0319000 00000000 00000480 48000288 100ac86c 100b0000 1008afb0 rnGPR16: 100beee8 1007ecb4 c7bcbce8 c0333388 00000000 bf80a728 0000005f c7bcbce8 rnGPR24: c799b1d8 c799b238 000004d0 c01c5998 000004d0 00009032 3c31323e c03194c8 rnCall Trace:rn[c7bcbc50] [c0018194] (unreliable)rn[c7bcbc70] [c01ca414] rn[c7bcbc90] [c01c5998] rn[c7bcbce0] [c02300f0] rn[c7bcbd50] [c01c3970] rn[c7bcbe30] [c01c3ce8] rn[c7bcbf00] [c01c4674] rn[c7bcbf40] [c000fcf8] rn--- Exception: c01Instruction dump:rn4bfffe2d 2b830010 7c7f1b78 409d003c 7fa000a6 57a0045e 7c000124 83df0074 rn2f9e0000 419e0078 801f0080 5400103a 913f0074 7fa00124 73808000 rn---[ end trace 8337b812452f0803 ]---rnKERNEL: assertion (!atomic_read(&sk->sk_wmem_alloc)) failed at net/unix/af_unix.c (350)rnKERNEL: assertion (sk_unhashed(sk)) failed at net/unix/af_unix.c (351)rnKERNEL: assertion (!sk->sk_<em>socket</em>) failed at net/unix/af_unix.c (352)rnAttempt to release alive unix <em>socket</em>: c799b180rnUnable to handle kernel paging request for data at address 0x00000000rnFaulting instruction address: 0xc01ccc4crnOops: Kernel access of bad area, sig: 11 [#2]rnFreescale MPC8272 ADSrnModules linked in: ipencrypt_<em>netlink</em>rnNIP: c01ccc4c LR: c01ccda8 CTR: c0230f78rnREGS: c7bbfbb0 TRAP: 0300 Tainted: G D (2.6.25)rnMSR: 00001032 CR: 20022488 XER: 00000000rnDAR: 00000000, DSISR: 22000000rnTASK = c7b727c0[776] 'syslogd' THREAD: c7bbe000rnGPR00: 00000000 c7bbfc60 c7b727c0 c799b000 00000000 c7bbfcc8 c7bbfce8 00000000 rnGPR08: c7bbfdbc 00000000 00009032 c70411e0 20000482 100ac86c 100b0000 1008afb0 rnGPR16: bf881778 bf8812f8 bf881378 00000000 c7bbfce8 c799b0b8 c00336dc c7bbfcc8 rnGPR24: 00000000 c7bbfc68 c7bbfc74 7fffffff c7404b00 c799b064 c799b000 c70411e0 rnCall Trace:rn[c7bbfc60] [00000004] (unreliable)rn[c7bbfcc0] [c01ccda8] rn[c7bbfce0] [c0230fec] rn[c7bbfd30] [c01c3514] rn[c7bbfe20] [c01c3800] rn[c7bbff00] [c01c4664] rn[c7bbff40] [c000fcf8] rn--- Exception: c01Instruction dump:rn41beff4c 801f0068 54007ffe 90170000 40b2ff18 813d0008 3929ffff 913d0008 rn817f0000 813f0004 931f0000 931f0004 912b0004 7d400124 419eff18 rn---[ end trace 8337b812452f0803 ]---rn------------[ cut here ]------------rnBadness at c0022ca0 [verbose debug info unavailable]rnNIP: c0022ca0 LR: c01c55f0 CTR: c01c4708rnREGS: c7bbf990 TRAP: 0700 Tainted: G D (2.6.25)rnMSR: 00021032 CR: 20022422 XER: 20000000rnTASK = c7b727c0[776] 'syslogd' THREAD: c7bbe000rnGPR00: 00000001 c7bbfa40 c7b727c0 c799b000 00000000 00000000 00000000 00000000 rnGPR08: 00001032 c03243c0 00000020 c7bbe000 80024428 100ac86c 100b0000 1008afb0 rnGPR16: bf881778 bf8812f8 bf881378 00000000 c7bbfce8 c799b0b8 c00336dc c7bbfcc8 rnGPR24: 00000000 c7bbfc68 ffffffff 00000000 c7404b00 c7404b0c c7ba1900 c799b000 rnCall Trace:rn[c7bbfa40] [c031da0c] (unreliable)rn[c7bbfa50] [c01c55f0] rn[c7bbfa90] [c01c29d0] rn[c7bbfac0] [c01c472c] rn[c7bbfad0] [c006fff8] rn[c7bbfaf0] [c006ca78] rn[c7bbfb10] [c001f1a4] rn[c7bbfb30] [c00207a8] rn[c7bbfb70] [c000dd38] rn[c7bbfb90] [c0012198] rn[c7bbfba0] [c0010198] rn--- Exception: 300[c7bbfc60] [00000004] (unreliable)rn[c7bbfcc0] [c01ccda8] rn[c7bbfce0] [c0230fec] rn[c7bbfd30] [c01c3514] rn[c7bbfe20] [c01c3800] rn[c7bbff00] [c01c4664] rn[c7bbff40] [c000fcf8] rn--- Exception: c01Instruction dump:rn80010014 83e1000c 38210010 7c0803a6 4e800020 4bfe3535 4bffffdc 3d20c032 rn392943c0 80090138 7c000034 5400d97e 2f800000 419eff94 38000001 rnUnable to handle kernel paging request for data at address 0x00000004rnFaulting instruction address: 0xc01c7fccrnOops: Kernel access of bad area, sig: 11 [#3]rnFreescale MPC8272 ADSrnModules linked in: ipencrypt_<em>netlink</em>rnNIP: c01c7fcc LR: c0230a20 CTR: c0230b4crnREGS: c7bbf9c0 TRAP: 0300 Tainted: G D (2.6.25)rnMSR: 00001032 CR: 20028428 XER: 20000000rnDAR: 00000004, DSISR: 22000000rnTASK = c7b727c0[776] 'syslogd' THREAD: c7bbe000rnGPR00: 00000000 c7bbfa70 c7b727c0 c799b064 00000001 00000000 00000000 00000000 rnGPR08: 00001032 ffffffe3 c70411e0 00000000 20024428 100ac86c 100b0000 1008afb0 rnGPR16: bf881778 bf8812f8 bf881378 00000000 c7bbfce8 c799b0b8 c00336dc c7bbfcc8 rnGPR24: 00000000 c7417d80 00000007 00000003 c7ba1080 00000000 c799b064 c799b000 rnCall Trace:rn[c7bbfa70] [c02309c4] (unreliable)rn[c7bbfaa0] [c01c3eb8] rn[c7bbfac0] [c01c4734] rn[c7bbfad0] [c006fff8] rn[c7bbfaf0] [c006ca78] rn[c7bbfb10] [c001f1a4] rn[c7bbfb30] [c00207a8] rn[c7bbfb70] [c000dd38] rn[c7bbfb90] [c0012198] rn[c7bbfba0] [c0010198] rn--- Exception: 300[c7bbfc60] [00000004] (unreliable)rn[c7bbfcc0] [c01ccda8] rn[c7bbfce0] [c0230fec] rn[c7bbfd30] [c01c3514] rn[c7bbfe20] [c01c3800] rn[c7bbff00] [c01c4664] rn[c7bbff40] [c000fcf8] rn--- Exception: c01Instruction dump:rn7d0000a6 5500045e 7c000124 81430000 7f8a1800 419e0034 81230008 38000000 rn816a0000 3929ffff 91230008 91630000 900a0000 900a0004 7d000124 rn---[ end trace 8337b812452f0803 ]---rnFixing recursive fault but reboot is needed!rnUnable to handle kernel paging request for data at address 0x4011332crnFaulting instruction address: 0xc007b7a8rnOops: Kernel access of bad area, sig: 11 [#4]rnFreescale MPC8272 ADSrnModules linked in: ipencrypt_<em>netlink</em>rnNIP: c007b7a8 LR: c0076044 CTR: c001a5e4rnREGS: c7199d10 TRAP: 0300 Tainted: G D (2.6.25)rnMSR: 00009032 CR: 44000424 XER: 00000000rnDAR: 4011332c, DSISR: 20000000rnTASK = c7009ba0[902] 'ps' THREAD: c7198000rnGPR00: c0076044 c7199dc0 c7009ba0 4011332c 0000001d 00020001 00000002 41c23977 rnGPR08: 00000004 c7bcf3f4 c7198034 c7bcf400 24000424 100ac86c 100b0000 1008afb0 rnGPR16: c0304bb4 c743452c c025c5a0 c7bcf428 c0320000 c70a2780 c7199e38 fffffff2 rnGPR24: 00000400 c7198000 00000400 00000400 0000ffff 00000000 00020001 4011332c rnCall Trace:rn[c7199dc0] [c0019834] (unreliable)rn[c7199de0] [c0076044] rn[c7199e30] [c006ea94] rn[c7199ef0] [c006f4fc] rn[c7199f10] [c006fb74] rn[c7199f40] [c000fcf8] rn--- Exception: c01Instruction dump:rn8017fffc 90010018 4bffffcc 9421ffe0 7d800026 7c0802a6 bfc10018 7c7f1b79 rn7cbe2b78 90010024 91810014 41820054 2e040017 2f804601 41be0014 rn---[ end trace 8337b812452f0803 ]---rnUnable to handle kernel paging request for data at address 0x03de006crnFaulting instruction address: 0xc024d844rnOops: Kernel access of bad area, sig: 11 [#5]rnFreescale MPC8272 ADSrnModules linked in: ipencrypt_<em>netlink</em>rnNIP: c024d844 LR: c0075e0c CTR: 00000000rnREGS: c7bcbcf0 TRAP: 0300 Tainted: G D (2.6.25)rnMSR: 00009032 CR: 24002484 XER: 00000000rnDAR: 03de006c, DSISR: 20000000rnTASK = c70097c0[903] 'grep' THREAD: c7bca000rnGPR00: c7bcbdb4 c7bcbda0 c70097c0 03de006c c7bcbda8 c7b811a0 c001af64 00000000 rnGPR08: c7bcbdb4 00000000 00000000 c7b81340 000021c6 100ac86c c70a2d80 00000000 rnGPR16: bfffffff c7bcbe38 00000000 00000000 00000400 00000000 00000000 00000000 rnGPR24: 0fedb340 00000000 c7bcf400 c7bcbf20 c7bcbf20 c70a2d80 c7bcbda8 c7bcf400 rnCall Trace:rn[c7bcbda0] [c0075dec] (unreliable)rn[c7bcbdd0] [c00764a8] rn[c7bcbe30] [c006ebcc] rn[c7bcbef0] [c006f668] rn[c7bcbf10] [c006fae4] rn[c7bcbf40] [c000fcf8] rn--- Exception: c01Instruction dump:rn2f890000 4dbd0020 48000174 7c001828 3000ffff 7c00192d 40a2fff4 2f800000 rn419c000c 38600000 4e800020 4800026c 3000ffff 7c00192d 40a2fff4 rn---[ end trace 8337b812452f0803 ]---rnUnable to handle kernel paging request for data at address 0x0023ae75rnFaulting instruction address: 0xc007b424rnOops: Kernel access of bad area, sig: 11 [#6]rnFreescale MPC8272 ADSrnModules linked in: ipencrypt_<em>netlink</em>rnNIP: c007b424 LR: c00754cc CTR: c0075ab0rnREGS: c7bcbaf0 TRAP: 0300 Tainted: G D (2.6.25)rnMSR: 00001032 CR: 24002424 XER: 20000000rnDAR: 0023ae75, DSISR: 20000000rnTASK = c70097c0[903] 'grep' THREAD: c7bca000rnGPR00: 00001032 c7bcbba0 c70097c0 ffffffff 0023ae69 00000000 c7bcf428 00000000 rnGPR08: 00009032 c7426500 00000020 00000000 24004422 100ac86c c70a2d80 00000000 rnGPR16: bfffffff c7bcbe38 00000000 00000000 00000400 00000000 00000000 00000000 rnGPR24: 0fedb340 ffffffff c743452c 00000000 c70a2d80 ffffffff c7bcf428 c70a2d80 rnCall Trace:rn[c7bcbba0] [c0058d40] (unreliable)rn[c7bcbbc0] [c00754cc] rn[c7bcbbf0] [c0075ad0] rn[c7bcbc10] [c006fff8] rn[c7bcbc30] [c006ca78] rn[c7bcbc50] [c001f1a4] rn[c7bcbc70] [c00207a8] rn[c7bcbcb0] [c000dd38] rn[c7bcbcd0] [c0012198] rn[c7bcbce0] [c0010198] rn--- Exception: 300[c7bcbda0] [c0075dec] (unreliable)rn[c7bcbdd0] [c00764a8] rn[c7bcbe30] [c006ebcc] rn[c7bcbef0] [c006f668] rn[c7bcbf10] [c006fae4] rn[c7bcbf40] [c000fcf8] rn--- Exception: c01Instruction dump:rn7c9f2378 90010024 7cde3378 91810010 409200e0 39600000 7c0000a6 5400045e rn7c000124 809e0000 2f840000 419e0034 7fc9f378 7f80f800 40be0014 rn---[ end trace 8337b812452f0803 ]---rnFixing recursive fault but reboot is needed!rnrnrn
Netlink 内核实现分析(二):通信
Netlink 是一种用于<em>内核</em>与用户空间通信的IPC(Inter Process Commumicate)机制,本文主要分析<em>内核</em>空间和用户空间使用<em>netlink</em>进行通信的具体流程。
Generic Netlink内核实现分析(一):初始化
Generic Netlink 是<em>内核</em>专门为了扩展<em>netlink</em><em>协议</em>簇而设计的“通用<em>netlink</em><em>协议</em>簇”,它基于Netlink子系统。本文以Generic Netlink为例来深入分析一下Netlink和Generic Netlink的消息结构以及子系统的<em>创建</em>初始化流程。
NDK socket connect 总是失败。求助。
rn权限已经添加。rn所以<em>创建</em><em>socket</em>没问题,可是connect<em>总是</em><em>失败</em>。rnGoogle得到一片国外论坛帖子,问题和我的如出一辙。rn帖子地址:http://stackoverflow.com/questions/4927356/android-ndk-networking-problems-tcp-connection-failsrnrnrn那位大神帮助下阿。十分感谢。
netlink内核层与用户层之间通信
目录 <em>netlink</em> api 应用层api <em>内核</em>层api <em>netlink</em>编码 应用层编码 <em>内核</em>层编码 <em>netlink</em>案例 应用层 [<em>netlink</em>_app.c] <em>内核</em>层 [<em>netlink</em>_driver.c] Makefile 测试结果 <em>netlink</em> api 应用层api <em>内核</em>层api <em>netlink</em>编码 应用层编码 <em>内核</em>层编码 n...
如何通过netlink来读取内核信息??
大家好,不知道怎么样通过<em>netlink</em>来获取<em>内核</em>中的网络地址,MAC地址,和路由表等信息,我对<em>netlink</em>还比较生疏,请各位大哥大姐们多多指点啊,这里谢过了先!
如何通过netlink来读取内核信息
怎么样通过<em>netlink</em>的函数库读取<em>内核</em>中有关网络的信息呢,如网卡地址,mac地址,和路由表信息等,有没有关于这方面的资料,书籍啊?请各位高手多多指点,这里先谢过了!rn
新手求助~netlink内核接收用户信息
我的<em>内核</em>版本是<em>linux</em>-2.6.32.12-0.7版本的rn看到网上还有个skb_get试过也不好使rn还有就是我怎么判断用户把信息发出来了呢?<em>内核</em>没收到也可能是用户没发出来,多谢各位大侠~~rn然后网上参考的是http://blog.chinaunix.net/uid-23069658-id-3405954.htmlrn这个帖子写的程序,但是rmmod kernel.ko时会被killed 而且<em>内核</em>也没有显示从用户得到的信息,dmesg信息如下:rnrntest <em>netlink</em> initrn[ 848.321732] test <em>netlink</em> exitrn[ 848.321747] BUG: unable to handle kernel NULL pointer dereference at 00000144rn[ 848.321754] IP: [] testnl_exit+0x14/0x30 [mynlker]rn[ 848.321761] *pdpt = 00000000339fe001 *pde = 0000000000000000rn[ 848.321765] Oops: 0000 [#1] SMPrn[ 848.321768] last sysfs file: /sys/devices/virtual/dmi/id/sys_vendorrn[ 848.321772] Modules linked in: mynlker(N-) binfmt_misc af_packet joydev usbhid hid microcode fuse loop dm_mod sg rtc_cmos ppdev rtc_core i2c_piix4 parport_pc i2c_core parport rtc_lib sr_mod floppy tpm_tis tpm tpm_bios pcspkr button uhci_hcd ehci_hcd usbcore sd_mod crc_t10dif edd ext3 mbcache jbd fan processor ide_pci_generic piix ide_core ata_generic ata_piix libata thermal thermal_sys hwmon xen_scsi(N) scsi_mod xen_vnif(N) xen_balloon(N) xen_hcall(N) xen_vbd(N) cdrom xen_vmdq(N) xen_platform_pci(N) [last unloaded: speedstep_lib]rn[ 848.321808] Supported: Yesrn[ 848.321810]rn[ 848.321813] Pid: 5524, comm: rmmod Tainted: G N (2.6.32.12-0.7-pae #1) HVM domUrn[ 848.321817] EIP: 0060:[] EFLAGS: 00010286 CPU: 0rn[ 848.321821] EIP is at testnl_exit+0x14/0x30 [mynlker]rn[ 848.321823] EAX: 00000000 EBX: 00000000 ECX: 0000a1a1 EDX: 00a32000rn[ 848.321826] ESI: 00000000 EDI: f7823200 EBP: f7823000 ESP: f3559f4crn[ 848.321829] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068rn[ 848.321833] Process rmmod (pid: 5524, ti=f3558000 task=f3a5a430 task.ti=f3558000)rn[ 848.321835] Stack:rn[ 848.321837] f7823110 c026a083 6c6e796d 0072656b 00000000 f39a8234 f3a43c80 f3e78dd8rn[ 848.321843] f3a43c80 f39a8234 00000014 b771e9d0 f3559fb4 c0533384 00000000 f3a43c84rn[ 848.321848] 00001000 f7823200 00000880 f3559f9c 00000000 bf97a950 bf97a950 00000880rn[ 848.321855] Call Trace:rn[ 848.321871] [] sys_delete_module+0x173/0x220rn[ 848.321878] [] sysenter_do_call+0x12/0x22rn[ 848.321885] [] 0xffffe424rn[ 848.321887] Code: 80 44 01 00 00 83 c4 04 e9 8e c1 c6 c8 8d b4 26 00 00 00 00 8drn[ 848.321899] EIP: [] testnl_exit+0x14/0x30 [mynlker] SS:ESP 0068:f3559f4crn[ 848.321904] CR2: 0000000000000144rn[ 848.321907] ---[ end trace 7b24547b7f85f2ea ]---rnrnrnrn我的代码如下:rn用户:rnrn int main(int argc,char *argv[])rnrn struct sockaddr_nl dest_addr;rn struct nlmsghdr *nlh = NULL;rn struct iovec iov;rn int sock_fd = -1;rn struct msghdr msg;rn int ret;rnrn if((sock_fd = <em>socket</em>(PF_NETLINK,SOCK_RAW,NETLINK_TEST))nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);rn nlh->nlmsg_pid = 0;rn nlh->nlmsg_type = NLMSG_NOOP;rn nlh->nlmsg_flags = 0;rnrn /*set the <em>netlink</em> info*/rn strcpy(NLMSG_DATA(nlh),argv[1]);rnrn if(ret = bind(sock_fd,(struct sockaddr *)&dest_addr,sizeof(dest_addr)))rn rn perror("can not bind sockfd with sockaddr_nl\n");rn exit(1);rn rnrn if(NULL==(nlh=(struct nlmsghdr*)malloc(NLMSG_SPACE(MAX_PAYLOAD))))rn rn perror("malloc failed \n");rn exit(1);rn rnrn memset(nlh,0,MAX_PAYLOAD);rnrn /*fill the <em>netlink</em> header with specified infor*/rn nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);rn nlh->nlmsg_pid = 0;rn nlh->nlmsg_type = NLMSG_NOOP;rn nlh->nlmsg_flags = 0;rnrn /*set the <em>netlink</em> info*/rn strcpy(NLMSG_DATA(nlh),argv[1]);rnrn memset(&iov,0,sizeof(iov));rn iov.iov_base = (void*)nlh;rn iov.iov_len = nlh->nlmsg_len;rn memset(&msg,0,sizeof(msg));rn msg.msg_iov = &iov;rn msg.msg_iovlen = 1;rnrn sendmsg(sock_fd,&msg,0);rnrn close(sock_fd);rn free(nlh);rn return 0;rnrnrn<em>内核</em>:rn#define NETLINK_TEST 18rnMODULE_LICENSE("GPL");rnrnstruct sock *nl_sk = NULL;rnrnstatic void nl_data_ready(struct sock *sk,int len)rnrn// struct sk_buff_head *readq;rn struct sk_buff *skb;rn struct nlmsghdr * nlh = NULL;rnrn// while((skb = skb_get(skb))!=NULL)rn while((skb=skb_dequeue(&sk->sk_receive_queue))!=NULL)rn rn printk(KERN_ALERT "In receive!\n");rn nlh=(struct nlmsghdr*)skb->data;rn printk(KERN_ALERT "%s: receive <em>netlink</em> msg payload: %s\n",__func__,(char *)NLMSG_DATA(nlh));rn kfree_skb(skb);rn rnrn printk("received finished!\n");rnrnrnstatic void testnl_exit(void)rnrn printk(KERN_ALERT "test <em>netlink</em> exit\n");rn sock_release(nl_sk->sk_<em>socket</em>);rnrnrnstatic int testnl_init(void)rnrn printk("test <em>netlink</em> init\n");rn nl_sk = <em>netlink</em>_kernel_create(&init_net,NETLINK_TEST,0,nl_data_ready,NULL,THIS_MODULE);rn return 0;rnrn
linux环境下daemon模式运行子进程与netlink通信失败
一个基于debian的嵌入式运行环境rnrndaemon模式下运行一个dhcpcd进程,获取ip,下发路由等都ok。<em>netlink</em>能够收到地址add和路由add等网络事件rnrn此时通过system()方法kill掉进程,dhcpcd无法正确的发送routedel等事件到<em>netlink</em>,可以捕捉到sock发送错误,返回errno为no such prosessrnrn然而发送的套接字打印出来是没有变过的……dhcpc运行的时候也是用的同一个sock,kill的时候就no such process了…………rnrn更神奇的是,通过shell直接kill dhcpcd则完全正常!!!rnrnrn有没有大神给分析一下可能存在的问题?rnrn以下是dhcpc启动代码rn[code=c]int i = 0;rn argv[i++] = buff;rnrn if(idc->gw == 0)rn argv[i++] = "-G"; /*do not use default route*/rn rn argv[i++] = "-m 0"; /*do not set metric*/ rn argv[i++] = "-b"; /*background 使用lib_system方法启动时,不加该参数,则能够正确接收路由信息*/ rnrn char mac[128];rn char temp[32];rn bzero( mac , 128);rn bzero( temp , 32);rn rn if (idc->hostname)rn rn argv[i++] = DHCP_OPT_HOSTNAME;rn argv[i++] = idc->hostname;rn rn argv[i++] = if_kernel_name (idc->ifp);rn argv[i] = 0;rn //pal_daemonize_program (argv[0], argv, 0, 0); 原本用的这个方法daemon启动,最终会调用execv。后为了定位问题改用lib_system启动,最终会调到system()rn rn unsigned char cmd[512] = 0;rn unsigned char *ptr = cmd;rn for( i = 0; argv[i] != NULL; i++)rn rn sprintf(ptr,"%s ",argv[i]);rn ptr += strlen(ptr);rn rn rn lib_system("%s &",cmd);rn rn[/code]
netlink socketlinux内核模块与用户态之间通信实例)
本文通过一个编程实例来更深入地了解<em>netlink</em>。1.1        实现内容1.          功能Ø  实现一个并发的echo服务器程序,它(接收端)将接收到字符串进行转换处理后,返回给发送端;允许有多个发送端同时存在;Ø  字符串的处理包括:直接返回、全部转换为大写、全部转换为小写;处理方式应可以配置,配置方式包括全局(缺省)及每“发送-接收对(xmit/recv peer)”的。配置...
netlink和Linux网络配置库Pyroute2.zip
Pyroute2是一个纯Python编写的<em>netlink</em>和Linux网络配置库。这个库提供了如下模块:Netlink<em>协议</em>实现(RTNetlink, TaskStats等)rtnl, 网络设置 --- 地址(addresses), 路由(routes), 传输控制(traffic controls)nl80211 --- 无线功能相关的API(开发中)nf<em>netlink</em> --- netfilter API: ipset (开发中), ...ipq --- 最简单的用户空间包过滤, iptables QUEUE targettaskstats --- 扩展的进程统计简单的<em>netlink</em> <em>socket</em>对象, 可被用在poll/select中网络配置模块(IPRoute)在某种程度上提供类似ip/tc功能的APIIPDB是一个Linux网络设置的异步事务数据库 标签:Pyroute2
linux netlink 编程示例(二)应用层
这篇文章给出一个<em>netlink</em>应用层程序用例,和上一篇博客<em>内核</em>篇结合起来参考。<em>内核</em>版本:3.4.39nlclient.c/* * Description : 应用层<em>netlink</em>编程 * Date :20180529 * Author :mason * Mail : mrsonko@126.com * */ #include &amp;lt;lin...
linuxnetlink接口详解(上)
<em>内核</em>版本:3.14.38 <em>netlink</em>是一种用于<em>内核</em>态和用户态进程之间进行数据传输的特殊的IPC机制。 特点:     1) 用户态采用<em>socket</em>风格的API     2) 除了预定义的<em>协议</em>类型之外,支持自定义<em>协议</em>类型     3) 异步通讯     4) 支持消息组播     4) 全双工(特别是支持<em>内核</em>主动发起会话) <em>netlink</em>涉及的数据结构:
linuxnetlink接口详解(中)
本文介绍了<em>linux</em><em>内核</em>中<em>netlink</em>模块的实现原理,主要包括整体架构和初始化相关
linux 内核】Linux 内核-常见问题
一。Linux<em>内核</em>主要有几种<em>内核</em>锁        主要有自旋锁和信号量        自旋锁是防止多处理器并发而引入的一种锁,在<em>内核</em>中大量应用于中断处理 二。Linux用户模式和<em>内核</em>模式        用户模式是受限模式,对内存和硬件的访问必须通过系统调用实现        <em>内核</em>模式是一种高特权模式,能直接访问内存和硬件 三。怎样申请大块<em>内核</em>内存
Linux socket函数创建过程分析
Linux <em>socket</em>函数<em>创建</em>过程分析(从用户到<em>内核</em>作用过程) houyufeng Socket 有关<em>socket</em>在网络编程中的作用我就不多做介绍。简单介绍下<em>socket</em>的发展历史。 套接字起源于 20 世纪 70 年代加利福尼亚大学伯克利分校版本的 Unix,即人们所说的 BSD Unix。 因此,有时人们也把套接字称为“伯克利套接字”或“BSD 套接字”。一开始,套接字被设计用在同 一台...
Linux 编译原来内核失败原因探索
大家好:rn  前些天由于工作上的需要,在RedHat4.0的2.6.9-11.ELsmp<em>内核</em>上成功重新编译了2.6.11的<em>内核</em>,rn现在我想把系统原来的2.6.9-11.ELsmp<em>内核</em>重新编译一下,照着以前的步骤进行,出现如下问题(我分别在2.6.11以及rn2.6.9-11.EL上编译的,出现错误都是一样的啊):rnrnrnStep1:rnmake mrproper:rnCLEAN initrnCLEAN include/asm-i386/asm_offsets.hrnscripts/Makefile.clean:10: Documentation/DocBook/Makefile: 没有那个文件或目录rnmake[1]: *** 没有规则可以<em>创建</em>目标“Documentation/DocBook/Makefile”。 停止。rnmake: *** [_mrproper_Documentation/DocBook] 错误 2rnrnStep2:rnmake menuconfigrn...rnrnStep3:rnmake deprn...rnrnStep4:rnmake cleanrn...rnrnStep5:rnmake bzImage:rnCHK include/<em>linux</em>/version.hrnSPLIT include/<em>linux</em>/autoconf.h -> include/config/*rnCHK include/asm-i386/asm_offsets.hrn/bin/sh: arch/i386/kernel/asm-offsets.s: 没有那个文件或目录rnUPD include/asm-i386/asm_offsets.hrnmv: stat‘include/asm-i386/asm_offsets.h.tmp’<em>失败</em>: 没有那个文件或目录rnmake: *** [include/asm-i386/asm_offsets.h] 错误 1rnrnrnStep1,Step5分别出现如上述问题,导致编译无法正常进行.rnrnrn是不是不能编译系统本来就有的<em>内核</em>啊,还是我的方法不对,请知道的兄弟姐妹告知一下.rnrn还有,是不是不能自己编译自己,也就是说只能在别的正常的<em>内核</em>里面编译自己想要编译的<em>内核</em>,我是这么想的,不知道对不对啊.rn
为什么我创建dialog时总是失败??
hWndDialog = CreateDialog(hInst,MAKEINTRESOURCE(IDD_MAIN_DIALOG),rn NULL,(DLGPROC)MainDlgProc);rnrn在该函数上设置断点,运行时<em>总是</em>rnFirst-chance exception in RemoteDogS.exe (NTDLL.DLL): 0xC0000005: Access Violationrnrn什么原因啊??
VC中嵌入浏览器,创建总是失败
BOOL CMsgDlg::OnInitDialog() rnrn CBaseDlg::OnInitDialog();rn rn VERIFY( m_htmlCtl.CreateFromStatic(IDC_STATIC_HTML, this) );rn rn m_edMsg.ShowWindow( SW_HIDE );rnrn // TODO: Add extra initialization herern m_buttonNext.ShowWindow(SW_HIDE);rn m_buttonPre.ShowWindow(SW_HIDE);rnrn return TRUE; // return TRUE unless you set the focus to a controlrn // EXCEPTION: OCX Property Pages should return FALSErnrnrnrn CStatic wndStatic;rn if (!wndStatic.SubclassDlgItem(nID, pParent))rn return FALSE;rnrn // Get static control rect, convert to parent's client coords.rn CRect rc;rn wndStatic.GetWindowRect(&rc);rn pParent->ScreenToClient(&rc);rn wndStatic.DestroyWindow();rnrn // create HTML control (CHtmlView)rn return Create(NULL, // class namern NULL, // titlern (WS_CHILD | WS_VISIBLE ), // stylern rc, // rectanglern pParent, // parentrn nID, // control IDrn NULL); // frame/doc context not usedrnrnrnrn // create the view window itselfrn m_pCreateContext = pContext;rn if (!CView::Create(lpszClassName, lpszWindowName,rn dwStyle, rect, pParentWnd, nID, pContext))rn rn return FALSE;rn rnrn AfxEnableControlContainer();rnrn RECT rectClient;rn GetClientRect(&rectClient);rnrn // create the control windowrn // AFX_IDW_PANE_FIRST is a safe but arbitrary IDrn if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,rn WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))rn rn DestroyWindow(); // 在这里<em>失败</em>了 ????(独立运行客户端界面成功,但是嵌入到其他客户端就<em>失败</em>rn return FALSE;rn rnrn LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();rn HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);rn if (!SUCCEEDED(hr))rn rn m_pBrowserApp = NULL;rn m_wndBrowser.DestroyWindow();rn DestroyWindow();rn return FALSE;rn rnrn return TRUE;rnrnrn不知道是什么原因 嵌入到其他对话框 这段代码就报错,但是自己独立运行没有问题。
在HibernateUtil类中创建SessionFactory总是失败
请问各位高手,我出现了一个令我头痛的问题:在HibernateUtil类中<em>创建</em>SessionFactory<em>总是</em><em>失败</em>:rnrnpackage com.zel.dao.hibernate;rnrnimport org.hibernate.HibernateException;rnimport org.hibernate.Session;rnimport org.hibernate.SessionFactory;rnimport org.hibernate.Transaction;rnimport org.hibernate.cfg.Configuration;rnrnpublic class HibernateUtil rn private static final SessionFactory sessionFactory;rnrn static rn try rn // Create the SessionFactoryrn sessionFactory = new Configuration().configure()rn .buildSessionFactory();rn catch (Throwable ex) rn ex.printStackTrace();rn System.out.println("Initial SessionFactory creation failed.");rn throw new ExceptionInInitializerError(ex);rn rn rnrn public static final ThreadLocal tLocalsess = new ThreadLocal();rnrn public static final ThreadLocal tLocaltx = new ThreadLocal();rnrn /*rn * getting the thread-safe session for usingrn */rn public static Session currentSession() rn Session session = (Session) tLocalsess.get();rnrn // open a new one, if none can be found.rn try rn if (session == null || !session.isOpen()) rn session = openSession();rn tLocalsess.set(session);rn rn catch (HibernateException e) rn // throw new HibernateException(e);rn e.printStackTrace();rn rn return session;rn rnrn /*rn * closing the thread-safe sessionrn */rn public static void closeSession() rnrn Session session = (Session) tLocalsess.get();rn tLocalsess.set(null);rn try rn if (session != null && session.isOpen()) rn session.close();rn rnrn catch (HibernateException e) rn // throw new InfrastructureException(e);rn rn rnrn /*rn * begin the transactionrn */rn public static void beginTransaction() rn System.out.println("begin tx");rn Transaction tx = (Transaction) tLocaltx.get();rn try rn if (tx == null) rn tx = currentSession().beginTransaction();rn tLocaltx.set(tx);rn rn catch (HibernateException e) rn // throw new InfrastructureException(e);rn rn rnrn /*rn * close the transactionrn */rn public static void commitTransaction() rn Transaction tx = (Transaction) tLocaltx.get();rn try rn if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack())rn tx.commit();rn tLocaltx.set(null);rn System.out.println("commit tx");rn catch (HibernateException e) rn // throw new InfrastructureException(e);rn rn rnrn /*rn * for rollbackingrn */rn public static void rollbackTransaction() rn Transaction tx = (Transaction) tLocaltx.get();rn try rn tLocaltx.set(null);rn if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) rn tx.rollback();rn rn catch (HibernateException e) rn // throw new InfrastructureException(e);rn rn rnrn private static Session openSession() throws HibernateException rn return getSessionFactory().openSession();rn rnrn private static SessionFactory getSessionFactory() throws HibernateException rn return sessionFactory;// SingletonSessionFactory.getInstance();rn rnrnrn在Tomcat服务器报下面的错误:rnrnrn--------------------------------------------------------------------------------rnrnrntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnjavax.servlet.ServletException: Servlet execution threw an exceptionrn rnrnroot cause rnrnjava.lang.ExceptionInInitializerError com.zel.dao.hibernate.HibernateUtil.(HibernateUtil.java:20) com.zel.dao.imp.SpecialtyDAOImp.saveSpecialty(SpecialtyDAOImp.java:83) com.zel.web.struts.action.AddSpecialtyAction.execute(AddSpecialtyAction.java:55) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:710) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn rnrnroot cause rnrnjava.lang.NoClassDefFoundError: org/aspectj/lang/Signature java.lang.Class.forName0(Native Method) java.lang.Class.forName(Class.java:169) org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:57) org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56) org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366) org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60) org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881) org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174) com.zel.dao.hibernate.HibernateUtil.(HibernateUtil.java:16) com.zel.dao.imp.SpecialtyDAOImp.saveSpecialty(SpecialtyDAOImp.java:83) com.zel.web.struts.action.AddSpecialtyAction.execute(AddSpecialtyAction.java:55) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:710) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn很急啊,请各为高手帮我解决一下?为什么啊?rn
为什么创建多个窗体总是失败
我用的是C++Builder 6 rnrn要求:前一个窗体上的按钮点击,Form2 窗体显示,Form1 消失rn 同样 Form2的按钮点击,Form1显示,Form2消失rnrn 在两个c++代码中已经包含了彼此的头文件。rn怎样做?
怎么获取协议号号???
//pprotoent是protoent结构的指针rn在pprotoent=getprotobynae();成功返回后,去获取<em>协议</em>号怎么<em>失败</em>CString str;rnchar number[10];rnsprintf(number,"%s",pprotoent->p_proto);//这句未处理的异常: 0xC0000005: 读取位置 0x00000008 时发生访问冲突rnrnstr.Format("%s",number);rn
在eclipse中创建maven总是失败
在命令提示符中运行  mvn -v  得到结果:但是紧接着运行:mvn help:system是就出现了下面的问题:C:\Users\xuweibin&amp;gt;mvn help:system[INFO] Scanning for projects...Downloading from nexus: http://192.168.10.210:8088/repository/maven-public/...
创建MySql的存储过程,总是提示失败
在学习MySqL的存储过程,如下语句:rn[code=SQL]rncreate procedure sp_name()rnbeginrnendrn[/code]rn可以正常建立rnrn但是我在begin和end之间写上任务代码时,就提示出错了,为什么呢?(先删除掉前一个建立的存储过程的,插入的语句,单独都能正常运行)rn[code=SQL]rncreate procedure sp_name()rnbeginrninsert into test values(3,3)rnendrn[/code]rnrn应该怎么写呢?我看网上的教程就这么写的,直接复制下来也出错
有人用过netlink socket中的NETLINK_GENERIC吗?
想实现一个应用程序a向其他应用程序b、c、d、e....广播消息rn使用<em>netlink</em>中的NETLINK_GENERICrnrn我在程序a中,绑定源地址addr.nl_groups = 0,目的地址addr.nl_groups =1rnrnb程序绑定源地址为addr.nl_groups = 1,可以收到a发来的消息rnrn但是接下来发现一个奇怪的现象rnrnb程序只要绑定addr.nl_groups为奇数, 就可以收到a发来的消息,为偶数,就收不到a发来的消息rnrn这是为什么呢? 我的预期是只要b绑定源地址addr.nl_groups != 1,就不该收到a发来的消息啊?
为什么在ATL中创建窗口总是失败?????
1:rnHINSTANCE hinst = _Module.GetModuleInstance();rn RECT* lpRect = new RECT;rn lpRect->left = lpRect->top = 100;rn lpRect->right=lpRect->bottom=300;rn HWND hList = ::CreateWindowEx(33, "SysListView32", NULL,rn WS_CHILD|WS_VISIBLE|LVS_REPORT, lpRect->left, lpRect->top, lpRect->right - lpRect->left,rn lpRect->bottom - lpRect->top, m_hWnd, 0,rn hinst, 0);rn DWORD dwRet = ::GetLastError();rnrn<em>创建</em><em>失败</em> dwRet = 1407rn1407 Cannot find window class. ERROR_CANNOT_FIND_WND_CLASS rnrnrnrn2:rnclass CTestDlg : public CDialogImpl,rn public CComObjectRootEx,rn public CComCoClass,rn public IDispatchImpl,rn public HttpSinkEventImplrn如上声明rntypedef CComObject CATLTestObj;rnrnHRESULT hRet = CATLTestObj::CreateInstance(&m_pTestObj);rn if(FAILED(hRet) || !m_pStockObj)rn return -1;rn m_pTestObj->AddRef();rn rn if(m_pTestObj)rn rn if(m_pTestObj->Create(m_hWnd) != NULL) <= <em>失败</em>!!!rnrn不知道为什么在ATL中<em>创建</em>窗口的东东老是<em>失败</em>,一样的代码在mfc中运行正常!!!rn请高手帮忙 谢谢!!rnrn
求教监听netlink socket消息的问题
<em>netlink</em> <em>socket</em>是<em>内核</em>与用户空间通信的一种方式,其中<em>netlink</em>内定义了许多不同的<em>协议</em>类型,比如NETLINK-XFRM。rn我现在需要来监听用户空间的进程和<em>内核</em>之间的通信,它们之间是通过<em>netlink</em> <em>socket</em>的NETLINK-XFRM<em>协议</em>来通信的。rn 以前做过监听本机某一端口的程序,也就是将网卡设为混杂模式,然后启一<em>socket</em>监听端口值为多少的数据包等等,但是对于如何监听<em>内核</em>和用户空间通信我完全不懂啊!所以请教大家了,谢谢大家的指教
Unconnected sockets not implemented 创建Socket失败
工程环境jdk 1.6.0_1.0,为了支持tls1.2,有TLSSocketConnectionFactory <em>协议</em>工厂类rnrn具体代码如下:rnprivate static String InitPartUploade(Map tmpMap) throws ClientProtocolException, IOException rn HttpsURLConnection httpurlconnection = createHttpsSSLDefault(tmpMap.get("url"), "POST");rn httpurlconnection.setRequestProperty("Host", tmpMap.get("host"));rn httpurlconnection.connect();rnrn System.out.println("-------------------InitPartUploade---------------------");rn int code = httpurlconnection.getResponseCode();rn System.out.println("-------------------"+code+"---------------------");rn if (code == 200) rn String data = IOUtils.toString(httpurlconnection.getInputStream(), "UTF-8");rn System.out.println(data);rn Document document;rn try rn document = DocumentHelper.parseText(data);rn catch (DocumentException e) rn return "";rn rn Element element = document.getRootElement();rn if (element != null) rn Element eUploadId = element.element("UploadId");rn String uploadId = eUploadId.getStringValue();rn return uploadId;rn rn return "";rn else rn return "";rn rn rnrn报错信息如下:rnException in thread "main" java.net.SocketException: Unconnected <em>socket</em>s not implementedrn at javax.net.SocketFactory.createSocket(SocketFactory.java:97)rn at sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:360)rn at sun.net.NetworkClient.doConnect(NetworkClient.java:145)rn at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)rn at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)rn at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:271)rn at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:328)rn at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)rn at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:731)rn at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)rn at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)rn at com.demo.InsurerTask.InitPartUploade(InsurerTask.java:466)rn at com.demo.InsurerTask.fileUpload(InsurerTask.java:378)rn at com.demo.InsurerTask.UploadTask(InsurerTask.java:125)rn at com.demo.InsurerTask.main(InsurerTask.java:67)rnrn跟代码进去,显示是rn public Socket createSocket()rn throws IOExceptionrn rn throw new SocketException("Unconnected <em>socket</em>s not implemented");rn rn报错,抛的异常,求解。。。rnrn生产JDK版本就是1.6,暂时还改不了。rnrnrnrn
创建Socket 失败,请高手指点!
CClientSocket m_<em>socket</em>;rnm_<em>socket</em>.Create();rnrn各位大哥,怎么我<em>创建</em>Socket就是不成功呢,请高手指点!不胜感激rnrn
Solaris10 for X86下创建SOCKET失败,为什么?
在Solaris10 for X86下<em>创建</em><em>socket</em>(sasend->sa_family, SOCK_RAW, IPPROTO_ICMP);其中sasend->sa_family的值为2。但是运行时,<em>socket</em>报错:Permission denied。我的用户是超级用户,并且可以做ping和traceroute的操作。rn请问各位大虾,<em>socket</em><em>失败</em>是什么原因呢?
Socket显示创建套接字失败。求解!
[code=C/C++]void CClientDlg::OnCconnect() rn rnrn// UpdateData(true);rn// m_CleintSocket.Create();rn //CString cStr;rn //const char *LPCTSTR=(LPCTSTR)cStr;rn// if(m_CleintSocket.Connect(m_striptext,m_porttext)) //点击连接后,把IP和端口号发送给服务器rn // MessageBox("连接服务器成功!");rn //else rn // MessageBox("连接服务器<em>失败</em>!");rn //判断是否输入了IP地址或端口号rn //设置按钮的可按型rn GetDlgItem(IDC_CCONNECT)->EnableWindow(FALSE); //点击之后就不能再点击了rn //<em>创建</em>套接字rn m_<em>socket</em>=new CSocket();rn if (!m_<em>socket</em>->Create())rn rn GetDlgItem(IDC_CCONNECT)->EnableWindow(TRUE);rn MessageBox("<em>创建</em>套接字<em>失败</em>!");rn //return;rn rn //判断从IP框获取的IP地址rn GetDlgItem(IDC_IP)->GetWindowText(m_strIP);rn MessageBox(m_strIP);rn if(!m_<em>socket</em>->Connect(m_strIP,m_strport))rn rn CString ipport;rn ipport.Format("%d",m_strport);rn MessageBox(ipport);rn GetDlgItem(IDC_CCONNECT)->EnableWindow(TRUE);rn // MessageBox(WSAGetLastError);rn MessageBox("连接<em>失败</em>!");rn return;rn rn elsern rn MessageBox("连接服务器成功!");rn rnrnrnrn[/code]Connect 是我设置的一个按钮,m_strIP,m_strport,在Clientdlg里面我都定义了,而且初始化了,调试后,获取的数据都正确,可是就是出现<em>创建</em>套接字<em>失败</em>,不知道是不是端口占用?求帮助,谢谢
为什么我的socket套接字老是创建失败
以下是我的源程序,一个简单的服务器端程序,rn可最后结果老是显示“<em>socket</em> error!”rn请各位大虾帮忙解答!rnrn#include rn#include rn#define USERPORT 12000rnrnvoid main(void)rnrn int sock; rn struct sockaddr_in server, client;rn int msgsock;rn char buf[1024];rn int rval, len;rnrn /* 建立套接字 */rn sock = <em>socket</em>(AF_INET, SOCK_STREAM, 0);rn if (sock == INVALID_SOCKET) rn rn printf("<em>socket</em> error!\n");rn exit(1);rn rnrn server.sin_family = AF_INET;rn server.sin_port = htons(USERPORT);rn server.sin_addr.s_addr = INADDR_ANY;rn if (bind(sock, (struct sockaddr *)&server, sizeof(server)) < 0) rn rn printf("bind error!\n");rn exit(1);rn rnrn /* 开始接收连接 */rn listen(sock, 5);rn len = sizeof(struct sockaddr);rn do rn rn msgsock = accept(sock, (struct sockaddr *)&client, (int *)&len);rn if (msgsock == -1)rn printf("accept error!\n");rn else dorn rn memset(buf, 0, sizeof(buf));rn if ((rval = recv(msgsock, buf, 1024, 0)) < 0)rn printf("receive error!\n");rn if (rval == 0)rn printf("ending connection \n");rn elsern printf("%s\n", buf);rn while (rval != 0);rn close<em>socket</em>(msgsock);rn while (1);rn rn exit(0);rnrn
socket在服务端的创建失败,帮帮忙!!!
在一个文档/视图结构里,我在文档类的OnNewDocument函数里建立SOCKET的建立,监听如下:rnBOOL CopenexesevDoc::OnNewDocument()rnrn if (!CRichEditDoc::OnNewDocument())rn return FALSE;rnrn // TODO:在此添加重新初始化代码rn // (SDI 文档将重用该文档)rn //--------------------------------------------------rn m_pSocket = new CSocket();rn if (m_pSocket->Create(1234))rn if (m_pSocket->Listen())rn return TRUE;rn rn elsern AfxMessageBox("fail to create!",MB_OK);rn //--------------------------------------------------rn return TRUE;rnrn但运行后发现<em>创建</em><em>失败</em>,Create(1234)返回的是0值,把端口号改一个数字,还是<em>失败</em>,不知道为什么?
求助 在子线程中创建socket失败
rn我用_beginthread创子线程,在子线程的最开始<em>创建</em><em>socket</em>,结果<em>失败</em>,错误出在无法将域名转换为IP地址,感觉很荒唐rn当我把<em>创建</em><em>socket</em>的语句挪到_beginthread之前,一切就正常了rn实在不行我就只能在主进程<em>创建</em>,然后传过去了rn可是我不知道到底为什么会有这种情况
socket创建失败,不清楚问题在哪?
m_hSocket = <em>socket</em>(AF_INET, SOCK_STREAM, IPPROTO_TCP);rnrn if (m_hSocket == INVALID_SOCKET)rn rn TRACE("Could not create <em>socket</em> %ld\n",WSAGetLastError());rn return FALSE;rn rnrn跟踪时m_hSocket<em>失败</em>rntrace :Could not create <em>socket</em> %ld rn 67 'C'rn请高手指点!
Cute ftp创建socket失败的原因?
我打开IE浏览器输入ftp:\\172.16.31.*,就可以链接到ftp的根目录;但是我用cute ftp链接的时出现<em>创建</em><em>socket</em><em>失败</em>,是什么原因?
创建socket时的协议参数的疑问~~~
SOCKET <em>socket</em>( int af, int type, int protocol );中, protocol参数是这个<em>socket</em>所用的<em>协议</em>.rn我所理解这个参数的意思是: 你的数据是基于这个<em>协议</em>的( 比如:TCP,那么我发送的数据的TCP头不用你构造,接收到的数据也不包含TCP头,<em>内核</em>已经帮你去掉了).rnrn但最近看到的程序与我的理解不同.比如这个从网上找到的ping程序:rnsock = <em>socket</em>(AF_INET, SOCK_RAW, IPPROTO_ICMP);rn它用原始套接字,发送数据时不用自已写IP头,但要自已填ICMP头,当收到数据时,能收到IP头!当然也能收到ICMP头!rnrn晕死,搞到我都弄不同白这个 protocol参数是搞什么的,MSDN也只有这句 "Protocol to be used with the <em>socket</em> that is specific to the indicated address family. "rnrn请大牛指点~~~这个protocol的真正用意是什么~rn
socket创建失败,WSAGetLastError返回0
<em>socket</em><em>创建</em><em>失败</em>,WSAGetLastError返回0,偶尔会出现这样正常吗?rnrn[code=C/C++]rnDWORD _stdcall thread(LPVOID lp)rnrn SOCKET _<em>socket</em>;rn _<em>socket</em> = <em>socket</em>(AF_INET, SOCK_STREAM, IPPROTO_TCP);rnrnrn if (SOCKET_ERROR == _<em>socket</em>)rn rn char tmp[55];rn sprintf(tmp, "<em>socket</em><em>创建</em><em>失败</em>,原因:%d", WSAGetLastError());rn OutputDebugString(tmp);rn Sleep(2000);rn return SOCKET_ERROR;rn rnrn sockaddr_in clientAddr;rn memset(&clientAddr, 0, sizeof(clientAddr));rn clientAddr.sin_family = AF_INET;rn clientAddr.sin_addr.s_addr = inet_addr("111.178.146.10");rn clientAddr.sin_port = ::htons(u_short(2001));rn rn rnrn int iMode = 1;rn ioctl<em>socket</em>(_<em>socket</em>,FIONBIO, (u_long FAR*) &iMode);rn FD_SET WriteSet;rn timeval timeout;rn timeout.tv_sec = 2; // 检测时间2秒rn timeout.tv_usec = 0;rn char error;rn int len = sizeof(char);rnrn BOOL bReuseaddr=TRUE;rn setsockopt(_<em>socket</em>,SOL_SOCKET ,SO_REUSEADDR,(const char*)&bReuseaddr,sizeof(BOOL));rnrn if ( 0 != connect(_<em>socket</em>, (SOCKADDR*)&clientAddr, sizeof(clientAddr)) )rn rn FD_ZERO(&WriteSet);rn FD_SET(_<em>socket</em>, &WriteSet);rn if ( select(0, NULL, &WriteSet, NULL, &timeout) > 0 )rn rn getsockopt(_<em>socket</em>, SOL_SOCKET, SO_ERROR, &error, &len);rn if (error != 0)rn rn char tmp[55];rn sprintf(tmp, "<em>socket</em><em>创建</em><em>失败</em>,原因:%d", WSAGetLastError());rn OutputDebugString(tmp);rnrn close<em>socket</em>(_<em>socket</em>);rn return SOCKET_ERROR;rn rn rn else rn rn char tmp[55];rn sprintf(tmp, "<em>socket</em><em>创建</em><em>失败</em>,原因:%d", WSAGetLastError());rn OutputDebugString(tmp);rnrn close<em>socket</em>(_<em>socket</em>);rn return SOCKET_ERROR;rn rn rnrn OutputDebugString("连接成功");rnrn Sleep(100000000);rn return 0;rnrnrnrnvoid CConnectDlg::OnOK() rnrn WSADATA m_wsaD;rn if ( 0 != WSAStartup(0x202,&m_wsaD) ) rn rn ::MessageBox(0, "初始化WSA<em>失败</em>!", 0, 0);rn rnrn for (int i = 0; i < 1000; i++)rn rn CreateThread(0, 0, thread, 0, 0, 0);rn Sleep(100);rn rn[/code]rnrnrnrn打印信息:rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] <em>socket</em><em>创建</em><em>失败</em>,原因:0 rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rn[2216] 连接成功rnrnrn偶尔出现一个<em>socket</em>返回<em>失败</em>正常吗? 是不是<em>创建</em>的太快原因?
Socket协议
Socket<em>协议</em>的形象描述 <em>socket</em>的英文原义是“孔”或“插座”。在这里作为4BDS UNIX的进程通信机制,取后一种意思。<em>socket</em>非常类似于电话插座。以一个国家级电话网为例。电话的通话双方相当于相互通信的2个进程,区号是它的网络地址;区内一个单位的交换机相当于一台主机,主机分配给每个用户的局内号码相当于<em>socket</em>号。任何用户在通话之前,首先要占有一部电话机,相当于申请一个<em>socket</em>...
socketsocket介绍-socket深入内核解析
之前有篇文章讲解了<em>socket</em>服务开发模式: 1、阻塞式-每次只接受一个请求,处理结束才接受下一个请求; 2、多进程-每次请求来了启动一个进程或者线程,来处理该请求; 3、IO复用模式-主要包括select模式、epoll模式 这篇文章就主要通过深入<em>内核</em>,讲述操作系统在<em>创建</em><em>socket</em>、接受和处理请求的时候究竟进行了哪些操作。
传奇号总是被盗
能告诉我现在盗传奇密码有几种方法吗?rnrn如果防呢???
Linux Socket TCP协议的7个关键函数
Socket(套接字)是网络进程之间进行通信的工具,它的主要函数是以下7个: int <em>socket</em>(int domain, int type, int protocol); //<em>创建</em>Socket,有点像fopen()函数,返回值是一个int型描述字。这个描述字会被后面的函数用到。 domain代表<em>协议</em>族,常用的有AF_INET(IPV4)、AF_INET6(IPV6)。这些参数在<em>linux</em>
linuxsocket里如何使用http协议
我需要做一个这样的clientrn使用http<em>协议</em>来想server端发送一个数据包rn不知<em>linux</em>的<em>socket</em>是怎么使用http<em>协议</em>的
使用linux socket的基本的FTP协议实现
使用<em>linux</em> <em>socket</em>实现的一个基本的FTP<em>协议</em>,采用被动传输模式。
TextSearch 1.3下载
程序名:TextSearch 运行环境:Windows XP 以上 主要目的:在text编码(Unicode, UTF, ANSI, ASCII等等)的文件内,查找某一字段(多国语言支持)。 主要功能: 1. 支持中英文的界面显示 2. 自定义所要查找的文件类型 3. 自定义不需要搜索的文件夹 4. 可包含子文件夹 5. 有“全部匹配”和部分匹配两种查找模式 6. 显示进度条,及正在扫描文件 7. 结果显示在主窗口并写入记录文件 使用:基本一看就知道。编码选择一般选Default就可以了;其他的编码格式在搜索一些特定文件的时候使用。 TextSearch 1.3 更新日志: 解决程序假死 相关下载链接:[url=//download.csdn.net/download/abcd_xyz/2779389?utm_source=bbsseo]//download.csdn.net/download/abcd_xyz/2779389?utm_source=bbsseo[/url]
2011北邮计算机复试下载
2011北邮计算机复试 相关下载链接:[url=//download.csdn.net/download/sunshinelx/4308140?utm_source=bbsseo]//download.csdn.net/download/sunshinelx/4308140?utm_source=bbsseo[/url]
视高协同视频会议系统\V3.0解决方案下载
视高协同视频会议系统\V3.0解决方案 相关下载链接:[url=//download.csdn.net/download/xiaoling960/4478018?utm_source=bbsseo]//download.csdn.net/download/xiaoling960/4478018?utm_source=bbsseo[/url]
相关热词 c# stream 复制 android c# c#监测窗口句柄 c# md5 引用 c# 判断tabtip 自己写个浏览器程序c# c# 字符串变成整数数组 c#语言编程写出一个方法 c# 转盘抽奖 c#选中treeview
我们是很有底线的