Code:
//begin code section 1
h_test = gethostbyname(TEST);
if(h_test==NULL) {
exit(1);
}
//end code section 1
tbox_addr.sin_family = h_test->h_addrtype;
memcpy((char *) &tbox_addr.sin_addr.s_addr, h_test->h_addr_list[0], h_test->h_length);
tbox_addr.sin_port = htons(TEST_PORT);
result = gethostname(BOX, 64);
if(result != 0){
exit(1);
}
//begin code section 2
h_ip = gethostbyname(BOX);
if(h_ip==NULL) {
exit(1);
}
//end code section 2
box_addr.sin_family = h_ip->h_addrtype;
memcpy((char *) &box_addr.sin_addr.s_addr, h_ip->h_addr_list[0], h_ip->h_length);
box_addr.sin_port = htons(BOX_PORT);
Hello,
Can someone explain to me why it is that if I switch the order of code section 1 and code section 2 then the value at box_addr.sin_addr.s_addr is actually h_test->h_addr_list[0] rather than h_ip->h_addr_list[0]? Is a static variable being used or something? Also, do I need to free the value returned by gethostbyname?
Thanks,
shawn