BlueCrab wrote:Also, if you have DHCP on your network, which I'm sure almost everyone probably does, the built-in stack supports DHCP as well. I don't believe it will ever by default use DHCP to configure things, but that's just a simple case of calling net_dhcp_request() to actually handle setting that up.
I take back the statement of it never automatically configuring things. I took another look at the code, and the built-in network code will try to initialize DHCP if the network device does not have a IP address after the initialization happens.
Practically, this means that unless there's stuff in the Dreamcast's flashrom for a static configuration of the BBA, it will always try DHCP to configure it at the end of net_init() (whether it gets called implicitly through the KOS_INIT_FLAGS or directly in your code).
Anyway... sorry for not putting up an example program for using KOS' built-in networking, but I honestly couldn't think of anything to show an example of. Really, there's little difference between KOS' built-in network stack and that which you would find on anything else that has BSD sockets. The only differences at the moment are:
- No select() or poll() -- This is something I'd like to fix sometime soon.
- No fcntl() or ioctl() -- In most cases the only time you'd use these is to set a socket to be non-blocking. There's a function for that specific case: fs_socket_setflags() which is in <kos/fs_socket.h>.
- No socket types available other than UDP.
I wrote the sockets code to mostly comply with the Single UNIX Specification, so it should very much match what you'd expect on any computer.
Anyway, here's a really lame example of something somewhat interesting you can do with the KOS network stack... A really crappy "ping" program:
Code: Select all
/* KallistiOS ##version##
ping.c
Copyright (C) 2009 Lawrence Sebald
This example is a very basic "ping" program, much like you might find on
any computer. However, this version lacks many of the niceties you might find
on a real OS' ping program.
*/
#include <stdio.h>
#include <arch/arch.h>
#include <kos/net.h>
#include <kos/thread.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
#define DATA_SIZE 56
int main(int argc, char *argv[]) {
uint8 addr[4] = { 127, 0, 0, 1 };
uint8 data[DATA_SIZE];
int i;
for(i = 0; i < DATA_SIZE; ++i) {
data[i] = (uint8)i;
}
for(i = 0; i < 10; ++i) {
net_icmp_send_echo(net_default_dev, addr, data, DATA_SIZE);
thd_sleep(250);
}
thd_sleep(2 * 1000);
return 0;
}