diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/dfnet/dfnet.c | 11 | ||||
| -rw-r--r-- | plugins/dfnet/dfnet.h | 2 | ||||
| -rw-r--r-- | plugins/dfnet/gui.c | 45 |
3 files changed, 41 insertions, 17 deletions
diff --git a/plugins/dfnet/dfnet.c b/plugins/dfnet/dfnet.c index acc8fb48..d76a7574 100644 --- a/plugins/dfnet/dfnet.c +++ b/plugins/dfnet/dfnet.c @@ -99,17 +99,6 @@ int RECV(void *buf, int Size, int Mode) { return count; } -void sockGetIP(char *IPAddress) { - char str[256]; - struct hostent *host; - unsigned char *addr; - - gethostname(str, 256); - host = gethostbyname(str); - addr = host->h_addr_list[0]; - sprintf(IPAddress, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); -} - long CALLBACK NETopen(unsigned long *gpuDisp) { int ret = sockOpen(); diff --git a/plugins/dfnet/dfnet.h b/plugins/dfnet/dfnet.h index d5851218..62f38425 100644 --- a/plugins/dfnet/dfnet.h +++ b/plugins/dfnet/dfnet.h @@ -69,8 +69,6 @@ long sockOpen(); void sockCreateWaitDlg(); void sockDlgUpdate(); void sockDestroyWaitDlg(); - -void sockGetIP(char *IPAddress); int sockPing(); int ShowPauseDlg(); diff --git a/plugins/dfnet/gui.c b/plugins/dfnet/gui.c index 1f2dc69c..6425c9e5 100644 --- a/plugins/dfnet/gui.c +++ b/plugins/dfnet/gui.c @@ -38,17 +38,54 @@ void CFGconfigure() { cfgSysMessage(_("Nothing to configure")); } +#ifdef __linux__ + +#include <sys/ioctl.h> +#include <linux/if.h> + +#define MAXINTERFACES 16 + +void sockGetIP(char *IPAddress) { + int fd, intrface; + struct ifreq buf[MAXINTERFACES]; + struct ifconf ifc; + struct sockaddr_in addr; + + strcpy(IPAddress, "127.0.0.1"); + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = (caddr_t)buf; + if (!ioctl (fd, SIOCGIFCONF, (char *)&ifc)) { + intrface = ifc.ifc_len / sizeof(struct ifreq); + while (intrface-- > 0) { + if (!(ioctl(fd, SIOCGIFADDR, (char *)&buf[intrface]))) { + memcpy(&addr, &(buf[intrface].ifr_addr), sizeof(addr)); + strcpy(IPAddress, inet_ntoa(addr.sin_addr)); + break; + } + } + } + close(fd); + } +} + +#else + void sockGetIP(char *IPAddress) { - char str[256]; struct hostent *host; - unsigned char *addr; + char str[256]; gethostname(str, 256); host = gethostbyname(str); - addr = (unsigned char *)host->h_addr_list[0]; - sprintf(IPAddress, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); + + if (host != NULL) + strcpy(IPAddress, inet_ntoa(*((struct in_addr *)host->h_addr_list[0]))); + else strcpy(IPAddress, "127.0.0.1"); } +#endif + void OnCopyIP(GtkWidget *widget, gpointer user_data) { char str[256]; |
