Removed all code that uses OpenGL from Image.
[io/quag.git] / addons / Socket / source / IoIPAddress.c
blob827761fc760b2d4a98022f847db652b34525fce9
1 /*#io
2 IPAddress ioDoc(
3 docCopyright("Steve Dekorte", 2004)
4 docLicense("BSD revised")
5 docDescription("Object representation of an Internet Protocol Address.")
6 docCategory("Networking")
8 */
11 /*#io
12 docSlot("setHostName(hostName)",
13 "Translates hostName to an IP using asynchronous DNS and sets the host attribute. Returns self.")
16 #include "IoIPAddress.h"
17 #include "IoState.h"
18 #include "IoNumber.h"
19 #include "IoSeq.h"
21 #define IPADDRESS(self) ((IPAddress *)IoObject_dataPointer(self))
23 IoIPAddress *IoMessage_locals_addressArgAt_(IoMessage *self, IoObject *locals, int n)
25 IoObject *v = IoMessage_locals_valueArgAt_(self, locals, n);
27 if (!ISIPADDRESS(v))
29 IoMessage_locals_numberArgAt_errorForType_(self, locals, n, "IPAddress");
32 return v;
35 IPAddress *IoMessage_locals_rawIPAddressArgAt_(IoMessage *self, IoObject *locals, int n)
37 return IoIPAddress_rawIPAddress(IoMessage_locals_addressArgAt_(self, locals, n));
40 IPAddress *IoIPAddress_rawIPAddress(IoIPAddress *self)
42 return IPADDRESS(self);
45 IoTag *IoIPAddress_newTag(void *state)
47 IoTag *tag = IoTag_newWithName_("IPAddress");
48 IoTag_state_(tag, state);
49 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoIPAddress_rawClone);
50 IoTag_freeFunc_(tag, (IoTagFreeFunc *)IoIPAddress_free);
51 return tag;
54 IoIPAddress *IoIPAddress_proto(void *state)
56 IoObject *self = IoObject_new(state);
58 IoObject_tag_(self, IoIPAddress_newTag(state));
59 IoObject_setDataPointer_(self, IPAddress_new());
61 IoState_registerProtoWithFunc_((IoState *)state, self, IoIPAddress_proto);
64 IoMethodTable methodTable[] = {
65 {"setIp", IoIPAddress_setIp},
66 {"ip", IoIPAddress_ip},
68 {"setPort", IoIPAddress_setPort},
69 {"port", IoIPAddress_port},
71 {NULL, NULL},
73 IoObject_addMethodTable_(self, methodTable);
76 return self;
79 IoIPAddress *IoIPAddress_rawClone(IoIPAddress *proto)
81 IoObject *self = IoObject_rawClonePrimitive(proto);
82 IoObject_setDataPointer_(self, IPAddress_new());
83 return self;
86 IoIPAddress *IoIPAddress_new(void *state)
88 IoObject *proto = IoState_protoWithInitFunction_((IoState *)state, IoIPAddress_proto);
89 return IOCLONE(proto);
92 void IoIPAddress_free(IoIPAddress *self)
94 IPAddress_free(IPADDRESS(self));
97 // -----------------------------------------------------------
100 IoIPAddress *IoIPAddress_newWithIPAddress_size_(void *state,
101 struct sockaddr *address,
102 size_t size)
104 IoIPAddress *self = IoIPAddress_new(state);
105 free(DATA(self)->address);
106 DATA(self)->address = malloc(size);
107 DATA(self)->size = size;
108 memcpy(DATA(self)->address, address, size);
109 return self;
113 // ip
115 IoObject *IoIPAddress_setIp(IoIPAddress *self, IoObject *locals, IoMessage *m)
117 IoSeq *ip = IoMessage_locals_seqArgAt_(m, locals, 0);
118 char *ipString = IoSeq_asCString(ip);
119 IPAddress_setIp_(IPADDRESS(self), ipString);
120 return self;
123 IoObject *IoIPAddress_ip(IoIPAddress *self, IoObject *locals, IoMessage *m)
125 char *ip = IPAddress_ip(IPADDRESS(self));
126 return IOSYMBOL(ip);
129 // port
131 IoObject *IoIPAddress_setPort(IoIPAddress *self, IoObject *locals, IoMessage *m)
133 uint16_t port = IoMessage_locals_intArgAt_(m, locals, 0);
134 IPAddress_setPort_(IPADDRESS(self), port);
135 return self;
138 IoObject *IoIPAddress_port(IoIPAddress *self, IoObject *locals, IoMessage *m)
140 int port = IPAddress_port(IPADDRESS(self));
141 return IONUMBER(port);