Linux hybrid mode-Linux Enterprise Application-Linux server application information. For details, refer to the following section. Run ifconfig eth0-promisc on the terminal first.
Set the NIC to the hybrid mode. Then run the following code:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
/*
* Set the interface to promisc mode.
*/
Int set_netpromisc ()
{
Int fd, s;
Struct ifreq ifr;
Fd = socket (AF_INET, SOCK_PACKET, htons (0x800 ));
If (fd <0)
{
Perror ("can not get SOCK_PACKET socket ");
Return 0;
}
Strcpy (ifr. ifr_name, "eth0 ");
S = ioctl (fd, SIOCGIFFLAGS, & ifr );
If (s <0)
{
Close (fd );
Perror ("can not get flags ");
Return 0;
}
Ifr. ifr_flags | = IFF_PROMISC;
S = ioctl (fd, SIOCSIFFLAGS, & ifr );
If (s <0)
{
Close (fd );
Perror ("can not set flags ");
Return 0;
}
Return fd;
}
/*
* Display characters
*/
Void show_char (void * buff, int len)
{
While (len --)
{
If (buff)
{
Printf ("% c", * (char *) (buff ++ )));
}
Else
{
Printf (".");
Buff ++;
}
}
}
/*
* Display a buff in Hex.
*/
Void show_hex (void * buff, int len)
{
Int I = 15, tmp;
While (len --)
{
Printf ("% 02x", * (unsigned char *) (buff ++ ));
If (I -- = 0)
{
Printf ("\ t ");
Show_char (buff-16, 16 );
Printf ("\ n ");
I = 15;
}
}
If (I! = 0)
{
Tmp = I + 1;
While (tmp --)
Printf ("% c ",'.');
Printf ("\ t ");
Show_char (buff-15 + I, 16-I );
Printf ("\ n ");
}
Printf ("\ n ");
}
/*
* The main function.
*/
Int main ()
{
Int sockfd, ret;
Char buff [4096];
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service