Windows fixes for NetworkAdapter addon
[io.git] / addons / NetworkAdapter / source / IoNetworkAdapter.c
blobfb1ccc00808feb9f8ed7cadca1bec8f9f85d63e6
1 /*#io
2 NetworkAdapter ioDoc(
3 docCopyright("Rich Collins", 2007)
4 docLicense("BSD revised")
5 docCategory("Networking")
6 docDescription("Interface to network adapter functionality")
7 */
9 #include "IoNetworkAdapter.h"
10 #include "IoState.h"
11 #include "IoSeq.h"
12 #include "OSXMacAddress.h"
13 #include "WindowsMacAddress.h"
15 IoTag *IoNetworkAdapter_newTag(void *state)
17 IoTag *tag = IoTag_newWithName_("NetworkAdapter");
18 IoTag_state_(tag, state);
19 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoNetworkAdapter_rawClone);
20 return tag;
23 IoNetworkAdapter *IoNetworkAdapter_proto(void *state)
25 IoNetworkAdapter *self = IoObject_new(state);
26 IoObject_tag_(self, IoNetworkAdapter_newTag(state));
28 IoState_registerProtoWithFunc_(state, self, IoNetworkAdapter_proto);
31 IoMethodTable methodTable[] = {
32 {"macAddress", IoNetworkAdapter_macAddress},
33 {NULL, NULL},
35 IoObject_addMethodTable_(self, methodTable);
37 return self;
40 IoNetworkAdapter *IoNetworkAdapter_rawClone(IoNetworkAdapter *proto)
42 IoNetworkAdapter *self = IoObject_rawClonePrimitive(proto);
43 return self;
46 IoNetworkAdapter *IoNetworkAdapter_new(void *state)
48 IoNetworkAdapter *proto = IoState_protoWithInitFunction_(state, IoNetworkAdapter_proto);
49 return IOCLONE(proto);
52 /* ----------------------------------------------------------- */
54 IoSeq *IoNetworkAdapter_macAddress(IoNetworkAdapter *self, IoObject *locals, IoMessage *m)
56 /*#io
57 docSlot("macAddress", "Returns the MAC address for the primary network adapter in a Hex string.")
60 #if defined(WIN32) || defined(__APPLE__) || defined(MACOSX)
61 char * mac = macAddress();
62 return mac ? IOSYMBOL(mac) : IONIL(self);
63 #else
64 return IONIL(self);
65 #endif