![]() |
| | #1 |
| Registered User Join Date: Sep 2009
Posts: 11
| Setting IP address to connect to The question is: I want the client to connect to the IP Address which i have to explicitly set as 'localhost'. But I don't know exactly how I set the IPAddress that the client is to connect to, could someone please tell me where I do that and how? Also, Code: socketAddr.sin_addr.s_addr = ipAddress->s_addr; /* Copies IP address */ Thanx heaps, Code: int fd;
struct in_addr* ipAddress;
struct hostent* hostp;
struct sockaddr_in socketAddr;
char buffer[1024];
int numBytes;
hostp = gethostbyname("localhost");
ipAddress = (struct in_addr*)hostp->h_addr_list[0];
/* Specify the address we're going to connect to */
socketAddr.sin_family = AF_INET; /* Internet socket */
socketAddr.sin_port = htons(13827); /* Port number */
socketAddr.sin_addr.s_addr = ipAddress->s_addr; /* Copies IP address */
/* Create TCP socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
/* Try to connect to our server address */
/* Address cast to generic socket address type, but we need to specify
** the size of the address as the third argument */
connect(fd, (struct sockaddr*)&socketAddr, sizeof(socketAddr));
|
| tesla is offline | |
| | #2 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Quote:
| |
| tabstop is offline | |
| | #3 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| So replace localhost with the name of the site you do want to connect to.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IP address configuration Files? | Matus | Tech Board | 3 | 01-29-2009 04:35 PM |
| Converting 32 bit binary IP to decimal IP (vice-versa) | Mankthetank19 | C Programming | 14 | 11-27-2008 12:53 PM |
| IP Address Control Text Freeing? | MitchellH | Windows Programming | 2 | 05-22-2005 11:49 PM |
| finding out ip address? | chiatello | Linux Programming | 3 | 08-07-2003 06:18 AM |
| Contest Results - May 27, 2002 | ygfperson | A Brief History of Cprogramming.com | 18 | 06-18-2002 01:27 PM |