Пример #1
0
static void dump_ehdr_and_myripad(unsigned char *stuff)
{
	struct ethhdr *ehdr = (struct ethhdr *) (stuff + 2);

;
	dump_ehdr(ehdr);
}
Пример #2
0
/* Rebuild the MyriNet MAC header. This is called after an ARP
 * (or in future other address resolution) has completed on this
 * sk_buff. We now let ARP fill in the other fields.
 */
static int myri_rebuild_header(struct sk_buff *skb)
{
	unsigned char *pad = (unsigned char *) skb->data;
	struct ethhdr *eth = (struct ethhdr *) (pad + MYRI_PAD_LEN);
	struct net_device *dev = skb->dev;

#ifdef DEBUG_HEADER
	DHDR(("myri_rebuild_header: pad[%02x,%02x] ", pad[0], pad[1]));
	dump_ehdr(eth);
#endif

	/* Refill MyriNet padding identifiers, this is just being anal. */
	pad[0] = MYRI_PAD_LEN;
	pad[1] = 0xab;

	switch (eth->h_proto)
	{
#ifdef CONFIG_INET
	case cpu_to_be16(ETH_P_IP):
 		return arp_find(eth->h_dest, skb);
#endif

	default:
//		printk(KERN_DEBUG
//		       "%s: unable to resolve type %X addresses.\n",
;

		memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
		return 0;
		break;
	}

	return 0;
}
Пример #3
0
static void dump_ehdr_and_myripad(unsigned char *stuff)
{
	struct ethhdr *ehdr = (struct ethhdr *) (stuff + 2);

	printk("pad[%02x:%02x]", stuff[0], stuff[1]);
	dump_ehdr(ehdr);
}
Пример #4
0
static __be16 myri_type_trans(struct sk_buff *skb, struct net_device *dev)
{
	struct ethhdr *eth;
	unsigned char *rawp;

	skb_set_mac_header(skb, MYRI_PAD_LEN);
	skb_pull(skb, dev->hard_header_len);
	eth = eth_hdr(skb);

#ifdef DEBUG_HEADER
	DHDR(("myri_type_trans: "));
	dump_ehdr(eth);
#endif
	if (*eth->h_dest & 1) {
		if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN)==0)
			skb->pkt_type = PACKET_BROADCAST;
		else
			skb->pkt_type = PACKET_MULTICAST;
	} else if (dev->flags & (IFF_PROMISC|IFF_ALLMULTI)) {
		if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
			skb->pkt_type = PACKET_OTHERHOST;
	}

	if (ntohs(eth->h_proto) >= 1536)
		return eth->h_proto;

	rawp = skb->data;

	
	if (*(unsigned short *)rawp == 0xFFFF)
		return htons(ETH_P_802_3);

	
	return htons(ETH_P_802_2);
}
Пример #5
0
/* Create the MyriNet MAC header for an arbitrary protocol layer
 *
 * saddr=NULL	means use device source address
 * daddr=NULL	means leave destination address (eg unresolved arp)
 */
static int myri_header(struct sk_buff *skb, struct net_device *dev,
		       unsigned short type, const void *daddr,
		       const void *saddr, unsigned len)
{
	struct ethhdr *eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
	unsigned char *pad = (unsigned char *) skb_push(skb, MYRI_PAD_LEN);

#ifdef DEBUG_HEADER
	DHDR(("myri_header: pad[%02x,%02x] ", pad[0], pad[1]));
	dump_ehdr(eth);
#endif

	/* Set the MyriNET padding identifier. */
	pad[0] = MYRI_PAD_LEN;
	pad[1] = 0xab;

	/* Set the protocol type. For a packet of type ETH_P_802_3/2 we put the
	 * length in here instead.
	 */
	if (type != ETH_P_802_3 && type != ETH_P_802_2)
		eth->h_proto = htons(type);
	else
		eth->h_proto = htons(len);

	/* Set the source hardware address. */
	if (saddr)
		memcpy(eth->h_source, saddr, dev->addr_len);
	else
		memcpy(eth->h_source, dev->dev_addr, dev->addr_len);

	/* Anyway, the loopback-device should never use this function... */
	if (dev->flags & IFF_LOOPBACK) {
		int i;
		for (i = 0; i < dev->addr_len; i++)
			eth->h_dest[i] = 0;
		return dev->hard_header_len;
	}

	if (daddr) {
		memcpy(eth->h_dest, daddr, dev->addr_len);
		return dev->hard_header_len;
	}
	return -dev->hard_header_len;
}
Пример #6
0
static int myri_header(struct sk_buff *skb, struct net_device *dev,
		       unsigned short type, const void *daddr,
		       const void *saddr, unsigned len)
{
	struct ethhdr *eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
	unsigned char *pad = (unsigned char *) skb_push(skb, MYRI_PAD_LEN);

#ifdef DEBUG_HEADER
	DHDR(("myri_header: pad[%02x,%02x] ", pad[0], pad[1]));
	dump_ehdr(eth);
#endif

	
	pad[0] = MYRI_PAD_LEN;
	pad[1] = 0xab;

	
	if (type != ETH_P_802_3)
		eth->h_proto = htons(type);
	else
		eth->h_proto = htons(len);

	
	if (saddr)
		memcpy(eth->h_source, saddr, dev->addr_len);
	else
		memcpy(eth->h_source, dev->dev_addr, dev->addr_len);

	
	if (dev->flags & IFF_LOOPBACK) {
		int i;
		for (i = 0; i < dev->addr_len; i++)
			eth->h_dest[i] = 0;
		return(dev->hard_header_len);
	}

	if (daddr) {
		memcpy(eth->h_dest, daddr, dev->addr_len);
		return dev->hard_header_len;
	}
	return -dev->hard_header_len;
}
Пример #7
0
/* Determine the packet's protocol ID. The rule here is that we
 * assume 802.3 if the type field is short enough to be a length.
 * This is normal practice and works for any 'now in use' protocol.
 */
static __be16 myri_type_trans(struct sk_buff *skb, struct net_device *dev)
{
	struct ethhdr *eth;
	unsigned char *rawp;

	skb_set_mac_header(skb, MYRI_PAD_LEN);
	skb_pull(skb, dev->hard_header_len);
	eth = eth_hdr(skb);

#ifdef DEBUG_HEADER
	DHDR(("myri_type_trans: "));
	dump_ehdr(eth);
#endif
	if (*eth->h_dest & 1) {
		if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN)==0)
			skb->pkt_type = PACKET_BROADCAST;
		else
			skb->pkt_type = PACKET_MULTICAST;
	} else if (dev->flags & (IFF_PROMISC|IFF_ALLMULTI)) {
		if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
			skb->pkt_type = PACKET_OTHERHOST;
	}

	if (ntohs(eth->h_proto) >= 1536)
		return eth->h_proto;

	rawp = skb->data;

	/* This is a magic hack to spot IPX packets. Older Novell breaks
	 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
	 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
	 * won't work for fault tolerant netware but does for the rest.
	 */
	if (*(unsigned short *)rawp == 0xFFFF)
		return htons(ETH_P_802_3);

	/* Real 802.2 LLC */
	return htons(ETH_P_802_2);
}
Пример #8
0
int show_ehdr( char **argv )
{
   if( *argv ) error_ret("bad args",-1);
   dump_ehdr( get_elf() );
   return( COMMAND_SUCCESS );
}
Пример #9
0
/* Main program. */
int main(int argc, char **argv)
{
	struct nucs_exec ahdr;   // minix aout header
	struct nucs_exec_elf32 input_exec_elf32;
	struct stat st_input;
	elf32_ehdr_t ehdr;
	elf32_phdr_t* phdrs = 0;
	elf32_shdr_t* shdrs = 0;
	int fd_in;
	int fd_out;
	int fd_aout;
	char* input = 0;
	char* output = 0;
	char* faout = 0;
	char strnum[MAX_DIGITS]; 
	char* strflags[MAX_TOKENS]; 
	unsigned int flags = A_EXEC;
	unsigned char cpu = A_I80386;
	int stackheap = -1;
	int hdrlen = HDRLEN;
	int opt;
	int i=0;
	int n=0;

	memset(strflags, 0, sizeof(strflags));
	memset(strnum, 0, sizeof(strnum));

	while ((opt = getopt(argc, argv,"c:d:f:hi:l:o:s:")) != -1) {
		switch (opt) {
		case 'c': /* cpu type */
			if(!strncmp(optarg,"i386",4))
				cpu = A_I80386;

			if(!strncmp(optarg,"i8086",5))
				cpu = A_I8086;
			break;

		case 'd': /* dump aout header */
			faout = optarg;
			break;

		case 'f': /* flags */
			memset(strflags,0,MAX_TOKENS);
			flags = 0x00;

			/* get the first token */
			strflags[0] = strtok(optarg," ,");

			/* parse the rest of string */
			while ((++i <= MAX_TOKENS) && ((strflags[i] = strtok (0," ,")) != 0));

			n=i;
			unsigned int flag = 0x00;

			for(i=0; i<n; i++) {
				if(strlen(strflags[i]) > 2 && strflags[i][0] == '0' &&
					strflags[i][1] == 'x')
					sscanf(strflags[i],"%x",&flag);
				else
					flag = atoi(strflags[i]);

				flags |= flag;
			}
			break;

		case 'h':
			usage();
			exit(0);

		case 'i': /* input */
			input = optarg;
			break;

		case 'l': /* header length (default 0x20) */
			memset(strnum,0,MAX_DIGITS);
			if(strlen(optarg) > 2 && optarg[0] == '0' && optarg[1] == 'x')
				sscanf(optarg,"%x",&hdrlen);
			else
				hdrlen = atoi(optarg);

			break;

		case 'o': /* output */
			output = optarg;
			break;

		case 's': /* stack + heap size */
		{
			char * mulstr;
			stackheap = strtoul(optarg, &mulstr, 0);

			if (mulstr[0] != 0) {
				switch (mulstr[0]) {
				case 'k':
					stackheap <<= 10;
					break;
				case 'M':
					stackheap <<= 20;
					break;
				default:
					goto wrong_size;
				}

				if (mulstr[1] != 0) {
					switch(mulstr[1]) {
					case 'w':
						stackheap *= 4; /* assuming 32bits */
						break;
					case 'b':
						break;
					default:
						goto wrong_size;
					}
				}
			}
			break;
wrong_size:
			fprintf(stderr, "Unrecognized size modifier\n");
			usage();
			exit(1);
		}
		break;

		default: /* '?' */
			usage();
			exit(1);
		}
	}

	if(faout) {
		if((fd_aout = open(faout, O_RDONLY))<0) {
			perror("open");
			exit(1);
		}

		if ((n = read(fd_aout, &ahdr, sizeof(ahdr))) < 0) {
			perror("read");
		}

		close(fd_aout);

		if (n != sizeof(ahdr)) {
			fprintf(stderr,"Wrong header size (want %d got %d\n",sizeof(ahdr),n);
		}

		dump_aout(&ahdr);

		return 0;
	}

	if(!input || !output || stackheap<0) {
		usage();
		exit(1);
	}

	if (stat(input, &st_input) != 0) {
		perror("stat");
		exit(1);
	}

	if((fd_in = open(input, O_RDONLY))<0) {
		report(input,"Couldn't open input file");
		exit(1);
	}

	if((fd_out = open(output, O_CREAT|O_RDWR|O_TRUNC, S_IFREG|S_IRUSR|S_IWUSR|S_IWUSR))<0) {
		report(output,"Couldn't open output file");
		exit(1);
	}

	read_elf32_ehdr(input, &ehdr);

#if DO_TRACE == 1
	printf("---[ELF header]---\n");
	dump_ehdr(&ehdr);
#endif

	phdrs = read_elf32_phdrs(input, &ehdr, phdrs);

#if DO_TRACE == 1
	for(i=0; i<ehdr.e_phnum; i++) {
		printf("---[%d. program header]---\n",i);
		dump_phdr(&phdrs[i]);
	}
#endif

	shdrs = read_elf32_shdrs(input, &ehdr, shdrs);

#if DO_TRACE == 1
	for(i=0; i<ehdr.e_shnum; i++) {
		printf("---[%d. section header]---\n",i);
		dump_shdr(&shdrs[i]);
	}
#endif

	create_exec_elf32(&ehdr, phdrs, shdrs, &input_exec_elf32);

#if DO_TRACE == 1
	dump_exec_elf32(&input_exec_elf32);
#endif

	/* Build a.out header and write to output */
	memset(&ahdr, 0, sizeof(ahdr));
	ahdr.a_magic[0] = A_MAGIC0;
	ahdr.a_magic[1] = A_MAGIC1;
	ahdr.a_flags    = flags;
	ahdr.a_cpu      = cpu;
	ahdr.a_hdrlen   = hdrlen;
	ahdr.a_text     = input_exec_elf32.text_size;
	ahdr.a_data     = input_exec_elf32.data_size;
	ahdr.a_bss      = input_exec_elf32.bss_size;

	ahdr.a_total = ahdr.a_text + ahdr.a_data + ahdr.a_bss + stackheap;
	ahdr.a_entry = input_exec_elf32.initial_ip;

	if (flags & A_NSYM) {
		ahdr.a_syms = input_exec_elf32.symtab_size;
	} else {
		ahdr.a_syms = 0;
	}

	write(fd_out, &ahdr, hdrlen);
	close(fd_in);
	close(fd_out);

	return 0;
}