Netzwerk unter MacOS
-
Ich kann auf meinem PC immer nur meine Netzwerksachen auf Windows und Linux testen. Zu MacOS habe ich keinen Zugriff. Jetzt steht aber bei Wikipedia:
http://de.wikipedia.org/wiki/Mac_OS_X , dass MacOSX auf einen open source Kernel namens Darwin basiert. Mit PearPC könnte man ja sicher diesen Kernel auf einem PC emulieren?Im Grunde bräuchte ich nur folgendes zum testen:
Eine Konsole sowie Netzwerkfunktionalität.Oder gibt es eine BSD Version, die in Sachen Sockets exakt so agiert, wie MacOSX?
Ein Beispiel:
#include <string.h> #include <net/if.h> #include <sys/socket.h> #include <netinet/in.h> #ifdef __APPLE__ # include <sys/sockio.h> #else # include <linux/sockios.h> #endif #define MAX_INTERFACES 64 #define TRUE 1 #define FALSE 0 int GetNetworkAdapter(char *Device, char MAC[6], int *Address, int *Netmask, int *Broadcast) { int Socket; struct ifreq *pInterface; struct ifconf Config; char Buffer[MAX_INTERFACES*sizeof(struct ifreq)]; int Count, I; Socket = socket(AF_INET, SOCK_DGRAM, 0); if(Socket == -1) return FALSE; Config.ifc_len = sizeof(Buffer); Config.ifc_buf = Buffer; if(ioctl(Socket, SIOCGIFCONF, &Config) != 0) { close(Socket); return FALSE; } Count = Config.ifc_len/sizeof(struct ifreq); pInterface = Config.ifc_req; for(I = 0; I < Count; I++) { if(pInterface->ifr_addr.sa_family == AF_INET && strncmp(pInterface->ifr_name, "eth", 3) == 0) { strcpy(Device, pInterface->ifr_name); *Address = ntohl(((struct sockaddr_in *)&pInterface->ifr_addr)->sin_addr.s_addr); ioctl(Socket, SIOCGIFHWADDR, pInterface); memcpy(MAC, &pInterface->ifr_hwaddr.sa_data, 6); ioctl(Socket, SIOCGIFNETMASK, pInterface); *Netmask = ntohl(((struct sockaddr_in *)&pInterface->ifr_netmask)->sin_addr.s_addr); *Broadcast = *Address | ~(*Netmask); close(Socket); return TRUE; } pInterface++; } close(Socket); return FALSE; }
Das funktioniert unter Linux ganz gut unter MacOSX hat mir ein Tester folgendes zurück gesendet:
Building Modules
Compiling:bsd.c
In file included from /Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:2:
/usr/include/net/if.h:213: error: field 'ifru_addr' has incomplete type
/usr/include/net/if.h:214: error: field 'ifru_dstaddr' has incomplete type
/usr/include/net/if.h:215: error: field 'ifru_broadaddr' has incomplete type
/usr/include/net/if.h:250: error: field 'ifra_addr' has incomplete type
/usr/include/net/if.h:251: error: field 'ifra_broadaddr' has incomplete type
/usr/include/net/if.h:252: error: field 'ifra_mask' has incomplete type
/usr/include/net/if.h:318: error: field 'addr' has incomplete type
/usr/include/net/if.h:319: error: field 'dstaddr' has incomplete type
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c: In function 'GetNetworkAdapter':
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:45: error: 'SIOCGIFHWADDR' undeclared (first use in this function)
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:45: error: (Each undeclared identifier is reported only once
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:45: error: for each function it appears in.)
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:46: error: 'struct ifreq' has no member named 'ifr_hwaddr'
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
Build Error: failed to compile /Applications/DEV/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c
Process completeWenn die Berkleysockets Plattform unabhängig sind, warum benötigt man dann unterschiedliche Header?
Naja, ich muss auch zugeben, ich bin kein großer C Programmierer.
mfg olli
-
Der Kernel von MacOS ist frei und heißt Darwin. Das ist im Grunde ein FreeBSD was auf einem Mach-Kernel läuft. Wenn du dich an die im POSIX-Standard definierten APIs hällst, sollte sein portieren kein Problem sein. Aber gerade ioctl-Flags sind ja oft System abhängig.
-
Dieser Thread wurde von Moderator/in rüdiger aus dem Forum Rund um die Programmierung in das Forum Linux/Unix verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.