Lines Matching refs:hijack
29 struct hijack {
102 static int hijack_open ( const char *interface, struct hijack *hijack ) {
107 hijack->pcap = pcap_open_live ( interface, SNAPLEN, 1, 0, errbuf );
108 if ( ! hijack->pcap ) {
117 if ( pcap_setnonblock ( hijack->pcap, 1, errbuf ) < 0 ) {
124 hijack->fd = pcap_get_selectable_fd ( hijack->pcap );
125 if ( hijack->fd < 0 ) {
132 hijack->datalink = pcap_datalink ( hijack->pcap );
137 if ( hijack->pcap )
138 pcap_close ( hijack->pcap );
146 static void hijack_close ( struct hijack *hijack ) {
147 pcap_close ( hijack->pcap );
154 static int hijack_install_filter ( struct hijack *hijack,
159 if ( pcap_compile ( hijack->pcap, &program, filter, 1, 0 ) < 0 ) {
161 filter, pcap_geterr ( hijack->pcap ) );
166 if ( pcap_setfilter ( hijack->pcap, &program ) < 0 ) {
168 filter, pcap_geterr ( hijack->pcap ) );
187 static int hijack_filter_ethernet ( struct hijack *hijack, const char *buf,
200 return hijack_install_filter ( hijack, filter );
207 static int hijack_filter ( struct hijack *hijack, const char *buf,
209 switch ( hijack->datalink ) {
211 return hijack_filter_ethernet ( hijack, buf, len );
214 ( pcap_datalink_val_to_name ( hijack->datalink ) ?
215 pcap_datalink_val_to_name ( hijack->datalink ) :
226 static ssize_t forward_from_hijacker ( struct hijack *hijack, int fd ) {
241 if ( ! hijack->filtered ) {
242 if ( hijack_filter ( hijack, buf, len ) == 0 )
243 hijack->filtered = 1;
247 if ( pcap_inject ( hijack->pcap, buf, len ) != len ) {
249 pcap_geterr ( hijack->pcap ) );
253 hijack->tx_count++;
261 static ssize_t forward_to_hijacker ( int fd, struct hijack *hijack ) {
267 if ( pcap_next_ex ( hijack->pcap, &pkt_header, &pkt_data ) < 0 ) {
269 pcap_geterr ( hijack->pcap ) );
288 hijack->rx_count++;
298 struct hijack hijack;
306 memset ( &hijack, 0, sizeof ( hijack ) );
307 if ( hijack_open ( interface, &hijack ) < 0 )
311 max_fd = ( ( fd > hijack.fd ) ? fd : hijack.fd );
316 FD_SET ( hijack.fd, &fdset );
323 len = forward_from_hijacker ( &hijack, fd );
329 if ( FD_ISSET ( hijack.fd, &fdset ) ) {
330 len = forward_to_hijacker ( fd, &hijack );
338 hijack_close ( &hijack );
341 hijack.rx_count, hijack.tx_count );
346 if ( hijack.pcap )
347 hijack_close ( &hijack );
369 "/var/run/hijack-%s", interface );
534 char pidfile[16 + IF_NAMESIZE + 4]; /* "/var/run/hijack-<intf>.pid" */
548 snprintf ( pidfile, sizeof ( pidfile ), "/var/run/hijack-%s.pid",