struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses */ }
struct hostent *server_info; char * hostname = "cslab103.cs.edinboro.edu"; if (NULL == (server_info = gethostbyname(hostname))){ sprintf(buf, "Name lookup failed for %s",hostname); perror("Name lookup failed "); exit(-1); }
struct sockaddr_in { short sin_family u_short sin_port; struct in_addr sin_addr; }
struct sockaddr_in where; ... where.sin_addr.s_addr = *((u_long *) server_info->h_addr_list[0]); where.sin_port = htons(5600); where.sin_family = AF_INET; if (-1 == connect(s,&where,sizeof(struct sockaddr_in))){ perror("Connection failed"); exit(-1); }