linux c 获取本地MAC地址
摘要:#include <stdio.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <netinet/in.h> #include <net/if.h> #include <string.h> int main(int argc, char *argv[]) { struct ifreq ifreq; int sock; if(argc!=2) { printf( "Usage : ethname\n "); ...
阅读全文
posted @
2012-05-10 10:15
吃吃户
阅读(10372)
推荐(0)
recv返回值
摘要:返回值为n1.n>0,正常读取n个字节2.n==0,socket对方节点正常shutdown3.n==-1,未能正常读取数据,有以下几种情况,errno被置为以下几种:EAGAIN or EWOULDBLOCK The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.这种情况要注意,前者是非阻塞方式下的一种正常返回,后者是超时的返回情况。
阅读全文
posted @
2011-12-09 16:57
吃吃户
阅读(5109)
推荐(0)
select,epoll,poll比较(网络资源总结)
摘要:转自:http://www.cnblogs.com/aga-j/archive/2011/08/26/2153943.htmlselect,poll,epoll简介selectselect本质上是通过设置或者检查存放fd标志位的数据结构来进行下一步处理。这样所带来的缺点是:1 单个进程可监视的fd数量被限制2 需要维护一个用来存放大量fd的数据结构,这样会使得用户空间和内核空间在传递该结构时复制开销大3 对socket进行扫描时是线性扫描pollpoll本质上和select没有区别,它将用户传入的数组拷贝到内核空间,然后查询每个fd对应的设备状态,如果设备就绪则在设备等待队列中加入一项并继续遍
阅读全文
posted @
2011-11-23 09:54
吃吃户
阅读(996)
推荐(0)
五种I/O模型
摘要:步骤1:等待数据到达网络,当分组到达时,它被拷贝到内核中某个缓冲区步骤2:将数据从内核缓冲区拷贝到应用缓冲区1.阻塞I/O 2.非阻塞I/O3.I/O复用4.信号驱动5.异步I/O综合
阅读全文
posted @
2011-11-21 21:45
吃吃户
阅读(257)
推荐(0)