[ hype @ 05.04.2004. 09:18 ] @
Sada vec lupam glavom o zid, i ne pomaze... ne znam zasto ne radi. Hint please! Izdvojeno parce koda bi trebalo da radi: - otvori raw socket - slusa i belezi protokol dolazecih paketa (ukoliko je protokol u opsegu 1-17) Medjutim nesto nije u redu, da li je potreban jos neki poziv WSAxxxx() ili ... ???? Code: // listen.c // #include <stdio.h> #include <winsock.h> struct iphdr { u_int ihl_version; u_char tos; u_int tot_len; u_int id; u_int frag_off; u_char ttl; u_char protocol; u_int check; u_long saddr; u_long daddr; }; int main(void) { WSADATA wsaData; WORD wVersionRequested = MAKEWORD(1,1); int nRet, s; char packet[64]; struct iphdr *ptr; nRet = WSAStartup(wVersionRequested, &wsaData); if (nRet || (wsaData.wVersion != wVersionRequested)) { perror("winsock_ver"); return -1; } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { perror("socket()"); return -1; } ptr = (struct iphdr *)packet; for (;;) { memset(&packet, 64, 0); recv(s, (char *)&packet, 64, 0); // greska ovde!? if (ptr->protocol >= 1 && ptr->protocol <= 17) fprintf(stderr,"packet protocol %d\n", ptr->protocol); } closesocket(s); WSACleanup(); return 0; } |