A simple ifconfig to show a list of NICs and mac addresses

This commit is contained in:
Ali Mashtizadeh 2015-01-23 13:02:31 -08:00
parent 92e5ae902a
commit 10bf52f68f
9 changed files with 97 additions and 6 deletions

View File

@ -162,6 +162,7 @@ CopyTree('build/include/machine', 'sys/' + env['ARCH'] + '/include', env)
SConscript('sys/SConscript', variant_dir='build/sys')
SConscript('lib/libc/SConscript', variant_dir='build/lib/libc')
SConscript('bin/shell/SConscript', variant_dir='build/bin/shell')
SConscript('sbin/ifconfig/SConscript', variant_dir='build/sbin/ifconfig')
SConscript('sbin/init/SConscript', variant_dir='build/sbin/init')
SConscript('tests/SConscript', variant_dir='build/tests')
@ -183,6 +184,7 @@ if env["BOOTDISK"] == "1":
bootdisk = env.BuildImage('#build/bootdisk.img', '#release/bootdisk.manifest')
Depends(bootdisk, "#build/tools/newfs_o2fs/newfs_o2fs")
Depends(bootdisk, "#build/bin/shell/shell")
Depends(bootdisk, "#build/sbin/ifconfig/ifconfig")
Depends(bootdisk, "#build/sbin/init/init")
Depends(bootdisk, "#build/sys/castor")
Depends(bootdisk, "#build/tests/threadtest")

View File

@ -3,6 +3,7 @@
#define __SYSCALL_H__
#include <sys/stat.h>
#include <sys/nic.h>
uint64_t OSTime();
uint64_t OSGetPID();
@ -32,5 +33,8 @@ int OSThreadExit(uint64_t status);
int OSThreadSleep(uint64_t time);
int OSThreadWait(uint64_t tid);
// Network
int OSNICStat(uint64_t nicNo, NIC *nic);
#endif /* __SYSCALL_H__ */

View File

@ -134,7 +134,16 @@ fputs(const char *str, FILE *fh)
int
puts(const char *str)
{
return fputs(str, stdout);
int status, status2;
status = fputs(str, stdout);
if (status < 0)
return EOF;
status2 = fputc('\n', stdout);
if (status2 < 0)
return EOF;
return status;
}
int

View File

@ -121,3 +121,9 @@ OSThreadWait(uint64_t tid)
return syscall(SYSCALL_THREADWAIT, tid);
}
int
OSNICStat(uint64_t nicNo, NIC *nic)
{
return syscall(SYSCALL_NICSTAT, nicNo, nic);
}

View File

@ -8,6 +8,7 @@ DIR /
FILE shell build/bin/shell/shell
END
DIR sbin
FILE ifconfig build/sbin/ifconfig/ifconfig
FILE init build/sbin/init/init
END
DIR tests

21
sbin/ifconfig/SConscript Normal file
View File

@ -0,0 +1,21 @@
import sys
Import('env')
ifconfig_env = env.Clone()
src = [ ]
src_common = [
"ifconfig.c"
]
src.append(src_common)
ifconfig_env.Append(LINKFLAGS = ['-nostdlib'])
ifconfig_env.Append(CPPFLAGS = ['-nostdinc'])
ifconfig_env.Append(CPPPATH = ['#build/include'])
ifconfig_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
ifconfig_env.Program("ifconfig", src)

26
sbin/ifconfig/ifconfig.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <errno.h>
#include <syscall.h>
int
main(int argc, const char *argv[])
{
int i;
uint64_t status;
NIC nic;
printf("Network Status\n");
for (i = 0; i < 32; i++) {
status = OSNICStat(i, &nic);
if (status == ENOENT)
continue;
printf("nic%d:\n", nic.nicNo);
printf(" ether %02x:%02x:%02x:%02x:%02x:%02x\n",
nic.mac[0], nic.mac[1], nic.mac[2],
nic.mac[3], nic.mac[4], nic.mac[5]);
}
}

View File

@ -35,14 +35,14 @@
#define SYSCALL_THREADWAIT 0x33
// Network
#define SYSCALL_SOCKET 0x40
#define SYSCALL_BIND 0x41
#define SYSCALL_CONNECT 0x42
#define SYSCALL_LISTEN 0x43
#define SYSCALL_SHUTDOWN 0x44
#define SYSCALL_NICSTAT 0x40
uint64_t Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
uint64_t a3, uint64_t a4, uint64_t a5);
#define SYSCALL_PACK(_errcode, _val) ((_errcode << 32) | (_val))
#define SYSCALL_ERRCODE(_result) (_result >> 32)
#define SYSCALL_VALUE(_result) (_result & 0xFFFFFFFF)
#endif /* __SYS_SYSCALL_H__ */

View File

@ -15,6 +15,7 @@
#include <sys/disk.h>
#include <sys/vfs.h>
#include <sys/vfsuio.h>
#include <sys/nic.h>
Handle *Console_OpenHandle();
@ -449,6 +450,25 @@ Syscall_ThreadWait(uint64_t tid)
}
}
uint64_t
Syscall_NICStat(uint64_t nicNo, uint64_t user_stat)
{
int status;
NIC *nic;
nic = NIC_GetByID(nicNo);
if (nic == NULL) {
return ENOENT;
}
status = CopyOut(nic, user_stat, sizeof(NIC));
if (status != 0) {
return status;
}
return 0;
}
uint64_t
Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
uint64_t a3, uint64_t a4, uint64_t a5)
@ -497,6 +517,8 @@ Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
return Syscall_ThreadSleep(a1);
case SYSCALL_THREADWAIT:
return Syscall_ThreadWait(a1);
case SYSCALL_NICSTAT:
return Syscall_NICStat(a1, a2);
default:
return (uint64_t)-1;
}