#include <netinet/udp.h> /* struct udphdr */
#include <net/ethernet.h> /* struct ethhdr */
#include <linux/ip.h> /* struct iphdr */

#include <netinet/in.h> /* ntohs, inet_ntoa */
#include <sys/socket.h> /* inet_ntoa */
#include <arpa/inet.h> /* inet_ntoa */

#include <string.h> /* strdup */
#include <stdlib.h> /* free */

#include "main.h"
#include "pcap_ip.h"

void handle_udp(const u_char *packet)
{
	struct udphdr *u;
	unsigned short sport, dport;
	char *saddr, *daddr;

	u = (struct udphdr*)(packet + sizeof(struct ethhdr)
			+ sizeof(struct iphdr));

	sport = ntohs(u->source);
	dport = ntohs(u->dest);
	
	saddr = strdup(inet_ntoa(get_ipsaddr(packet)));
	daddr = strdup(inet_ntoa(get_ipdaddr(packet)));

	DEBUGP(D_NOW, "UDP packet source: %s:%d, destination: %s:%d\n",
			saddr, sport, daddr, dport);
	
	free(saddr);
	free(daddr);
}

