From: SourceForge.net <no...@so...> - 2010-03-02 14:50:52
|
Bugs item #2960729, was opened at 2010-02-28 16:47 Message generated for change (Comment added) made by keithmarshall You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=2960729&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: w32api Group: Behaves as Documented Status: Deleted Resolution: Invalid Priority: 5 Private: No Submitted By: Eugene M. (bonez92) Assigned to: Nobody/Anonymous (nobody) Summary: sockaddr_in structure Initial Comment: Hi! I am using w32api 3.14. In winsock2.h sockaddr_in declared as: struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; } ; when trying to compile the code where sockaddr_in is used gcc.exe reports an error "`SOCKADDR_IN' undeclared (first use this function)". g++ doesn't report any errors and compiles successfully. After changing structure declaration: typedef struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; } sockaddr_in; gcc compiles successfully. ---------------------------------------------------------------------- >Comment By: Keith Marshall (keithmarshall) Date: 2010-03-02 14:50 Message: My previous comment notwithstanding, since it isn't my intention to be unhelpful:-- - I guess you are getting a compilation error saying "`sockaddr_in' undeclared ..."; this definitely *is* a bug in your code! - You must #include winsock2.h; in your example, it is commented out. - The source of your error is *not* related to this declaration: struct sockaddr_in client_addr; which is (now) perfectly correct usage. - The source of your error *is* this statement: printf("%d\n", sizeof(sockaddr_in)); where you are *still* trying to use sockaddr_in as a defined type, which it isn't; the type you need is `struct sockaddr_in', so change your code to: printf( "%d\n", sizeof( struct sockaddr_in )); and it should compile correctly. BTW, it took me longer to strip the copy-and-paste artifact garbage from your sample code, than it did to subsequently run it through the compiler and identify your bug. There is a file attachment facility on these trackers; please use it, when submitting code samples. ---------------------------------------------------------------------- Comment By: Keith Marshall (keithmarshall) Date: 2010-03-02 14:17 Message: Please DON'T show us code from Microsoft's SDKs! We aren't allowed to look at it, and by pushing it in our faces, you poison your ticket; even if this does identify a legitimate MinGW bug, you force me to delete it, and we can take no further action against it. ---------------------------------------------------------------------- Comment By: Eugene M. (bonez92) Date: 2010-03-01 14:42 Message: By the way I opened winsock2.h ---------------------------------------------------------------------- Comment By: Eugene M. (bonez92) Date: 2010-03-01 14:32 Message: Hmmm... If it is bug in my code then how to compile it? gcc reports the same error as without putting "struct". Here is the code: //#include <winsock2.h> #include <stdio.h> #include <windows.h> int main(void) { char* header="GET / HTTP 1.1\nHost: localhost\nUser-Agent: MyBot\nAccept: */*\nPragma: no-cache\nCache-Control: no-cache\0"; WORD wVersionRequested; WSADATA wsaData; SOCKET hSocket, client_socket; struct sockaddr_in client_addr; client_addr.sin_family=1; client_addr.sin_port=2; char msg[25]; int msg_len, client_addr_len; wVersionRequested = 2; WSAStartup(wVersionRequested, &wsaData); puts ("HTTP. GET.\n\n"); printf("%d\n", sizeof(sockaddr_in)); puts (header); return 0; } I am trying to compile as gcc d001.c -o d001.exe -lws2_32 Now what am I doing wrong? ---------------------------------------------------------------------- Comment By: Keith Marshall (keithmarshall) Date: 2010-03-01 14:16 Message: AFAICT, this is a bug in *your* code, *not* in MinGW. According to http://msdn.microsoft.com/en-us/library/zx63b042(VS.80).aspx, sockaddr_in is correctly declared as a structure tag, but is *not* typedef qualified. Your code may compile as C++ source, because C++ treats structs as classes, and the tagname for a class automatically becomes a type; it is not so in C code, where you must either explicitly supply the typedef yourself, (when it isn't predeclared in a system header), or you must explicitly declare your variables as struct sockaddr_in my_socket; and *not* as sockaddr_in my_socket; ---------------------------------------------------------------------- Comment By: Eugene M. (bonez92) Date: 2010-02-28 16:48 Message: Forgot to include. GCC's version is 4.4.0 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=2960729&group_id=2435 |