Example #1
0
int printIPPacket(gpacket_t *msg)
{
	ip_packet_t *ip_pkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int tos;

	ip_pkt = (ip_packet_t *)msg->data.data;
	printf("IP: ----- IP Header -----\n");
	printf("IP: Version        : %d\n", ip_pkt->ip_version);
	printf("IP: Header Length  : %d Bytes\n", ip_pkt->ip_hdr_len*4);
	printf("IP: Total Length   : %d Bytes\n", ntohs(ip_pkt->ip_pkt_len));
	printf("IP: Type of Service: 0x%02X\n", ip_pkt->ip_tos);
	printf("IP:      xxx. .... = 0x%02X (Precedence)\n", IPTOS_PREC(ip_pkt->ip_tos));
	tos = IPTOS_TOS(ip_pkt->ip_tos);
	if (tos ==  IPTOS_LOWDELAY)
		printf("IP:      ...1 .... = Minimize Delay\n");
	else
		printf("IP:      ...0 .... = Normal Delay\n");
	if (tos == IPTOS_THROUGHPUT)
		printf("IP:      .... 1... = Maximize Throughput\n");
	else
		printf("IP:      .... 0... = Normal Throughput\n");
	if (tos == IPTOS_RELIABILITY)
		printf("IP:      .... .1.. = Maximize Reliability\n");
	else
		printf("IP:      .... .0.. = Normal Reliability\n");
	if (tos == IPTOS_MINCOST)
		printf("IP:      .... ..1. = Minimize Cost\n");
	else
		printf("IP:      .... ..0. = Normal Cost\n");
	printf("IP: Identification : %d\n", ntohs(ip_pkt->ip_identifier));
	printf("IP: Flags          : 0x%02X\n", ((ntohs(ip_pkt->ip_frag_off) & ~IP_OFFMASK)>>13));
	if ((ntohs(ip_pkt->ip_frag_off) & IP_DF) == IP_DF)
		printf("IP:      .1.. .... = do not fragment\n");
	else
		printf("IP:      .0.. .... = can fragment\n");
	if ((ntohs(ip_pkt->ip_frag_off) & IP_MF) == IP_MF)
		printf("IP:      ..1. .... = more fragment\n");
	else
		printf("IP:      ..0. .... = last fragment\n");
	printf("IP: Fragment Offset: %d Bytes\n", (ntohs(ip_pkt->ip_frag_off) & IP_OFFMASK));
	printf("IP: Time to Live   : %d sec/hops\n", ip_pkt->ip_ttl);

	printf("IP: Protocol       : %d", ip_pkt->ip_prot);
	printf("IP: Checksum       : 0x%X\n", ntohs(ip_pkt->ip_cksum));
	printf("IP: Source         : %s", IP2Dot(tmpbuf, gNtohl((tmpbuf+20), ip_pkt->ip_src)));
	printf("IP: Destination    : %s", IP2Dot(tmpbuf, gNtohl((tmpbuf+20), ip_pkt->ip_dst)));

	return ip_pkt->ip_prot;
}
Example #2
0
/**
 * nfq_pkt_snprintf_ip - print IPv4 header into buffer in iptables LOG format
 * \param buf: pointer to buffer that will be used to print the header
 * \param size: size of the buffer (or remaining room in it)
 * \param ip: pointer to a valid IPv4 header
 *
 * This function returns the number of bytes that would have been written in
 * case that there is enough room in the buffer. Read snprintf manpage for more
 * information to know more about this strange behaviour.
 */
int nfq_ip_snprintf(char *buf, size_t size, const struct iphdr *iph)
{
	int ret;
	struct in_addr src = { iph->saddr };
	struct in_addr dst = { iph->daddr };

	ret = snprintf(buf, size, "SRC=%s DST=%s LEN=%u TOS=0x%X "
				  "PREC=0x%X TTL=%u ID=%u PROTO=%u ",
			inet_ntoa(src), inet_ntoa(dst),
			ntohs(iph->tot_len), IPTOS_TOS(iph->tos),
			IPTOS_PREC(iph->tos), iph->ttl, ntohs(iph->id),
			iph->protocol);

	return ret;
}
Example #3
0
File: net.c Project: brabander/olsr
void
os_socket_set_olsr_options(struct interface * ifs, int sock, union olsr_sockaddr *mcast) {
  /* Set TOS */
  int data = IPTOS_PREC(olsr_cnf->tos);
  if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (char *)&data, sizeof(data)) < 0) {
    OLSR_WARN(LOG_INTERFACE, "setsockopt(SO_PRIORITY) error %s", strerror(errno));
  }
  data = IPTOS_TOS(olsr_cnf->tos);
  if (setsockopt(sock, SOL_IP, IP_TOS, (char *)&data, sizeof(data)) < 0) {
    OLSR_WARN(LOG_INTERFACE, "setsockopt(IP_TOS) error %s", strerror(errno));
  }

  if (mcast) {
    join_mcast(ifs, sock, mcast);
  }
}