From 61a9fd525d670b0c62728b47bc982e2274940795 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Mon, 8 Apr 2024 10:55:45 +0800 Subject: [PATCH] chore(examples): spilt `ip-addr.lua` Signed-off-by: Jianhui Zhao --- examples/netlink/ip-addr-add.lua | 11 +++++++++++ examples/netlink/ip-addr-del.lua | 11 +++++++++++ examples/netlink/ip-addr-get.lua | 15 +++++++++++++++ examples/netlink/ip-addr.lua | 27 --------------------------- 4 files changed, 37 insertions(+), 27 deletions(-) create mode 100755 examples/netlink/ip-addr-add.lua create mode 100755 examples/netlink/ip-addr-del.lua create mode 100755 examples/netlink/ip-addr-get.lua delete mode 100755 examples/netlink/ip-addr.lua diff --git a/examples/netlink/ip-addr-add.lua b/examples/netlink/ip-addr-add.lua new file mode 100755 index 0000000..c602b0d --- /dev/null +++ b/examples/netlink/ip-addr-add.lua @@ -0,0 +1,11 @@ +#!/usr/bin/env eco + +local addr = require 'eco.ip'.address + +local ifname = 'eth0' + +local ok, err = addr.add(ifname, { address = '192.168.1.2', prefix = 32, scope = 'global' }) +if not ok then + print('add fail:', err) + return +end diff --git a/examples/netlink/ip-addr-del.lua b/examples/netlink/ip-addr-del.lua new file mode 100755 index 0000000..9eb33d7 --- /dev/null +++ b/examples/netlink/ip-addr-del.lua @@ -0,0 +1,11 @@ +#!/usr/bin/env eco + +local addr = require 'eco.ip'.address + +local ifname = 'eth0' + +local ok, err = addr.del(ifname, { address = '192.168.1.2', prefix = 32 }) +if not ok then + print('del fail:', err) + return +end diff --git a/examples/netlink/ip-addr-get.lua b/examples/netlink/ip-addr-get.lua new file mode 100755 index 0000000..d03cd99 --- /dev/null +++ b/examples/netlink/ip-addr-get.lua @@ -0,0 +1,15 @@ +#!/usr/bin/env eco + +local addr = require 'eco.ip'.address + +local ifname = 'eth0' + +local res, err = addr.get(ifname) +if not res then + print('get fail:', err) + return +end + +for k, v in pairs(res) do + print(k .. ':', v) +end diff --git a/examples/netlink/ip-addr.lua b/examples/netlink/ip-addr.lua deleted file mode 100755 index da74e06..0000000 --- a/examples/netlink/ip-addr.lua +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env eco - -local addr = require 'eco.ip'.address - -local ifname = 'eth0' - -local ok, err = addr.add(ifname, { address = '192.168.1.2', prefix = 32, scope = 'global' }) -if not ok then - print('add fail:', err) - return -end - -local res, err = addr.get(ifname) -if not res then - print('get fail:', err) - return -end - -for k, v in pairs(res) do - print(k .. ':', v) -end - -ok, err = addr.del(ifname, { address = '192.168.1.2', prefix = 32 }) -if not ok then - print('del fail:', err) - return -end