KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
netcfg.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  kos/netcfg.h
4  Copyright (C) 2003 Dan Potter
5 
6 */
7 
8 #ifndef __KOS_NETCFG_H
9 #define __KOS_NETCFG_H
10 
11 /** \file kos/netcfg.h
12  \brief Network configuration interface.
13 
14  This file provides a common interface for reading and writing the network
15  configuration on KOS. The interface can read from the flashrom on the
16  Dreamcast or from a file (such as on a VMU or the like), and can write data
17  back to a file.
18 
19  The data that is written out by this code is written in a relatively easy to
20  parse text-based format.
21 
22  \author Dan Potter
23 */
24 
25 #include <sys/cdefs.h>
26 __BEGIN_DECLS
27 
28 #include <arch/types.h>
29 
30 /** \defgroup netcfg_methods Network connection methods
31 
32  These constants give the list of network connection methods that are
33  supported by the netcfg_t type. One of these will be in the method field of
34  objects of that type.
35 
36  @{
37 */
38 #define NETCFG_METHOD_DHCP 0 /**< \brief Use DHCP to configure. */
39 #define NETCFG_METHOD_STATIC 1 /**< \brief Static network configuration. */
40 #define NETCFG_METHOD_PPPOE 4 /**< \brief Use PPPoE. */
41 /** @} */
42 
43 /** \defgroup netcfg_srcs Network configuration sources
44 
45  These constants give the list of places that the network configuration might
46  be read from. One of these constants should be in the src field of objects
47  of type netcfg_t.
48 
49  @{
50 */
51 #define NETCFG_SRC_VMU 0 /**< \brief Read from a VMU. */
52 #define NETCFG_SRC_FLASH 1 /**< \brief Read from the flashrom. */
53 #define NETCFG_SRC_CWD 2 /**< \brief Read from the working directory. */
54 #define NETCFG_SRC_CDROOT 3 /**< \brief Read from the root of the CD. */
55 /** @} */
56 
57 /** \brief Network configuration information.
58 
59  This structure contains information about the network configuration of the
60  system, as set up by the user.
61 
62  \headerfile kos/netcfg.h
63 */
64 typedef struct netcfg {
65  /** \brief Where was this configuration read from?
66  \see netcfg_srcs
67  */
68  int src;
69 
70  /** \brief How should the network be configured?
71  \see netcfg_methods
72  */
73  int method;
74 
75  uint32 ip; /**< \brief IPv4 address of the console */
76  uint32 gateway; /**< \brief IPv4 address of the gateway/router. */
77  uint32 netmask; /**< \brief Network mask for the local net. */
78  uint32 broadcast; /**< \brief Broadcast address for the local net. */
79  uint32 dns[2]; /**< \brief IPv4 address of the DNS servers. */
80  char hostname[64]; /**< \brief DNS/DHCP hostname. */
81  char email[64]; /**< \brief E-Mail address. */
82  char smtp[64]; /**< \brief SMTP server address. */
83  char pop3[64]; /**< \brief POP3 server address. */
84  char pop3_login[64]; /**< \brief POP3 server username. */
85  char pop3_passwd[64]; /**< \brief POP3 server password. */
86  char proxy_host[64]; /**< \brief Proxy server address. */
87  int proxy_port; /**< \brief Proxy server port. */
88  char ppp_login[64]; /**< \brief PPP Username. */
89  char ppp_passwd[64]; /**< \brief PPP Password. */
90  char driver[64]; /**< \brief Driver program filename (if any). */
91 } netcfg_t;
92 
93 /** \brief Load network configuration from a file.
94 
95  This function loads the network configuration that is stored in the given
96  file to the network configuration structure passed in. This function will
97  also handle files on the VMU with the VMU specific header attached without
98  any extra work required.
99 
100  \param fn The file to read the configuration from.
101  \param out Buffer to store the parsed configuration.
102  \return 0 on success, <0 on failure.
103 */
104 int netcfg_load_from(const char * fn, netcfg_t * out);
105 
106 /** \brief Load network configuration from the Dreamcast's flashrom.
107 
108  This function loads the network configuration that is stored in flashrom of
109  the Dreamcast, parsing it into a netcfg_t.
110 
111  \param out Buffer to store the parsed configuration.
112  \return 0 on success, <0 on failure.
113  \note This currently does not read the configuration stored by
114  the PlanetWeb browser at all.
115 */
116 int netcfg_load_flash(netcfg_t * out);
117 
118 /** \brief Load network configuration.
119 
120  This function loads the network configuration data, searching in multiple
121  locations to attempt to find a file with a stored configurtion. This
122  function will attempt to read the configuration from each VMU first (from
123  a file named net.cfg), then it will try the flashrom, followed by the
124  current working directory, and lastly the root of the CD.
125 
126  \param out Buffer to store the parsed configuraiton.
127  \return 0 on success, <0 on failure.
128 */
129 int netcfg_load(netcfg_t * out);
130 
131 /** \brief Save network configuration to a file.
132 
133  This function saves the network configuration to the specified file. This
134  function will automatically prepend the appropriate header if it is saved
135  to a VMU.
136 
137  \param fn The file to save to.
138  \param cfg The configuration to save.
139  \return 0 on success, <0 on failure.
140 */
141 int netcfg_save_to(const char * fn, const netcfg_t * cfg);
142 
143 /** \brief Save network configuration to the first available VMU.
144 
145  This function saves the network configuration to first VMU that it finds. It
146  will not retry if the first VMU doesn't have enough space to hold the file.
147 
148  \param cfg The configuration to save.
149  \return 0 on success, <0 on failure.
150 */
151 int netcfg_save(const netcfg_t * cfg);
152 
153 __END_DECLS
154 
155 #endif /* __KOS_NETCFG_H */
156 
Common integer types.
int netcfg_load_from(const char *fn, netcfg_t *out)
Load network configuration from a file.
int proxy_port
Proxy server port.
Definition: netcfg.h:87
int netcfg_load_flash(netcfg_t *out)
Load network configuration from the Dreamcast's flashrom.
int netcfg_save_to(const char *fn, const netcfg_t *cfg)
Save network configuration to a file.
Network configuration information.
Definition: netcfg.h:64
char pop3_login[64]
POP3 server username.
Definition: netcfg.h:84
char pop3[64]
POP3 server address.
Definition: netcfg.h:83
uint32 ip
IPv4 address of the console.
Definition: netcfg.h:75
int netcfg_save(const netcfg_t *cfg)
Save network configuration to the first available VMU.
int netcfg_load(netcfg_t *out)
Load network configuration.
char driver[64]
Driver program filename (if any).
Definition: netcfg.h:90
int method
How should the network be configured?
Definition: netcfg.h:73
int src
Where was this configuration read from?
Definition: netcfg.h:68
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
uint32 gateway
IPv4 address of the gateway/router.
Definition: netcfg.h:76
char smtp[64]
SMTP server address.
Definition: netcfg.h:82
char proxy_host[64]
Proxy server address.
Definition: netcfg.h:86
uint32 netmask
Network mask for the local net.
Definition: netcfg.h:77
uint32 broadcast
Broadcast address for the local net.
Definition: netcfg.h:78
uint32 dns[2]
IPv4 address of the DNS servers.
Definition: netcfg.h:79
char email[64]
E-Mail address.
Definition: netcfg.h:81
char ppp_login[64]
PPP Username.
Definition: netcfg.h:88
char pop3_passwd[64]
POP3 server password.
Definition: netcfg.h:85
char hostname[64]
DNS/DHCP hostname.
Definition: netcfg.h:80
char ppp_passwd[64]
PPP Password.
Definition: netcfg.h:89
struct netcfg netcfg_t
Network configuration information.