/[gxemul]/upstream/0.3.1/include/net.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/0.3.1/include/net.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Mon Oct 8 16:17:52 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 4879 byte(s)
0.3.1
1 dpavlin 2 #ifndef NET_H
2     #define NET_H
3    
4     /*
5     * Copyright (C) 2004-2005 Anders Gavare. All rights reserved.
6     *
7     * Redistribution and use in source and binary forms, with or without
8     * modification, are permitted provided that the following conditions are met:
9     *
10     * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17     *
18     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21     * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22     * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24     * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27     * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28     * SUCH DAMAGE.
29     *
30     *
31     * $Id: net.h,v 1.11 2005/03/14 19:14:03 debug Exp $
32     *
33     * Emulated network support. (See net.c for more info.)
34     */
35    
36     #include <netinet/in.h>
37     #include <arpa/inet.h>
38     #include <netdb.h>
39    
40     struct emul;
41     struct ethernet_packet_link;
42    
43    
44     /*****************************************************************************/
45    
46     /* NOTE: udp_connection and tcp_connection are actually for
47     internal use only. */
48     struct udp_connection {
49     int in_use;
50     int64_t last_used_timestamp;
51    
52     /* Inside: */
53     unsigned char ethernet_address[6];
54     unsigned char inside_ip_address[4];
55     int inside_udp_port;
56    
57     /* TODO: Fragment support for outgoing packets! */
58     int fake_ns;
59    
60     /* Outside: */
61     int udp_id;
62     int socket;
63     unsigned char outside_ip_address[4];
64     int outside_udp_port;
65     };
66    
67     struct tcp_connection {
68     int in_use;
69     int64_t last_used_timestamp;
70    
71     /* Inside: */
72     unsigned char ethernet_address[6];
73     unsigned char inside_ip_address[4];
74     int inside_tcp_port;
75     uint32_t inside_timestamp;
76    
77     /* TODO: tx and rx buffers? */
78     unsigned char *incoming_buf;
79     int incoming_buf_rounds;
80     int incoming_buf_len;
81     uint32_t incoming_buf_seqnr;
82    
83     uint32_t inside_seqnr;
84     uint32_t inside_acknr;
85     uint32_t outside_seqnr;
86     uint32_t outside_acknr;
87    
88     /* Outside: */
89     int state;
90     int tcp_id;
91     int socket;
92     unsigned char outside_ip_address[4];
93     int outside_tcp_port;
94     uint32_t outside_timestamp;
95     };
96    
97     /*****************************************************************************/
98    
99    
100     #define MAX_TCP_CONNECTIONS 60
101     #define MAX_UDP_CONNECTIONS 60
102    
103     struct net {
104     /* The emul struct which this net belong to: */
105     struct emul *emul;
106    
107     /* The network's addresses: */
108     struct in_addr netmask_ipv4;
109     int netmask_ipv4_len;
110    
111     /* NICs connected to this network: */
112     int n_nics;
113     void **nic_extra; /* one void * per NIC */
114    
115     /* The "special machine": */
116     unsigned char gateway_ipv4_addr[4];
117     unsigned char gateway_ethernet_addr[6];
118    
119     /* Read from /etc/resolv.conf: */
120     char *domain_name;
121     int nameserver_known;
122     struct in_addr nameserver_ipv4;
123    
124     int64_t timestamp;
125    
126     struct ethernet_packet_link *first_ethernet_packet;
127     struct ethernet_packet_link *last_ethernet_packet;
128    
129     struct udp_connection udp_connections[MAX_UDP_CONNECTIONS];
130     struct tcp_connection tcp_connections[MAX_TCP_CONNECTIONS];
131     };
132    
133     /* net.c: */
134     void net_generate_unique_mac(struct machine *, unsigned char *macbuf);
135     int net_ethernet_rx_avail(struct net *net, void *extra);
136     int net_ethernet_rx(struct net *net, void *extra,
137     unsigned char **packetp, int *lenp);
138     void net_ethernet_tx(struct net *net, void *extra,
139     unsigned char *packet, int len);
140     void net_dumpinfo(struct net *net);
141     void net_add_nic(struct net *net, void *extra, unsigned char *macaddr);
142     struct net *net_init(struct emul *emul, int init_flags,
143     char *ipv4addr, int netipv4len);
144    
145     /* Flag used to signify that this net should have a gateway: */
146     #define NET_INIT_FLAG_GATEWAY 1
147    
148    
149     /*
150     * This is for internal use in src/net.c:
151     */
152    
153     struct ethernet_packet_link {
154     struct ethernet_packet_link *prev;
155     struct ethernet_packet_link *next;
156    
157     void *extra;
158     unsigned char *data;
159     int len;
160     };
161    
162    
163     #define TCP_OUTSIDE_TRYINGTOCONNECT 1
164     #define TCP_OUTSIDE_CONNECTED 2
165     #define TCP_OUTSIDE_DISCONNECTED 3
166     #define TCP_OUTSIDE_DISCONNECTED2 4
167    
168     #define TCP_INCOMING_BUF_LEN 2000
169    
170    
171     #endif /* NET_H */

  ViewVC Help
Powered by ViewVC 1.1.26