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

Diff of /upstream/0.4.0/src/net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/net.c revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC upstream/0.4.0/src/net.c revision 25 by dpavlin, Mon Oct 8 16:20:03 2007 UTC
# Line 1  Line 1 
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:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: net.c,v 1.80 2005/08/12 05:49:46 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   *   *
# Line 157  void net_generate_unique_mac(struct mach Line 157  void net_generate_unique_mac(struct mach
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) {
169                    fatal("Internal error in net_generate_unique_mac().\n");
170                    exit(1);
171            }
172    
173          /*  TODO: Remember the mac addresses somewhere?  */          /*  TODO: Remember the mac addresses somewhere?  */
174          machine->nr_of_nics ++;          machine->nr_of_nics ++;
# Line 1430  static void net_arp(struct net *net, voi Line 1428  static void net_arp(struct net *net, voi
1428                          if (memcmp(packet+24, net->gateway_ipv4_addr, 4) != 0)                          if (memcmp(packet+24, net->gateway_ipv4_addr, 4) != 0)
1429                                  break;                                  break;
1430    
1431                          lp = net_allocate_packet_link(net, extra, len + 14);                          lp = net_allocate_packet_link(net, extra, 60 + 14);
1432    
1433                          /*  Copy the old packet first:  */                          /*  Copy the old packet first:  */
1434                            memset(lp->data, 0, 60 + 14);
1435                          memcpy(lp->data + 14, packet, len);                          memcpy(lp->data + 14, packet, len);
1436    
1437                          /*  Add ethernet ARP header:  */                          /*  Add ethernet ARP header:  */
# Line 1453  static void net_arp(struct net *net, voi Line 1452  static void net_arp(struct net *net, voi
1452    
1453                          break;                          break;
1454                  case 3:         /*  Reverse Request  */                  case 3:         /*  Reverse Request  */
1455                          lp = net_allocate_packet_link(net, extra, len + 14);                          lp = net_allocate_packet_link(net, extra, 60 + 14);
1456    
1457                          /*  Copy the old packet first:  */                          /*  Copy the old packet first:  */
1458                            memset(lp->data, 0, 60 + 14);
1459                          memcpy(lp->data + 14, packet, len);                          memcpy(lp->data + 14, packet, len);
1460    
1461                          /*  Add ethernet RARP header:  */                          /*  Add ethernet RARP header:  */
# Line 1954  void send_udp(struct in_addr *addrp, int Line 1954  void send_udp(struct in_addr *addrp, int
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    
# Line 2062  void net_ethernet_tx(struct net *net, vo Line 2062  void net_ethernet_tx(struct net *net, vo
2062    
2063          /*  ARP:  */          /*  ARP:  */
2064          if (packet[12] == 0x08 && packet[13] == 0x06) {          if (packet[12] == 0x08 && packet[13] == 0x06) {
2065                  if (len != 60)                  if (len != 42 && len != 60)
2066                          fatal("[ net_ethernet_tx: WARNING! unusual "                          fatal("[ net_ethernet_tx: WARNING! unusual "
2067                              "ARP len (%i) ]\n", len);                              "ARP len (%i) ]\n", len);
2068                  net_arp(net, extra, packet + 14, len - 14, 0);                  net_arp(net, extra, packet + 14, len - 14, 0);
# Line 2251  static void net_gateway_init(struct net Line 2251  static void net_gateway_init(struct net
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 ");
# Line 2419  struct net *net_init(struct emul *emul, Line 2419  struct net *net_init(struct emul *emul,
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;

Legend:
Removed from v.12  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26