net_gethostbyname vs. numeric IPs? January 08, 2010 09:14AM | Registered: 14 years ago Posts: 4 |
s32 tcp_connect (char *host, const u16 port) { struct sockaddr_in sa; s32 s, res; s64 t; // added for testing for numeric IPs struct in_addr * myaddr; if (inet_aton(host, myaddr)) { printf("Host is numeric IP\n"); //... // setup 'sa' with binarified address and a couple other things memset (&sa, 0, sizeof (struct sockaddr_in)); sa.sin_family= PF_INET; sa.sin_len = sizeof (struct sockaddr_in); // 4 bytes sa.sin_port= htons (port); //memcpy ((char *) &sa.sin_addr, &myaddr, sizeof(struct in_addr)); memcpy ((char *) &sa.sin_addr, host, strlen(host)); //printf("Size of sa.in_addr: %d Size of in_addr: %d size of myaddr: %d\n", sizeof(sa.sin_addr), sizeof(struct in_addr), sizeof(myaddr)); } else { //original net_gethostbyname stuff here... struct hostent *hp = net_gethostbyname(host); if (!hp || !(hp->h_addrtype == PF_INET)) { printf ("net_gethostbyname failed: %d\n", errno); return errno; } memset (&sa, 0, sizeof (struct sockaddr_in)); sa.sin_family= PF_INET; sa.sin_len = sizeof (struct sockaddr_in); sa.sin_port= htons (port); memcpy ((char *) &sa.sin_addr, hp->h_addr_list[0], hp->h_length); } // else
Re: net_gethostbyname vs. numeric IPs? January 08, 2010 11:43AM | Registered: 15 years ago Posts: 405 |
Re: net_gethostbyname vs. numeric IPs? January 09, 2010 11:40AM | Registered: 14 years ago Posts: 4 |
struct in_addr myaddr; if (inet_aton(host, &myaddr)) { printf("Host is numeric IP\n"); //... // setup 'sa' with binarified address and a couple other things memset (&sa, 0, sizeof (struct sockaddr_in)); sa.sin_family= PF_INET; sa.sin_len = sizeof (struct sockaddr_in); sa.sin_port= htons (port); memcpy ((char *) &sa.sin_addr, &myaddr.s_addr, sizeof(struct in_addr)); }
Re: net_gethostbyname vs. numeric IPs? January 09, 2010 12:32PM | Registered: 15 years ago Posts: 405 |
Quote
Drmn4ea
Now to find out, is there any available mechanism to provide an IRQ/callback when a packet arrives, rather that poll continuously for them? (Or is this why there are hardly any networked multiplayer homebrew games...)
Polling function check if data is recieved if data exists then append to buffer if no data then do nothing
Main function Initiate network Connect to ip Initialise threading Assign polling function to thread (the above polling function) while threading { check buffer if buffer has data then pause threading and output after output clear buffer restart threading do nothing if buffer empty sleep for a short period of time (just for stability) }
Re: net_gethostbyname vs. numeric IPs? January 10, 2010 06:42AM | Registered: 14 years ago Posts: 4 |
Quote
theoretically, if you set a callback it is polling continuosly as without polling it wont know if had recieved anything.
Re: net_gethostbyname vs. numeric IPs? January 10, 2010 11:02AM | Registered: 14 years ago Posts: 686 |