newbie socket question

R

Robert Smith

using redhat 8.0 and I have the following code....

#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define DEST_IP "64.12.161.153"
// #define DEST_IP "127.0.0.1"
#define DEST_PORT 235

int main()
{
int sockfd;
int connectOK;
struct sockaddr_in dest_addr; // will holdthe destination addr

sockfd = socket(AF_INET, SOCK_STREAM, 0); //do some error checking!

dest_addr.sin_family = AF_INET; //host byte order
dest_addr.sin_port = htons(DEST_PORT); //short, network byte order
dest_addr.sin_addr.s_addr =inet_addr(DEST_IP);
memset(&(dest_addr.sin_zero), '\0', 8); //zero the rest of the
struct

// don't forget to error check the connect()!
connectOK = connect(sockfd, (struct sockaddr*)&dest_addr,
sizeof(struct sockaddr));

if(connectOK==-1)
printf("not connected");
else
printf("connected");

return 0;
}

When i use the ip address 64.12.161.153 which is the correct server it says
its connected.
When i use the ip address 127.0.0.1 which is not the correct server is says
not connected.
When i use any other IP address it just hangs there and doesnt print
anything, why is this?
Also after it connects how can i test to see how long it will hold the
connection open for untill the remote server closes it?
thanks
 
J

Joona I Palaste

Robert Smith said:
using redhat 8.0 and I have the following code....
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

Stop right there. This is a question about non-standard extension APIs,
not of the C language. Please ask in comp.unix.programmer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top