diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2010-05-13 06:59:35 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2010-05-13 06:59:35 +0000 |
| commit | d923b4329d7e2a8e48c57f503514bfeeca7c6b87 (patch) | |
| tree | 28939b4ad90ada279567edf42794b0ba139528fa /plugins | |
| parent | dd5ee8b8101f704777a05805f1d88c0d40e60cf7 (diff) | |
| download | pcsxr-d923b4329d7e2a8e48c57f503514bfeeca7c6b87.tar.gz | |
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@47952 e17a0e51-4ae3-4d35-97c3-1a29b211df97
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]; |
