TSK_VS_INFO * tsk_vs_sun_open(TSK_IMG_INFO * img_info, TSK_DADDR_T offset) { TSK_VS_INFO *vs; // clean up any errors that are lying around tsk_error_reset(); vs = (TSK_VS_INFO *) tsk_malloc(sizeof(*vs)); if (vs == NULL) return NULL; vs->img_info = img_info; vs->vstype = TSK_VS_TYPE_SUN; vs->tag = TSK_VS_INFO_TAG; vs->offset = offset; /* inititialize settings */ vs->part_list = NULL; vs->part_count = 0; vs->endian = 0; vs->block_size = img_info->sector_size; /* Assign functions */ vs->close = sun_close; /* Load the partitions into the sorted list */ if (sun_load_table(vs)) { sun_close(vs); return NULL; } /* fill in the sorted list with the 'unknown' values */ if (tsk_vs_part_unused(vs)) { sun_close(vs); return NULL; } return vs; }
int main_t10(int argc, char *argv[]){ int sockfd; struct iphdr *ip_hdr; struct icmphdr *icmp_hdr; struct sockaddr_in servaddr; int payload_size = 0; if(argc != 4){ fprintf(stderr, "Usage: %s <source IP> <dest IP> <payload size>", argv[0]); exit(0); } payload_size = atoi(argv[3]); /* * If you use IPPROTO_ICMP, then kernel will fill in the correct * ICMP header checksum, If IPPROTO_RAW, then it wont */ sockfd = sun_socket(AF_INET, SOCK_RAW, IPPROTO_RAW); const int on = 1; // Provide ourself IP header sun_setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)); // Allow socket to send datagrams to broadcast addresses sun_setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (const char *)&on, sizeof(on)); // Calculate total packet size int packet_size = sizeof(struct iphdr) + sizeof(struct icmphdr) + payload_size; char *packet = (char *)sun_malloc(packet_size); ip_hdr = (struct iphdr *)packet; icmp_hdr = (struct icmphdr *)(packet + sizeof(struct iphdr)); memset(packet, 0, packet_size); ip_hdr->version = 4; ip_hdr->ihl = 5; // IP header length 5*32 = 160bits = 20 bytes ip_hdr->tos = 0; // Type of service ip_hdr->tot_len = htons(packet_size); // Total length, header + data ip_hdr->id = rand(); // Identification ip_hdr->ttl = 255; // Time-to-live ip_hdr->frag_off = 0; // Fragment Offset ip_hdr->protocol = IPPROTO_ICMP; // Protocol sun_inet_pton(AF_INET, argv[1], &ip_hdr->saddr); // Source address sun_inet_pton(AF_INET, argv[2], &ip_hdr->daddr); // Destination Address ip_hdr->check = 0; // check sum, Let kernel fills in. icmp_hdr->type = ICMP_ECHO; icmp_hdr->code = 0; icmp_hdr->un.echo.sequence = rand(); icmp_hdr->un.echo.id = rand(); // set payload memset(packet + sizeof(struct iphdr) + sizeof(struct icmphdr), rand() % 255, payload_size); // set checksum icmp_hdr->checksum = sun_in_cksum((unsigned short *)icmp_hdr, sizeof(struct icmphdr) + payload_size); memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; sun_inet_pton(AF_INET, argv[2], &servaddr.sin_addr); sun_sendto(sockfd, packet, packet_size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); printf("done.\n"); free(packet); sun_close(sockfd); return (0); }