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

linux sock_rawԭʼÌ×½Ó×Ö±à³Ì

sock_rawԭʼÌ×½Ó×Ö±à³Ì¿ÉÒÔ½ÓÊÕµ½±¾»úÍø¿¨ÉϵÄÊý¾ÝÖ¡»òÕßÊý¾Ý°ü,¶ÔÓë¼àÌýÍøÂçµÄÁ÷Á¿ºÍ·ÖÎöÊǺÜÓÐ×÷ÓõÄ.Ò»¹²¿ÉÒÔÓÐ3ÖÖ·½Ê½´´½¨ÕâÖÖsocket
 
1.socket(AF_INET, SOCK_RAW, IPPROTO_TCP|IPPROTO_UDP|IPPROTO_ICMP)·¢ËͽÓÊÕipÊý¾Ý°ü
2.socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP|ETH_P_ARP|ETH_P_ALL))·¢ËͽÓÊÕÒÔÌ«ÍøÊý¾ÝÖ¡
3.socket(AF_INET, SOCK_PACKET, htons(ETH_P_IP|ETH_P_ARP|ETH_P_ALL))¹ýʱÁË,²»ÒªÓð¡
 
Àí½âÒ»ÏÂSOCK_RAWµÄÔ­Àí, ±ÈÈçÍø¿¨ÊÕµ½ÁËÒ»¸ö 14+20+8+100+4 µÄudpµÄÒÔÌ«ÍøÊý¾ÝÖ¡.
 
Ê×ÏÈ,Íø¿¨¶Ô¸ÃÊý¾ÝÖ¡½øÐÐÓ²¹ýÂË(¸ù¾ÝÍø¿¨µÄģʽ²»Í¬»áÓв»Í¬µÄ¶¯×÷,Èç¹ûÉèÖÃÁËpromisc»ìÔÓģʽµÄ»°,Ôò²»×öÈκιýÂËÖ±½Ó½»¸øÏÂÒ»²ãÊäÈëÀý³Ì,·ñÔò·Ç±¾»úmac»òÕ߹㲥mac»á±»Ö±½Ó¶ªÆú).°´ÕÕÉÏÃæµÄÀý×Ó,Èç¹û³É¹¦µÄ»°,»á½øÈëipÊäÈëÀý³Ì.µ«ÊÇÔÚ½øÈëipÊäÈëÀý³Ì֮ǰ,ϵͳ»á¼ì²éϵͳÖÐÊÇ·ñÓÐͨ¹ýsocket(AF_PACKET, SOCK_RAW, ..)´´½¨µÄÌ×½Ó×Ö.Èç¹ûÓеĻ°²¢ÇÒЭÒéÏà·û,ÔÚÕâ¸öÀý×ÓÖоÍÊÇÐèÒªETH_P_IP»òÕßETH_P_ALLÀàÐÍ.ϵͳ¾Í¸øÿ¸öÕâÑùµÄsocket½ÓÊÕ»º³åÇø·¢ËÍÒ»¸öÊý¾ÝÖ¡¿½±´.È»ºó½øÈëÏÂÒ»²½.
 
Æä´Î,½øÈëÁËipÊäÈëÀý³Ì(ip²ã»á¶Ô¸ÃÊý¾Ý°ü½øÐÐÈí¹ýÂË,¾ÍÊǼì²éУÑé»òÕ߶ªÆú·Ç±¾»úip»òÕ߹㲥ipµÄÊý¾Ý°üµÈ,¾ßÌåÒª²Î¿¼Ô´´úÂë),Àý×ÓÖоÍÊÇÈç¹û³É¹¦µÄ»°»á½øÈëudpÊäÈëÀý³Ì.µ«ÊÇÔÚ½»¸øudpÊäÈëÀý³Ì֮ǰ,ϵͳ»á¼ì²éϵͳÖÐÊÇ·ñÓÐͨ¹ýsocket(AF_INET, SOCK_RAW, ..)´´½¨µÄÌ×½Ó×Ö.Èç¹ûÓеĻ°²¢ÇÒЭÒéÏà·û,ÔÚÕâ¸öÀý×ÓÖоÍÊÇÐèÒªIPPROTO_UDPÀàÐÍ.ϵͳ¾Í¸øÿ¸öÕâÑùµÄsocket½ÓÊÕ»º³åÇø·¢ËÍÒ»¸öÊý¾ÝÖ¡¿½±´.È»ºó½øÈëÏÂÒ»²½.
 
×îºó,½øÈëudpÊäÈëÀý³Ì ...
 
ps:Èç¹ûУÑéºÍ³ö´íµÄ»°,Äں˻áÖ±½Ó¶ªÆú¸ÃÊý¾Ý°üµÄ.¶ø²»»á¿½±´¸øsock_rawµÄÌ×½Ó×Ö,ÒòΪУÑéºÍ¶¼³ö´íÁË,Êý¾Ý¿Ï¶¨ÓÐÎÊÌâµÄ°üÀ¨ËùÓÐÐÅÏ¢¶¼Ã»ÓÐÒâÒåÁË.
 
½øÒ»²½·ÖÎöËûÃǵÄÄÜÁ¦.
1. socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
ÄÜ:¸ÃÌ×½Ó×Ö¿ÉÒÔ½ÓÊÕЭÒéÀàÐÍΪ(tcp udp icmpµÈ)·¢Íù±¾»úµÄipÊý¾Ý°ü,´ÓÉÏÃæ¿´µÄ¾ÍÊÇ20+8+100.
²»ÄÜ:²»ÄÜÊÕµ½·Ç·¢Íù±¾µØipµÄÊý¾Ý°ü(ipÈí¹ýÂ˻ᶪÆúÕâЩ²»ÊÇ·¢Íù±¾»úipµÄÊý¾Ý°ü).
²»ÄÜ:²»ÄÜÊÕµ½´Ó±¾»ú·¢ËͳöÈ¥µÄÊý¾Ý°ü.
·¢Ë͵Ļ°ÐèÒª×Ô¼º×éÖ¯tcp udp icmpµÈÍ·²¿.¿ÉÒÔsetsockoptÀ´×Ô¼º°ü×°ipÍ·²¿
ÕâÖÖÌ×½Ó×ÖÓÃÀ´Ð´¸öping³ÌÐò±È½ÏÊʺÏ
     
2. socket(PF_PACKET, SOCK_RAW, htons(x)); 
Õâ¸öÌ×½Ó×ֱȽÏÇ¿´ó,´´½¨ÕâÖÖÌ


Ïà¹ØÎĵµ£º

ʵսLinux Bluetooth±à³Ì£¨Èý£© HCI²ã±à³Ì

1. HCI²ãЭÒé¸ÅÊö£º
HCIÌṩһÌ×ͳһµÄ·½·¨À´·ÃÎÊBluetoothµ×²ã¡£ÈçͼËùʾ£º
´ÓͼÉÏ¿ÉÒÔ¿´³ö£¬Host Controller Interface(HCI)  ¾ÍÊÇÓÃÀ´¹µÍ¨HostºÍModule¡£Hostͨ³£¾ÍÊÇPC£¬ ModuleÔòÊÇÒÔ¸÷ÖÖÎïÀíÁ¬½ÓÐÎʽ£¨USB,serial,pc-cardµÈ£©Á¬½Óµ½PCÉϵÄbluetooth Dongle¡£
ÔÚHostÕâÒ»¶Ë£ºapplication,SDP,L2capµÈЭÒé ......

ʵսLinux Bluetooth±à³Ì£¨ËÄ£© L2CAP²ã±à³Ì

£¨L2CAPЭÒé¼ò½é£¬L2CAPÔÚBlueZÖеÄʵÏÖÒÔ¼°L2CAP±à³Ì½Ó¿Ú£©
Ò»£ºL2CAPЭÒé¼ò½é£º
Logical Link Control and Adaptation Protocol(L2CAP)
Âß¼­Á¬½Ó¿ØÖƺÍÊÊÅäЭÒé (L2CAP) ΪÉϲãЭÒéÌṩÃæÏòÁ¬½ÓºÍÎÞÁ¬½ÓµÄÊý¾Ý·þÎñ£¬²¢Ìṩ¶àЭÒ鹦ÄܺͷָîÖØ×é²Ù×÷¡£L2CAP ³äÐíÉϲãЭÒéºÍÓ¦ÓÃÈí¼þ´«ÊäºÍ½ÓÊÕ×î´ó³¤¶ÈΪ 64K µÄ L2CAP Ê ......

ʵսLinux Bluetooth±à³Ì (Æß) SDPЭÒé

Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖЭÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀЭÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......

Linux ½Å±¾±àд»ù´¡(Ò»)

1.1 Óï·¨»ù±¾½éÉÜ
1.1.1 ¿ªÍ·
³ÌÐò±ØÐëÒÔÏÂÃæµÄÐпªÊ¼£¨±ØÐë·½ÔÚÎļþµÄµÚÒ»ÐУ©£º
#!/bin/sh
·ûºÅ#!ÓÃÀ´¸æËßϵͳËüºóÃæµÄ²ÎÊýÊÇÓÃÀ´Ö´ÐиÃÎļþµÄ³ÌÐò¡£ÔÚÕâ¸öÀý×ÓÖÐÎÒÃÇʹÓÃ/bin/shÀ´Ö´ÐгÌÐò¡£
µ±±à¼­ºÃ½Å±¾Ê±£¬Èç¹ûÒªÖ´Ðиýű¾£¬»¹±ØÐëʹÆä¿ÉÖ´ÐС£
Ҫʹ½Å±¾¿ÉÖ´ÐУº
±àÒë chmod +x filename ÕâÑù²ÅÄÜÓÃ./filena ......

linuxʵÓÃÃüÁîÊÕ¼¯

½ø³Ìƪ
²é¿´Ä³½ø³Ì¶Ë¿ÚºÅ
netstat -anp | grep 80
lsof -i :port
Àý£º  ×¢Òâ":"ºó£¬½ô¸ú¶Ë¿ÚºÅ£¬Ã»Óпոñ
#lsof -i :443
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
java    2731 root   35u  IPv6   7778       TCP *:https (LI ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ