aboutsummaryrefslogtreecommitdiff
path: root/docs/j1demo/firmware/ip0.fs
blob: 1631d5fd32fc52744c2868a4dfe91e2225c042cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
( Variables for IP networking                JCB 13:21 08/24/10)

module[ ip0"
create ip-id-counter    d# 2 allot
create ip-addr          d# 4 allot
create ip-router        d# 4 allot
create ip-subnetmask    d# 4 allot
create ip-dns           d# 4 allot
create icmp-alarm-ptr   d# 1 allot

: ethaddr-broadcast
    h# ffff dup dup
;

: net-my-ip
    ip-addr 2@
;

: ethaddr-pretty-w
    dup endian hex2
    [char] : emit
    hex2
;

: ethaddr-pretty
    swap rot
    ethaddr-pretty-w [char] : emit
    ethaddr-pretty-w [char] : emit
    ethaddr-pretty-w
;

: ip-pretty-byte
    h# ff and
    \ d# 0 u.r
    hex2
;

: ip-pretty-2
    dup swab ip-pretty-byte [char] . emit ip-pretty-byte
;

: ip-pretty
    swap
    ip-pretty-2 [char] . emit
    ip-pretty-2
;

( IP address literals                        JCB 14:30 10/26/10)

================================================================

It is neat to write IP address literals e.g.
ip# 192.168.0.1

================================================================

meta

: octet# ( c -- u ) 0. rot parse >number throw 2drop ;

: ip# 
    [char] . octet# 8 lshift
    [char] . octet# or do-number
    [char] . octet# 8 lshift
    bl octet#       or do-number
;

target

]module