ether promisc

Michal Ludvig michal-linux na logix.cz
Neděle Září 16 22:58:59 CEST 2001


David Trcka wrote:

> potrebuju uvest jedno ethernetove zarizeni do promiskuitniho rezimu a mam
> k dispozici pouze utilitku ip (iproute2-ss001007) a nebo /proc, bohuzel
> ani v jednom jsem to nenasel. Opakuju, ifconfig _nemam_. Jadro je rada
> 2.2.x. Dik za pomoc.

A co takhle staticky ifconfig slinkovany s dietlibc? Ten by mohl mit tak 
kolem 30kB (staticky slinkovany!). Kdyby i tohle bylo moc, tak na 
nastaveni interfacu do promisc staci:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>

int main()
{
	int sock;
	struct ifreq ethreq;

         if ( (sock=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP)))<0)
		{ perror("socket"); exit(1);  }
         strncpy(ethreq.ifr_name,"eth0",IFNAMSIZ);
         if (ioctl(sock,SIOCGIFFLAGS,&ethreq)==-1)
		{ perror("ioctl"); close(sock); exit(1); }
         ethreq.ifr_flags|=IFF_PROMISC;
	// ethreq.ifr_flags&=~IFF_PROMISC; /* pro zruseni promisc */
         if (ioctl(sock,SIOCSIFFLAGS,&ethreq)==-1)
		{ perror("ioctl"); close(sock); exit(1); }

         close(sock);
         return 0;
}

a tohle slinkovat s dietlibc. Staticky to ma 4764 bytes :-) A funguje 
to. Jestli chcete, tak vam poslu binarku.

Michal Ludvig



Další informace o konferenci Linux