Linux·¢ËÍarpÇëÇóÓë½ÓÊÕarpÏìÓ¦
Linux ÖлñµÃ±¾»úÍø¿¨MACµØÖ·ºÜ¼òµ¥£¬ioctl()¾ÍOK¡£¿ÉÈçºÎ»ñµÃ¾ÖÓòÍøÆäËûÖ÷»úµÄMACµØÖ·ÄØ…Á´Â·²ã¹ã²¥ARPÇëÇó£¬È»ºó½ÓÊÕARPÏìÓ¦¡£ÊµÏÖ½é¸ö¹¦ÄÜÆäʵÒÑÓÐÏÖ³ÉÈý·½¿â¿ÉÓã¬Èçlibnet¡£²»¹ýÏë¼ÓÉî¶ÔÐÒéµÄÀí½âºÍLinuxÍøÂç±à³ÌAPIµÄÀí½â£¬jiayi »¹ÊǾö¶¨ÓÃLinuxµÄPF_PACKET×Ô¼ºÊµÏÖ£¬¸Ä°¡¸Ä£¬ÖÕÓڳɹ¦¡«ÒÔÏÂÊÇ´óÌå˼·
1. ΪÊý¾Ý±¨·ÖÅä¿Õ¼ä£¬´´½¨ÏàÓ¦µÄ½á¹¹Ìå req£¬arp Êý¾Ý±¨µÄÖ¡¸ñʽÈçͼ
2. ´´½¨ PF_PACKET ÔʼÌ×½Ó×Ö£¬·¢ËÍÌ×½Ó×ÖΪ reqfd£¬½ÓÊÕÌ×½Ó×ÖΪ recvfd
3. ÌîдÁ´Â·²ãͨÓýṹÌå reqsa
3. get_ifi()»ñÈ¡±¾»úÍøÂç½Ó¿ÚÊý¾Ý£¬ÌîдҪ·¢Ë͵ÄARPÊý¾Ý±¨ req ½á¹¹Ì壬sendto()·¢ËÍ
4. Ñ»·recvfrom()½ÓÊÕARPÏìÓ¦£¬Â˵ô¾Óɱ¾µØ½Ó¿ÚµÄÆäËûARPÊý¾Ý±¨
·¢ËÍARPÇëÇóÄÜ×öµÄʲ»½ö½ö»ñÈ¡MACµØÖ·°É…ÆäËû“ÓÐÒâÒ唵ÄÊÂÒ²¿ÉÒÔ³¢ÊÔÒ»ÏÂÏÂ……ÏÂÃæÊÇ´úÂë
C code
/**
* @send_arp.c
* @This software is intended to be used as a example to show how to send and receive arp request with Linux * PF_PACKET interface
* @Author£ºjiayi,http://www.jiayii.com
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <sys/types.h>
#include <asm/types.h>
#include <features.h> /* ÐèÒªÀïÃæµÄ glibc °æ±¾ºÅ */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h> /* Á´Â·²ã£¨L2£©ÐÒé */
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h> /* Á´Â·²ãÐÒé */
#endif
#include <netinet/if_ether.h>
#define INLEN 4
#define MAC_BCAST_ADDR (uint8_t *) "\xff\xff\xff\xff\xff\xff"
void usage_quit(char *arg0);
int get_ifi(char *
Ïà¹ØÎĵµ£º
1) ʹÓõĿⲻͬ¡£windowsÏÂͼÐοª·¢Ò»°ãÓÃ΢ÈíµÄMFC»ò.net¿â£¬¶øLinuxÏÂÔò³£ÓÃqt¿â¡£C/C++ͨÓÿ⣨c¿â£¬STL¿â£©µÄ½Ó¿ÚÏàͬ£¬µ«ÄÚ²¿ÊµÏÖ²»Í¬¡£
2) ±àÒëÆ÷²»Í¬¡£windowsÏÂÓõÄÊÇ΢Èí±àÒëÆ÷VC»ò.net£¬¶øLinuxÏÂÔòÓÃgcc¡£
3) ¿ª·¢»·¾³²»Í¬¡£windowsµÄ±àÒëÆ÷×Ô¶¯Éú³Émakefile£¬¶øLinuxÔòÐèÒªÊÖ¶¯±àдmakefil ......
¡¡¡¡Õâ¶Îʱ¼äÀÏÅöµ½ÓÐÈËÎʼ°¸÷¸öLinux°æ±¾µÄ±¾µØrootÃÜÂëÆƽⷽ·¨£¬ÎÒÕâÀï×Ô¼ºÒÔ¼°ÔÚÍøÂçÉÏËѼ¯ÁËЩ×ÊÁÏ£¬Ï£Íû¶Ô¿´µ½ÁËÕâÎÄÕ¶øÓÖÇ¡ºÃÓõõ½µÄ¼¼ÊõÈËÔ±Óеã°ïÖú£º
(Ò»)RedHat/CentOS/Fedora ϵͳÃÜÂëÆƽâ
¡¡¡¡1.ÔÚgrubÑ¡Ïî²Ëµ¥°´E½øÈë±à¼Ä£Ê½
¡¡¡¡2.±à¼kernel ÄÇÐÐ×îºó¼ÓÉÏ¿Õ¸ñS (»òÕß¿Õ¸ñSingle)
¡¡¡¡3.°´B£¬Æô¶¯µ ......
/* Offtimer.c.For auto halt. */
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#define DELAY 60/* Time of sleeping */
int main()
{
time_t now;
struct tm *p;
while(1)
{
now = time(NULL);
&n ......
±¾ÎÄÖ÷Òª½éÉÜÈçºÎÓÃLinux×öÒ»¸ö¹¦ÄÜÍ걸µÄ·ÓÉÆ÷£¬ÕâÀォÖ÷Òª½éÉܾ²Ì¬Â·ÓÉÆ÷ºÍ¶¯Ì¬Â·ÓÉÆ÷µÄÅäÖ㬵«²»°üÀ¨IPαװ»òÕß˵¹«ÓÃÒ»¸öIPµØÖ··ÃÎÊÍâÃæÍøÂçµÈÎÊÌâ¡£ÆäÒѾ²»ÊôÓÚ±¾Ö÷ÌâÌÖÂ۵ķ¶Î§£¬Çë²Î¿¼ÆäËûÈç·À»ðǽµÄÅäÖõȵÄÄÚÈÝ¡£
LRP(Linux Router Project)ÒѾ³ÉÁ¢ÁËÓкü¸ÄêµÄʱ¼äÁË¡£Õâ¸ö¼Æ»®µÄÄ¿µÄÊÇÀûÓÃLinux²Ù×÷ϵͳ½«À ......
Index: flash.c
===================================================================
--- flash.c (revision 1804)
+++ flash.c (working copy)
@@ -26,6 +26,8 @@
#include "ebootnand.h"
#include "ll_nand.h"
#includ ......