1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: net.c,v 1.84 2005/11/25 03:38:00 debug Exp $ |
* $Id: net.c,v 1.89 2006/02/09 22:40:26 debug Exp $ |
29 |
* |
* |
30 |
* Emulated (ethernet / internet) network support. |
* Emulated (ethernet / internet) network support. |
31 |
* |
* |
157 |
x = machine->serial_nr; |
x = machine->serial_nr; |
158 |
y = machine->nr_of_nics; |
y = machine->nr_of_nics; |
159 |
|
|
|
/* |
|
|
* TODO: What is a good starting value? Something like this? |
|
|
* |
|
|
* +-----------+-------------------+-------------+-------------+ |
|
|
* | 16 bits | 16 bits machine | 12 bits | 4 bits of | |
|
|
* | fixed | serial nr | NIC nr(*) | zeroes | |
|
|
* +-----------+-------------------+-------------+-------------+ |
|
|
*/ |
|
160 |
macbuf[0] = 0x10; |
macbuf[0] = 0x10; |
161 |
macbuf[1] = 0x20; |
macbuf[1] = 0x20; |
162 |
macbuf[2] = 0x30; |
macbuf[2] = 0x30; |
163 |
macbuf[3] = 0; |
macbuf[3] = 0; |
164 |
macbuf[4] = 0; |
macbuf[4] = 0; |
165 |
macbuf[5] = machine->serial_nr << 4; |
/* NOTE/TODO: This only allows 8 nics per machine! */ |
166 |
|
macbuf[5] = (machine->serial_nr << 4) + (machine->nr_of_nics << 1); |
167 |
|
|
168 |
if (macbuf[0] & 1 || macbuf[5] & 1) { |
if (macbuf[0] & 1 || macbuf[5] & 1) { |
169 |
fatal("Internal error in net_generate_unique_mac().\n"); |
fatal("Internal error in net_generate_unique_mac().\n"); |
1954 |
si.sin_port = htons(portnr); |
si.sin_port = htons(portnr); |
1955 |
|
|
1956 |
if (sendto(s, packet, len, 0, (struct sockaddr *)&si, |
if (sendto(s, packet, len, 0, (struct sockaddr *)&si, |
1957 |
sizeof(si)) != len) { |
sizeof(si)) != (ssize_t)len) { |
1958 |
perror("send_udp(): sendto"); |
perror("send_udp(): sendto"); |
1959 |
} |
} |
1960 |
|
|
2251 |
*/ |
*/ |
2252 |
void net_dumpinfo(struct net *net) |
void net_dumpinfo(struct net *net) |
2253 |
{ |
{ |
2254 |
int iadd = 4; |
int iadd = DEBUG_INDENTATION; |
2255 |
struct remote_net *rnp; |
struct remote_net *rnp; |
2256 |
|
|
2257 |
debug("net: simulating "); |
debug("net: simulating "); |
2419 |
|
|
2420 |
net_dumpinfo(net); |
net_dumpinfo(net); |
2421 |
|
|
2422 |
/* This is neccessary when using the real network: */ |
/* This is necessary when using the real network: */ |
2423 |
signal(SIGPIPE, SIG_IGN); |
signal(SIGPIPE, SIG_IGN); |
2424 |
|
|
2425 |
return net; |
return net; |