Rev 2941 Rev 2942
Line 11... Line 11...
11 // 1.00 2012_09 Proof of concept (no configuration, not for public release) 11 // 1.00 2012_09 Proof of concept (no configuration, not for public release)
12 // 1.01 2012_09 Added parameter for device selection 12 // 1.01 2012_09 Added parameter for device selection
13 // 1.02 2012_12 Error handling and debugged 13 // 1.02 2012_12 Error handling and debugged
14 // 1.03 2012_12 Release version ready to publish 14 // 1.03 2012_12 Release version ready to publish
15 // 1.04 2013_04 Socket Bind Error with explanation (multiple instance of XVC Server) 15 // 1.04 2013_04 Socket Bind Error with explanation (multiple instance of XVC Server)
16 // 1.05 2013-04 Test FTDI cable during wait for Accept (to stop the server immediately when cable is disconnected) 16 // 1.05 2013_04 Test FTDI cable during wait for Accept (to stop the server immediately when cable is disconnected)
17 // 1.06 2013-04 Added support for Linux (thanks to Martin Poviser) 17 // 1.06 2013_04 Added support for Linux (thanks to Martin Poviser)
-   18 // 1.07 2013_04 Rewritten Host Address function for Linux (function gethostbyname returns 127.0.1.1 on Debian systems)
-   19 // Solved compatibility problems on Linux (FT_SetLatncyTimer requires delay, udev problem with ftdi_sio driver)
18 // 20 //
19 // 21 //
20 // Purpose: 22 // Purpose:
21 // 23 //
22 // XILINX development software (ISE, WebPack) supports several types of JTAG programming 24 // XILINX development software (ISE, WebPack) supports several types of JTAG programming
Line 81... Line 83...
81 // It does not work for internal FLASH of Spartan XC3SxxAN either. 83 // It does not work for internal FLASH of Spartan XC3SxxAN either.
82 // 84 //
83 // 85 //
84 // Possible improvements: 86 // Possible improvements:
85 // 87 //
86 // Linux version (not fully functional yet). -  
87 // External definition of JTAG pins. 88 // External definition of JTAG pins.
88 // Enable Socket Number (to be able to run multiple XVC Servers), now it is constant XVC_TCP_PORT (should be only a default) 89 // Enable Socket Number (to be able to run multiple XVC Servers), now it is constant XVC_TCP_PORT (should be only a default)
89   90  
90   91  
91 // Library Definitions 92 // Library Definitions
Line 116... Line 117...
116 #include <sys/socket.h> 117 #include <sys/socket.h>
117 #include <fcntl.h> 118 #include <fcntl.h>
118 #include <errno.h> 119 #include <errno.h>
119 #include <unistd.h> 120 #include <unistd.h>
120 #include <netdb.h> 121 #include <netdb.h>
-   122 #include <net/if.h>
-   123 #include <sys/ioctl.h>
-   124 #include <arpa/inet.h>
121   125  
122 #endif 126 #endif
123   127  
124 #define XVC_RX_BUFLEN (XVC_JTAG_LEN/8*2+20) // Length of receive buffer in bytes (command+length+TMSbuffer+TDIbuffer) 128 #define XVC_RX_BUFLEN (XVC_JTAG_LEN/8*2+20) // Length of receive buffer in bytes (command+length+TMSbuffer+TDIbuffer)
125 #define XVC_TX_BUFLEN (XVC_JTAG_LEN/8) // Length of transmit buffer in bytes (TDObuffer) 129 #define XVC_TX_BUFLEN (XVC_JTAG_LEN/8) // Length of transmit buffer in bytes (TDObuffer)
Line 463... Line 467...
463 jtagClosePort(); 467 jtagClosePort();
464 return -2; 468 return -2;
465 } 469 }
466 #endif 470 #endif
467   471  
468 // Display HostName and Address 472 // Display HostName
469 char sMyName[255]; 473 char sMyName[255];
470 gethostname(sMyName, sizeof(sMyName)); 474 gethostname(sMyName, sizeof(sMyName));
471 printf(" Host Name %s\n", sMyName); 475 printf(" Host Name %s\n", sMyName);
-   476  
-   477 // Display Address
-   478 #ifdef WIN32
472 hostent * pHostInfo; 479 hostent * pHostInfo;
473 pHostInfo = gethostbyname(sMyName); 480 pHostInfo = gethostbyname(sMyName);
474 printf(" Network Name %s\n", pHostInfo->h_name); 481 printf(" Network Name %s\n", pHostInfo->h_name);
475 if (pHostInfo->h_length>0 && pHostInfo->h_length<=16) 482 if (pHostInfo->h_length>0 && pHostInfo->h_length<=16)
476 { 483 {
Line 479... Line 486...
479 { 486 {
480 printf("%d.", (unsigned char)pHostInfo->h_addr_list[0][i]); 487 printf("%d.", (unsigned char)pHostInfo->h_addr_list[0][i]);
481 } 488 }
482 printf("%d\n", (unsigned char)pHostInfo->h_addr_list[0][pHostInfo->h_length-1]); 489 printf("%d\n", (unsigned char)pHostInfo->h_addr_list[0][pHostInfo->h_length-1]);
483 } 490 }
-   491 #else
-   492 int TempSocket;
-   493 struct ifreq ifreqs[20];
-   494 struct ifconf ic;
-   495  
-   496 ic.ifc_len = sizeof ifreqs;
-   497 ic.ifc_req = ifreqs;
-   498  
-   499 TempSocket = socket(AF_INET, SOCK_DGRAM, 0);
-   500 if (TempSocket < 0) {
-   501 perror("socket");
-   502 return -2;
-   503 }
-   504  
-   505 if (ioctl(TempSocket, SIOCGIFCONF, &ic) < 0) {
-   506 perror("SIOCGIFCONF");
-   507 return -2;
-   508 }
-   509  
-   510 for (int i = 0; i < ic.ifc_len/sizeof(struct ifreq); ++i)
-   511 {
-   512 if (ifreqs[i].ifr_name[0]!='l')// remove lo
-   513 printf(" Host Address %s: %s\n",
-   514 ifreqs[i].ifr_name,
-   515 inet_ntoa(((struct sockaddr_in*)&ifreqs[i].ifr_addr)->sin_addr));
-   516 }
-   517 #endif
484   518  
485 // Create Protocol Structure 519 // Create Protocol Structure
486 struct addrinfo hints; 520 struct addrinfo hints;
487 memset(&hints, 0, sizeof(hints)); 521 memset(&hints, 0, sizeof(hints));
488 hints.ai_family = AF_INET; // IP6 522 hints.ai_family = AF_INET; // IP6