KOS PPP support over the Modem

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

KOS PPP support over the Modem

Post by BlueCrab »

This evening, I have finally finished working on one of the most requested features that had been missing from KOS for all these years -- the ability to use the modem to connect to the Internet. KOS has had support for using the modem itself for a long time (the current modem driver was added around ten years ago now), but there hasn't ever been a working way of actually using that with the network stack. Until now, of course.

I had first started working on a PPP library about 7 years ago, only to shelve it for various reasons, including the inability to actually test it to see if it worked. Well, about 2 weeks ago, I decided to pick up where I left off, and restart work on a PPP library. Most of the code has been written in that 2 week span, although there are some bits and pieces from my old library from 2007. The library itself contains support code for using PPP over both the modem and over a coder's cable, and is fully linked in with the IPv4 portion of the network stack (no IPv6 support just yet, but I'll probably do that at some point, just for completeness). I've tested using the library to connect to a Raspberry Pi over the coder's cable (USB, obviously), and to connect to a Netopia R2020 router over the modem with success on both counts.

What I'd like is if people who might have a coder's cable of some sort and a Dreamcast modem laying around might be able to test out the library with a real Dialup ISP. That's the one thing I haven't been able to test the code with as of yet that I'd like to have done. If you want to do so, first make sure you have your git copy of KOS up-to-date, re-run make to build libppp (it's in the addons tree) and the other assorted updates to the repo, and then compile the following program ("kos-cc -o ppptest.elf ppptest.c -lppp" will do the trick, assuming of course that you name the file ppptest.c):

Code: Select all

#include <stdio.h>
#include <kos/dbglog.h>

#include <arch/arch.h>

#include <ppp/ppp.h>
#include <kos/net.h>

KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);

int main(int argc, char *argv[]) {
    int i;

    ppp_init();

    i = ppp_modem_init("12", 1, NULL);
    if(i < 0)
        return 0;

    ppp_set_login("dream", "cast");
    i = ppp_connect();

    if(i == -1) {
        printf("Link establishment failed!\n");
        return 0;
    }

    printf("Pinging the other side of the link (%d.%d.%d.%d)\n",
           net_default_dev->gateway[0], net_default_dev->gateway[1],
           net_default_dev->gateway[2], net_default_dev->gateway[3]);

    for(i = 0; i < 10; ++i) {
        net_icmp_send_echo(net_default_dev, net_default_dev->gateway, 1234, i,
                           NULL, 0);
        thd_sleep(500);
    }

    printf("Pinging sylverant.net (67.222.144.120)\n");
    for(i = 0; i < 10; ++i) {
        uint8 addr[4] = { 67, 222, 144, 120 };
        net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
        thd_sleep(500);
    }

    ppp_shutdown();
    return 0;
}
You'll probably want to change the phone number (the first argument to ppp_modem_init()), and the username/password pair (ppp_set_login()).
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: KOS PPP support over the Modem

Post by SWAT »

Good job! As always beautiful code, look nice.
In the network stack are still need to add DNS functions such as gethostbyname etc. If you do it will be just fine!
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS PPP support over the Modem

Post by BlueCrab »

A couple of different DNS-related things are actually next on my list of things to do.

Granted one of the things has nothing to do with KOS... but that's beside the point. :wink:
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS PPP support over the Modem

Post by BlueCrab »

SWAT wrote:In the network stack are still need to add DNS functions such as gethostbyname etc. If you do it will be just fine!
Done as of commit 1b7264, documentation is here (although it follows POSIX pretty much completely, other than flags that aren't supported).

As with most systems, gethostbyname() should be avoided in favor of getaddrinfo().
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: KOS PPP support over the Modem

Post by SWAT »

Very good! Big thanks!
Image
Crystal Triad
DCEmu Newbie
DCEmu Newbie
Posts: 3
Joined: Fri Apr 18, 2014 1:01 am
Has thanked: 0
Been thanked: 0

Re: KOS PPP support over the Modem

Post by Crystal Triad »

Hello, will be there any examples for this?

Thanks,

- Crystal Triad
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS PPP support over the Modem

Post by BlueCrab »

Crystal Triad wrote:Hello, will be there any examples for this?

Thanks,

- Crystal Triad
Of the PPP stuff? Sure at some point (hopefully soon) I'll throw one together that reads the settings from the flashrom and attempts to connect. Of course, there's an example in the first post here that does most of that already. :wink:
TheReverendGregory
DCEmu Newbie
DCEmu Newbie
Posts: 1
Joined: Thu Aug 21, 2014 6:37 pm
Has thanked: 0
Been thanked: 0

Re: KOS PPP support over the Modem

Post by TheReverendGregory »

I know it would depend on the developer wanting to implement it, but does this new support in KOS open the door for games like DOOM having modem play support?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS PPP support over the Modem

Post by BlueCrab »

In theory, sure. Anything written with KOS that has network support could easily be made to support the modem using this library.
Post Reply