[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

What's wrong?

I'm writing an mrtg-like program. It's finished but i dont want to use the
kernel's ip accounting, so I try to write a RAW SOCKET based traffic
counter. I've written a small program following by the socket faq and man
pages, but i think it's reading bad ip headers. Here is the program:

--------- cut here  ---------------
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>

extern int errno;

#define PROTO htons(0x0800)

struct ip_pkt {
 struct iphdr ip;
 char *buffer;
} pkt;

int main(void)
  int s;
  struct in_addr in;

   if ((s = socket(AF_INET, SOCK_PACKET, PROTO)) == -1) {

     read(s, &pkt, sizeof(struct ip_pkt));
     in.s_addr = pkt.ip.saddr;
     printf("IP Packet from: %s\n", inet_ntoa(in));


-------------- cut here --------------

What did i wrong? Please some1.

 Tibor Koleszár
=[ IntegraNET ]===[ Internet Service Provider Corporation ]=
[ Koleszar Tibor - System engineer                         ]
[ E-mail         : t.koleszar@somogy.hu                    ]

Reply to: