Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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 *


Ïà¹ØÎĵµ£º

linuxÄں˺¯Êý±Ê¼Ç(¶þ)

ÐźÅÖ¸¶¨´¦Àíº¯Êý
void (*signal (int signum,void (*handle)(int)))(int);ÉèÖÃij¸öÐźŵĴ¦Àí·½·¨
int sigaction(int signum,const struct sigaction *act,struct sigaction *oldact);ÓÃÓÚ¼ì²é»ò¸Ä±ä½ø³ÌÔÚ½Óµ½ÐźÅʱµÄ¶¯×÷
Ðźż¯²Ù×÷º¯Êý
static inline void sigaddset(sigset_t *set,int _sig);
static inline voi ......

Linux tty/pty/pts ¸ÅÄîÇø±ð

tty0£­6ÊÇlinux±¾µØÖÕ¶Ë£¬pts/xÊÇÔ¶³ÌµÇ½ÐèÒªµÄÖÕ¶Ë£¬±ÈÈçijÈËÒªtelnetµ½ÄãµÄ»ú×Ó£¬¾ÍÐèÒªÄãµÄϵͳÓÐpts/x¡£ 
»ù±¾¸ÅÄ
¡¡
¡¡1. tty(ÖÕ¶ËÉ豸µÄͳ³Æ):
¡¡¡¡ttyÒ»´ÊÔ´ÓÚTeletypes£¬»òÕßteletypewriters£¬Ô­À´Ö¸µÄÊǵ紫´ò×Ö»ú£¬ÊÇͨ¹ý´®ÐÐÏßÓôòÓ¡»ú¼üÅÌͨ¹ýÔĶÁºÍ·¢ËÍÐÅÏ¢µÄ¶«Î÷£¬ºóÀ´Õâ¶«Î÷±»¼üÅÌÓëÏÔʾÆ÷È¡´ú ......

4.1. Introduction to Linux Routing


4.1. Introduction to Linux Routing
The design of IP routing allows for very simple route definitions for small networks, while not hindering the flexibility of routing in complex environments. A key concept in IP routing is the ability to define what addresses are locally reachable as oppose ......

linuxÏÂcÓïÑԹػú³ÌÐò

/* 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×öÒ»¸ö¹¦ÄÜÍ걸µÄ·ÓÉÆ÷

±¾ÎÄÖ÷Òª½éÉÜÈçºÎÓÃLinux×öÒ»¸ö¹¦ÄÜÍ걸µÄ·ÓÉÆ÷£¬ÕâÀォÖ÷Òª½éÉܾ²Ì¬Â·ÓÉÆ÷ºÍ¶¯Ì¬Â·ÓÉÆ÷µÄÅäÖ㬵«²»°üÀ¨IPαװ»òÕß˵¹«ÓÃÒ»¸öIPµØÖ··ÃÎÊÍâÃæÍøÂçµÈÎÊÌâ¡£ÆäÒѾ­²»ÊôÓÚ±¾Ö÷ÌâÌÖÂ۵ķ¶Î§£¬Çë²Î¿¼ÆäËûÈç·À»ðǽµÄÅäÖõȵÄÄÚÈÝ¡£
LRP(Linux Router Project)ÒѾ­³ÉÁ¢ÁËÓкü¸ÄêµÄʱ¼äÁË¡£Õâ¸ö¼Æ»®µÄÄ¿µÄÊÇÀûÓÃLinux²Ù×÷ϵͳ½«À ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ