How to pass an IP address to inet_addr?
Posted
by
November
on Super User
See other posts from Super User
or by November
Published on 2012-10-07T03:27:02Z
Indexed on
2012/10/07
3:41 UTC
Read the original article
Hit count: 475
I can't seem to pass an IP address to inet_addr
. I have gone through the debug but I still can't figure out why this won't work.
printf("Server IP\nIP:");
scanf("%s",cmdPtr);
//Bind socket
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr(&cmdPtr);
address.sin_port = htonl(SERVER_PORT);
lenC = sizeof(address);
if (connect(sdC, (struct sockaddr *) &address , lenC) < 0) {
perror("Could not bind Socket\n");
return -1;
}
© Super User or respective owner