Thread: storage size of 'sin' isn't known

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    storage size of 'sin' isn't known

    Hi,

    i am writing my first program regarding sockets in C and i have this problem which i cannot unfortunately resolve...any ideas pls??

    Storage size of 'sin' isn't known



    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <string.h>
    
    int main(){
    	
    	struct hostent *phe;
    	struct sockaddr_in sin; //problem is here........
    	char *host;
    	int s, rc, type;
    
    	host = "tombaker.cis.um.edu.mt";
    	memset(&sin, 0, sizeof(sin));
    
    	sin.sin_family = AF_INET;
    	sin->sin_port = 7; //ECHO service
    	sin.sin_addr = inet_makeaddr(
    			inet_network("193.188.43.36"),
    			inet_addr("193.188.43.36"));
    	s= socket(PF_INET, SOCK_STREAM, 0);
    	rc = connect(s, (struct sockaddr *)&sin, sizof(sin));
    	if (rc != 0)
    	 printf("failed");
    	else (printf("connected"));
    
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You failed to include winsock2.h.
    String literals should be const: http://cpwiki.sourceforge.net/Common...kes_and_errors
    And just in you aren't aware, you can't assign strings in C that way. It will merely store the address of the string literal.

    >>sin->sin_port = 7; //ECHO service
    Doesn't work, because sin is a local variable, not a pointer.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Elysia View Post
    You failed to include winsock2.h.
    String literals should be const: http://cpwiki.sourceforge.net/Common...kes_and_errors
    They should be, but you often have no choice. There are a lot of bad APIs out there that take string parameters as simply "char *". So you either declare your own strings the same way, or you have to scatter zillions of cast-away-const all over the place.

    The error of attempting to modify a string literal is becoming less and less dangerous, since more and more systems will throw a fault when you try to do so -- at least you'll find the problem and be able to correct it.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    I had the same problem (Xubuntu-8.10 on i386), and i solved it with including one header file of those:

    #include <netinet/in.h>

    or

    #include <arpa/inet.h>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 06:14 PM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  5. storage size of regs is unkown
    By Vertex34 in forum C Programming
    Replies: 5
    Last Post: 11-04-2003, 10:17 AM