Re: Need some help with the TINI EVAL Kit
"Kris Ardis" <Kristopher.Ardis-6tN4nzCoH/[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <00a601c3ffa9$d3706420$764000b4@kardis> |
There are a few problems with this program: 1) You should clear out the 'socketaddress' to all 0's. This is not done automatically for you, whatever garbage is already there will be present in sin_addr[0..11]. 2) Change 'unsigned char result' to 'int result'...the socket functions have 16-bit return values. 3) You need to bind before you connect. 4) You might also want to change your switch statement at the bottom to have a success case when the return value is 0, so you don't get confused and see an error message even though the return value is 0. Kris ----- Original Message ----- From: "Desai, Sohail" <[email protected]> To: "Kris Ardis" <Kristopher.Ardis-6tN4nzCoH/[email protected]>; <[email protected]> Sent: Friday, February 27, 2004 4:23 PM Subject: RE: [TINI]Need some help with the TINI EVAL Kit Hi Kris, Thanks for your reply, here is my code for creating a HTTP client: ********************************************************************* #include "rom400_dhcp.h" #include "rom400_sock.h" #include "rom400_init.h" #include "rom400_task.h" #include "tini400_dns.h" #include "rom400_err.h" #include <stdio.h> #define RAM_START 0x14000 #define RAM_END 0x5FFFF void network_config() { unsigned char config[60]; unsigned int result; unsigned int i; for (i=0;i<56;i++) config[i] = 0; result = getnetworkparams(config); printf("Network params result: %d\r\n", result); printf("IP : %bu.%bu.%bu.%bu\r\n", config[12], config[13], config[14], config[15]); printf("Subnet: %bu.%bu.%bu.%bu\r\n", config[16], config[17], config[18], config[19]); printf("Prefix: %bu\r\n", config[20]); printf("Gate : %bu.%bu.%bu.%bu\r\n", config[33], config[34], config[35], config[36]); } void main() { unsigned int temp; unsigned char result; struct hostent* hostresult; struct sockaddr socketaddress; char* info; char buffer[20]; char buffer2[] = "GET /index.html HTTP/1.0\r\n \r\n"; int handle1; init_rom(RAM_START,RAM_END); clear_param_buffers(); dhcp_init(); result = task_wait(0, FLAG_DHCP_WAIT, 20000); temp = dhcp_status(); switch (temp) { case DHCP_STATUS_INIT : printf("DHCP: Init\r\n"); break; case DHCP_STATUS_SELECTING : printf("DHCP: Selecting\r\n"); break; case DHCP_STATUS_REQUESTING : printf("DHCP: Requesting\r\n"); break; case DHCP_STATUS_INITREBOOT : printf("DHCP: Init reboot\r\n"); break; case DHCP_STATUS_REBOOTING : printf("DHCP: Rebooting\r\n"); break; case DHCP_STATUS_BOUND : printf("DHCP: Bound\r\n"); break; case DHCP_STATUS_RENEWING : printf("DHCP: Renewing\r\n"); break; case DHCP_STATUS_REBINDING : printf("DHCP: Rebinding\r\n"); break; } network_config(); printf("Getting IP address for www.google.com\r\n"); hostresult = gethostbyname("www.google.com"); info = hostresult->h_addr_list[0]; if(info == NULL) { printf("DNS lookup failed.\r\n"); } else { printf("lenght of address: %u\r\n",hostresult->h_length); printf("The IP address is: %s\r\n",inet_ntop(hostresult->h_addrtype,info,buffer,20)); socketaddress.sin_port = 80; printf("Setting Socket Port to:%u\r\n",socketaddress.sin_port); socketaddress.sin_addr[12] = info[0]; socketaddress.sin_addr[13] = info[1]; socketaddress.sin_addr[14] = info[2]; socketaddress.sin_addr[15] = info[3]; printf("creating socket to www.google.com.\r\n"); handle1 = syn_socket(SOCKET_TYPE_STREAM); result = connect(handle1,&socketaddress,sizeof(struct sockaddr)); printf("%x\r\n",result); switch(result) { case ROM400_CONNECTEXCEPTION: printf("rom 400 connect exception\r\n"); break; case ROM400_SOCKETEXCEPTION: printf("rom 400 socket exception\r\n"); break; default: printf("unknown error.. connection failed\r\n"); break; } /* { printf("socket creation successful.\r\n"); printf("Sending a request using GET command.\r\n"); syn_send(handle1,sizeof(buffer2),buffer2); */ closesocket(handle1); // } } while(1); } ************************************************************************ *** I am monitoring the communication through ethereal. The DHCP request and DNS lookup work fine but not the socket creation. Thanks for all your help. BTW I checked the ROM error codes as you advised and I keep on getting a ROM 400 CONNECT EXCEPTION. What does this mean? Sohail _______________________________________________ TINI mailing list TINI-6tN4nzCoH/[email protected] To UNSUBSCRIBE, edit your profile, or see list archives: http://lists.dalsemi.com/mailman/listinfo/tini