Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >System Management


    

Blue Forest http://www.lslnet.com at 20:18 on April 6, 2006


Next to the link layer capturing Packet freeBSD, socket () parameters of how to write?

[code]

#include "Stdio.h>;
#include "Stdlib.h>;
#include "Unistd.h>;
#include "String.h>;
#include "Netdb.h>;
#include "Unistd.h>;
#include "Signal.h>;
#include "Fcntl.h>;

  
#include "Netinet/in_systm.h>;
#include "Netinet/in.h>;
#include "Netinet/ip.h>;
#include "Netinet/tcp.h>;
#include "Netinet/udp.h>;



#include "Sys/socket.h>;
#include "Sys/ioctl.h>;
#include "Sys/stat.h>;
#include "Sys/param.h>;
#include "Sys/mbuf.h>;
#include "Sys/malloc.h>;
#include "Sys/protosw.h>;
#include "Sys/ctype.h>;
#include "Sys/kernel.h>;
#include "Sys/sysctl.h>;

#include "Arpa/inet.h>;


#include "Net/if.h>;
#include "Net/ethernet.h>;
#include "Net/route.h>;
#include "Netinet/ip_fw.h>;
#include "Netinet/ip_dummynet.h>;



0x0003 # ETH_P_ALL
Void die (char *why, int n)
{   
Perror (why);
Exit (n);
}   

Int do_promisc (char *nif, int sock)
{   
Struct ifreq ifr;


Strncpy (ifr.ifr_name, nif, strlen (nif) +1);
If ((ioctl (sock, SIOCGIFFLAGS, &ifr) ====== -1))
  {         
Die ( "ioctl" 2);
  }   
  
Ifr.ifr_flags) IFF_PROMISC;
  
If (ioctl (sock, SIOCSIFFLAGS, &ifr) ====== 1)
  {
Die ( "ioctl", 3);
  }   
}   


Char buf[2*32767];

Main ()
{   
FILE * fp;
Struct sockaddr_in addr;
Struct ether_header *peth;
Struct ip *pip;
Struct tcphdr *ptcp;
Struct udphdr *pudp;
/*add More protocol head here. . . . */
Char mac[16];

Int sock, r, len;
Char *data;
Char *ptemp;

Char ss[32], dd[32];
Int Rifa


If ((sock = socket (PF_INET, SOCK_RAW, htons (0))) ====== 1)
//if ((Sock = socket (PF_LINK, SOCK_RAW, htons (0))) ====== 1) 4003rd installed promiscuous mode failure
{

Die ( "socket", 1);
}

Do_promisc ( "fxp0" sock);

Fp=fopen ( "pkg.log", "ab+");
If (fp<0)
{
Printf ( "open file error\n");
Return 0
}
Printf ( "[%d][%d]\n" sock, fp);
System ( "ifconfig");
For (are;)
         {   
      
Practically = sizeof (addr);
               
R = recvfrom (sock, (char *) buf, sizeof (buf), 0, (struct sockaddr *) &addr, &len);
Buf[r] = 0

               
                        
         }
}

[/code]

Next to the link layer capturing Packet freeBSD, socket () parameters of how to write?

Top about themselves.

Next to the link layer capturing Packet freeBSD, socket () parameters of how to write?

Linux's code like this? Only the BPF FreeBSD, or direct use libpcap most simple, under libpcap Google under a lot of information.

Next to the link layer capturing Packet freeBSD, socket () parameters of how to write?

Thank you, at least, a set of explanations.



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com