The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-28-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by Stevhp
sad.sin_family=AF_INET;
sad.sin_port=atoi(argv[2]);
sad.sin_addr.s_addr=inet_addr(argv[1]);
Let's try a wild guess, you are using a little-endian machine such as a x86?

unsigned short my_port=atoi(argv[2]);

memset(&sad,0,sizeof(sad));
sad.sin_family=AF_INET;
sad.sin_port=htons(my_port);
sad.sin_addr.s_addr=inet_addr(argv[1]);

as long as both port and host are numeric, else use getservbyname and gethostbyname.