⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux.c

📁 Virtual EtherDrive&#174 blade AoE target.
💻 C
字号:
// linux.c: low level access routines for Linux#include "config.h"#include <sys/socket.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <sys/time.h>#include <features.h>    /* for the glibc version number */#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1#include <netpacket/packet.h>#include <net/ethernet.h>     /* the L2 protocols */#else#include <asm/types.h>#include <linux/if_packet.h>#include <linux/if_ether.h>   /* The L2 protocols */#endif#include <sys/ioctl.h>#include <sys/types.h>#include <net/if.h>#include <netinet/in.h>#include <linux/fs.h>#include <sys/stat.h>#include "dat.h"#include "fns.h"int	getindx(int, char *);int	getea(int, char *, uchar *);intdial(char *eth)		// get us a raw connection to an interface{	int i;	int n, s;	struct sockaddr_ll sa;	enum { aoe_type = 0x88a2 };	memset(&sa, 0, sizeof sa);	s = socket(PF_PACKET, SOCK_RAW, htons(aoe_type));	if (s == -1) {		perror("got bad socket");		return -1;	}	i = getindx(s, eth);	sa.sll_family = AF_PACKET;	sa.sll_protocol = htons(0x88a2);	sa.sll_ifindex = i;	n = bind(s, (struct sockaddr *)&sa, sizeof sa);	if (n == -1) {		perror("bind funky");		return -1;	}	return s;}intgetindx(int s, char *name)	// return the index of device 'name'{	struct ifreq xx;	int n;	strcpy(xx.ifr_name, name);	n = ioctl(s, SIOCGIFINDEX, &xx);	if (n == -1)		return -1;	return xx.ifr_ifindex;}intgetea(int s, char *name, uchar *ea){	struct ifreq xx;	int n;        strcpy(xx.ifr_name, name);	n = ioctl(s, SIOCGIFHWADDR, &xx);	if (n == -1) {		perror("Can't get hw addr");		return 0;	}	memmove(ea, xx.ifr_hwaddr.sa_data, 6);	return 1;}intgetmtu(int s, char *name){	struct ifreq xx;	int n;	strcpy(xx.ifr_name, name);	n = ioctl(s, SIOCGIFMTU, &xx);	if (n == -1) {		perror("Can't get mtu");		return 1500;	}	return xx.ifr_mtu;}intgetsec(int fd, uchar *place, vlong lba, int nsec){	lseek(fd, lba * 512, 0);	return read(fd, place, nsec * 512);}intputsec(int fd, uchar *place, vlong lba, int nsec){	lseek(fd, lba * 512, 0);	return write(fd, place, nsec * 512);}intgetpkt(int fd, uchar *buf, int sz){	return read(fd, buf, sz);}intputpkt(int fd, uchar *buf, int sz){	return write(fd, buf, sz);}vlonggetsize(int fd){	vlong size;	struct stat s;	int n;	n = ioctl(fd, BLKGETSIZE64, &size);	if (n == -1) {	// must not be a block special		n = fstat(fd, &s);		if (n == -1) {			perror("getsize");			exit(1);		}		size = s.st_size;	}	return size;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -