Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / wslua / wslua_address.c
blob7bba186382e9e9c7223c210e04e0ec0a5c21ad6a
1 /*
2 * wslua_address.c
4 * Wireshark's interface to the Lua Programming Language
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
8 * (c) 2011, Stig Bjorlykke <stig@bjorlykke.org>
9 * (c) 2014, Hadriel Kaplan <hadrielk@yahoo.com>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * SPDX-License-Identifier: GPL-2.0-or-later
18 #include "config.h"
20 #include "wslua.h"
22 #include <epan/addr_resolv.h>
24 /* WSLUA_CONTINUE_MODULE Pinfo */
27 WSLUA_CLASS_DEFINE(Address,FAIL_ON_NULL("Address")); /* Represents an address. */
29 WSLUA_CONSTRUCTOR Address_ip(lua_State* L) {
30 /* Creates an Address Object representing an IPv4 address. */
32 #define WSLUA_ARG_Address_ip_HOSTNAME 1 /* The address or name of the IP host. */
33 Address addr = (Address)g_malloc(sizeof(address));
34 uint32_t ip_addr;
35 const char* name = luaL_checkstring(L,WSLUA_ARG_Address_ip_HOSTNAME);
37 if (! get_host_ipaddr(name, &ip_addr)) {
38 ip_addr = 0;
41 alloc_address_wmem(NULL, addr, AT_IPv4, 4, &ip_addr);
42 pushAddress(L,addr);
43 WSLUA_RETURN(1); /* The Address object. */
46 WSLUA_CONSTRUCTOR Address_ipv6(lua_State* L) {
47 /* Creates an Address Object representing an IPv6 address. */
49 #define WSLUA_ARG_Address_ipv6_HOSTNAME 1 /* The address or name of the IP host. */
50 Address addr = (Address)g_malloc(sizeof(address));
51 ws_in6_addr ip_addr;
52 const char* name = luaL_checkstring(L,WSLUA_ARG_Address_ipv6_HOSTNAME);
54 if (!get_host_ipaddr6(name, &ip_addr)) {
55 memset(&ip_addr, 0, sizeof(ip_addr));
58 alloc_address_wmem(NULL, addr, AT_IPv6, sizeof(ip_addr.bytes), &ip_addr.bytes);
59 pushAddress(L,addr);
60 WSLUA_RETURN(1); /* The Address object */
63 WSLUA_CONSTRUCTOR Address_ether(lua_State *L) {
64 /* Creates an Address Object representing an Ethernet address. */
66 #define WSLUA_ARG_Address_ether_ETH 1 /* The Ethernet address. */
67 Address addr = (Address)g_malloc(sizeof(address));
68 const char *name = luaL_checkstring(L, WSLUA_ARG_Address_ether_ETH);
69 uint8_t eth_buf[6];
71 if(!str_to_eth(name, eth_buf))
72 memset(eth_buf, 0, sizeof(eth_buf));
74 alloc_address_wmem(NULL, addr, AT_ETHER, sizeof(eth_buf), eth_buf);
75 pushAddress(L, addr);
76 WSLUA_RETURN(1); /* The Address object. */
79 #if 0
80 /* TODO */
81 static int Address_ss7(lua_State* L) {
82 Address addr = g_malloc(sizeof(address));
84 /* alloc_address() */
86 pushAddress(L,addr);
87 return 1;
89 static int Address_sna(lua_State* L) {
90 Address addr = g_malloc(sizeof(address));
92 /* alloc_address() */
94 pushAddress(L,addr);
95 return 1;
97 static int Address_atalk(lua_State* L) {
98 Address addr = g_malloc(sizeof(address));
100 /* alloc_address() */
102 pushAddress(L,addr);
103 return 1;
105 static int Address_vines(lua_State* L) {
106 Address addr = g_malloc(sizeof(address));
108 /* alloc_address() */
110 pushAddress(L,addr);
111 return 1;
113 static int Address_osi(lua_State* L) {
114 Address addr = g_malloc(sizeof(address));
116 /* alloc_address() */
118 pushAddress(L,addr);
119 return 1;
121 static int Address_arcnet(lua_State* L) {
122 Address addr = g_malloc(sizeof(address));
124 /* alloc_address() */
126 pushAddress(L,addr);
127 return 1;
129 static int Address_fc(lua_State* L) {
130 Address addr = g_malloc(sizeof(address));
132 /* alloc_address() */
134 pushAddress(L,addr);
135 return 1;
137 static int Address_string(lua_State* L) {
138 Address addr = g_malloc(sizeof(address));
140 /* alloc_address() */
142 pushAddress(L,addr);
143 return 1;
145 static int Address_eui64(lua_State* L) {
146 Address addr = g_malloc(sizeof(address));
148 /* alloc_address() */
150 pushAddress(L,addr);
151 return 1;
153 static int Address_uri(lua_State* L) {
154 Address addr = g_malloc(sizeof(address));
156 /* alloc_address() */
158 pushAddress(L,addr);
159 return 1;
161 static int Address_tipc(lua_State* L) {
162 Address addr = g_malloc(sizeof(address));
164 /* alloc_address() */
166 pushAddress(L,addr);
167 return 1;
169 #endif
171 WSLUA_METHODS Address_methods[] = {
172 WSLUA_CLASS_FNREG(Address,ip),
173 WSLUA_CLASS_FNREG_ALIAS(Address,ipv4,ip),
174 WSLUA_CLASS_FNREG(Address,ipv6),
175 WSLUA_CLASS_FNREG(Address,ether),
176 #if 0
177 WSLUA_CLASS_FNREG_ALIAS(Address,ss7pc,ss7),
178 WSLUA_CLASS_FNREG(Address,sna},
179 WSLUA_CLASS_FNREG(Address,atalk),
180 WSLUA_CLASS_FNREG(Address,vines),
181 WSLUA_CLASS_FNREG(Address,osi),
182 WSLUA_CLASS_FNREG(Address,arcnet),
183 WSLUA_CLASS_FNREG(Address,fc),
184 WSLUA_CLASS_FNREG(Address,string),
185 WSLUA_CLASS_FNREG(Address,eui64),
186 WSLUA_CLASS_FNREG(Address,uri),
187 WSLUA_CLASS_FNREG(Address,tipc),
188 #endif
189 { NULL, NULL }
192 WSLUA_METAMETHOD Address__tostring(lua_State* L) {
193 Address addr = checkAddress(L,1);
194 char *str = address_to_display(NULL, addr);
196 lua_pushstring(L, str);
198 wmem_free(NULL, str);
200 WSLUA_RETURN(1); /* The string representing the address. */
203 /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
204 static int Address__gc(lua_State* L) {
205 Address addr = toAddress(L,1);
207 if (addr) {
208 free_address(addr);
209 g_free(addr);
212 return 0;
215 WSLUA_METAMETHOD Address__eq(lua_State* L) { /* Compares two Addresses. */
216 Address addr1 = checkAddress(L,1);
217 Address addr2 = checkAddress(L,2);
218 bool result = false;
220 if (addresses_equal(addr1, addr2))
221 result = true;
223 lua_pushboolean(L,result);
225 return 1;
228 WSLUA_METAMETHOD Address__le(lua_State* L) { /* Compares two Addresses. */
229 Address addr1 = checkAddress(L,1);
230 Address addr2 = checkAddress(L,2);
231 bool result = false;
233 if (cmp_address(addr1, addr2) <= 0)
234 result = true;
236 lua_pushboolean(L,result);
238 return 1;
241 WSLUA_METAMETHOD Address__lt(lua_State* L) { /* Compares two Addresses. */
242 Address addr1 = checkAddress(L,1);
243 Address addr2 = checkAddress(L,2);
244 bool result = false;
246 if (cmp_address(addr1, addr2) < 0)
247 result = true;
249 lua_pushboolean(L,result);
251 return 1;
254 WSLUA_META Address_meta[] = {
255 WSLUA_CLASS_MTREG(Address,tostring),
256 WSLUA_CLASS_MTREG(Address,eq),
257 WSLUA_CLASS_MTREG(Address,le),
258 WSLUA_CLASS_MTREG(Address,lt),
259 { NULL, NULL }
263 int Address_register(lua_State *L) {
264 WSLUA_REGISTER_CLASS(Address);
265 return 0;
270 * Editor modelines - https://www.wireshark.org/tools/modelines.html
272 * Local variables:
273 * c-basic-offset: 4
274 * tab-width: 8
275 * indent-tabs-mode: nil
276 * End:
278 * vi: set shiftwidth=4 tabstop=8 expandtab:
279 * :indentSize=4:tabSize=8:noTabs=true: