/[gxemul]/trunk/src/net/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 /trunk/src/net/net.c

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

revision 38 by dpavlin, Mon Oct 8 16:21:53 2007 UTC revision 44 by dpavlin, Mon Oct 8 16:22:56 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: net.c,v 1.8 2007/03/24 06:40:16 debug Exp $   *  $Id: net.c,v 1.12 2007/08/25 22:27:28 debug Exp $
29   *   *
30   *  Emulated network.   *  Emulated network.
31   *   *
# Line 76  struct ethernet_packet_link *net_allocat Line 76  struct ethernet_packet_link *net_allocat
76  {  {
77          struct ethernet_packet_link *lp;          struct ethernet_packet_link *lp;
78    
79          lp = malloc(sizeof(struct ethernet_packet_link));          CHECK_ALLOCATION(lp = malloc(sizeof(struct ethernet_packet_link)));
         if (lp == NULL)  
                 goto fail;  
80    
81          lp->len = len;          lp->len = len;
82          lp->extra = extra;          lp->extra = extra;
83          lp->data = malloc(len);          CHECK_ALLOCATION(lp->data = malloc(len));
         if (lp->data == NULL)  
                 goto fail;  
84    
85          lp->next = NULL;          lp->next = NULL;
86    
# Line 97  struct ethernet_packet_link *net_allocat Line 93  struct ethernet_packet_link *net_allocat
93          net->last_ethernet_packet = lp;          net->last_ethernet_packet = lp;
94    
95          return lp;          return lp;
   
 fail:  
         fprintf(stderr, "net_allocate_ethernet_packet_link(): out of memory\n");  
         exit(1);  
   
         /*  Gets rid of a compiler warning:  */  
         return NULL;  
96  }  }
97    
98    
# Line 595  static void parse_resolvconf(struct net Line 584  static void parse_resolvconf(struct net
584                          if (i < len)                          if (i < len)
585                                  buf[i] = '\0';                                  buf[i] = '\0';
586                          /*  fatal("DOMAIN='%s'\n", buf + start);  */                          /*  fatal("DOMAIN='%s'\n", buf + start);  */
587                          net->domain_name = strdup(buf + start);                          CHECK_ALLOCATION(net->domain_name = strdup(buf+start));
588                          break;                          break;
589                  }                  }
590  }  }
# Line 618  void net_add_nic(struct net *net, void * Line 607  void net_add_nic(struct net *net, void *
607          }          }
608    
609          net->n_nics ++;          net->n_nics ++;
610          net->nic_extra = realloc(net->nic_extra, sizeof(void *)          CHECK_ALLOCATION(net->nic_extra = realloc(net->nic_extra, sizeof(void *)
611              * net->n_nics);              * net->n_nics));
         if (net->nic_extra == NULL) {  
                 fprintf(stderr, "net_add_nic(): out of memory\n");  
                 exit(1);  
         }  
612    
613          net->nic_extra[net->n_nics - 1] = extra;          net->nic_extra[net->n_nics - 1] = extra;
614  }  }
# Line 673  void net_dumpinfo(struct net *net) Line 658  void net_dumpinfo(struct net *net)
658          int iadd = DEBUG_INDENTATION;          int iadd = DEBUG_INDENTATION;
659          struct remote_net *rnp;          struct remote_net *rnp;
660    
661          debug("net: simulating ");          debug("net:\n");
662    
663            debug_indentation(iadd);
664    
665            debug("simulated network: ");
666          net_debugaddr(&net->netmask_ipv4, NET_ADDR_IPV4);          net_debugaddr(&net->netmask_ipv4, NET_ADDR_IPV4);
667          debug("/%i", net->netmask_ipv4_len);          debug("/%i", net->netmask_ipv4_len);
668    
669          debug(" (max outgoing: TCP=%i, UDP=%i)\n",          debug(" (max outgoing: TCP=%i, UDP=%i)\n",
670              MAX_TCP_CONNECTIONS, MAX_UDP_CONNECTIONS);              MAX_TCP_CONNECTIONS, MAX_UDP_CONNECTIONS);
671    
672          debug_indentation(iadd);          debug("simulated gateway+nameserver: ");
   
         debug("simulated gateway: ");  
673          net_debugaddr(&net->gateway_ipv4_addr, NET_ADDR_IPV4);          net_debugaddr(&net->gateway_ipv4_addr, NET_ADDR_IPV4);
674          debug(" (");          debug(" (");
675          net_debugaddr(&net->gateway_ethernet_addr, NET_ADDR_ETHERNET);          net_debugaddr(&net->gateway_ethernet_addr, NET_ADDR_ETHERNET);
676          debug(")\n");          debug(")\n");
677    
         debug_indentation(iadd);  
678          if (!net->nameserver_known) {          if (!net->nameserver_known) {
679                  debug("(could not determine nameserver)");                  debug("(could not determine nameserver)\n");
680          } else {          } else {
681                  debug("using nameserver ");                  debug("simulated nameserver uses real nameserver ");
682                  net_debugaddr(&net->nameserver_ipv4, NET_ADDR_IPV4);                  net_debugaddr(&net->nameserver_ipv4, NET_ADDR_IPV4);
683                    debug("\n");
684          }          }
685    
686          if (net->domain_name != NULL && net->domain_name[0])          if (net->domain_name != NULL && net->domain_name[0])
687                  debug(", domain \"%s\"", net->domain_name);                  debug("domain: %s\n", net->domain_name);
         debug("\n");  
         debug_indentation(-iadd);  
688    
689          rnp = net->remote_nets;          rnp = net->remote_nets;
690          if (net->local_port != 0)          if (net->local_port != 0)
# Line 741  struct net *net_init(struct emul *emul, Line 726  struct net *net_init(struct emul *emul,
726          struct net *net;          struct net *net;
727          int res;          int res;
728    
729          net = malloc(sizeof(struct net));          CHECK_ALLOCATION(net = malloc(sizeof(struct net)));
         if (net == NULL) {  
                 fprintf(stderr, "net_init(): out of memory\n");  
                 exit(1);  
         }  
   
730          memset(net, 0, sizeof(struct net));          memset(net, 0, sizeof(struct net));
731    
732          /*  Set the back pointer:  */          /*  Set the back pointer:  */
# Line 789  struct net *net_init(struct emul *emul, Line 769  struct net *net_init(struct emul *emul,
769                          exit(1);                          exit(1);
770                  }                  }
771    
772                  memset((char *)&si_self, sizeof(si_self), 0);                  memset((char *)&si_self, 0, sizeof(si_self));
773                  si_self.sin_family = AF_INET;                  si_self.sin_family = AF_INET;
774                  si_self.sin_port = htons(local_port);                  si_self.sin_port = htons(local_port);
775                  si_self.sin_addr.s_addr = htonl(INADDR_ANY);                  si_self.sin_addr.s_addr = htonl(INADDR_ANY);
# Line 809  struct net *net_init(struct emul *emul, Line 789  struct net *net_init(struct emul *emul,
789                          struct hostent *hp;                          struct hostent *hp;
790    
791                          /*  debug("adding '%s'\n", remote[n_remote]);  */                          /*  debug("adding '%s'\n", remote[n_remote]);  */
792                          rnp = malloc(sizeof(struct remote_net));                          CHECK_ALLOCATION(rnp =
793                                malloc(sizeof(struct remote_net)));
794                          memset(rnp, 0, sizeof(struct remote_net));                          memset(rnp, 0, sizeof(struct remote_net));
795    
796                          rnp->next = net->remote_nets;                          rnp->next = net->remote_nets;
797                          net->remote_nets = rnp;                          net->remote_nets = rnp;
798    
799                          rnp->name = strdup(remote[n_remote]);                          CHECK_ALLOCATION(rnp->name = strdup(remote[n_remote]));
800                          if (strchr(rnp->name, ':') != NULL)                          if (strchr(rnp->name, ':') != NULL)
801                                  strchr(rnp->name, ':')[0] = '\0';                                  strchr(rnp->name, ':')[0] = '\0';
802    
# Line 829  struct net *net_init(struct emul *emul, Line 810  struct net *net_init(struct emul *emul,
810                          free(rnp->name);                          free(rnp->name);
811    
812                          /*  And again:  */                          /*  And again:  */
813                          rnp->name = strdup(remote[n_remote]);                          CHECK_ALLOCATION(rnp->name = strdup(remote[n_remote]));
814                          if (strchr(rnp->name, ':') == NULL) {                          if (strchr(rnp->name, ':') == NULL) {
815                                  fprintf(stderr, "Remote network '%s' is not "                                  fprintf(stderr, "Remote network '%s' is not "
816                                      "'host:portnr'?\n", rnp->name);                                      "'host:portnr'?\n", rnp->name);

Legend:
Removed from v.38  
changed lines
  Added in v.44

  ViewVC Help
Powered by ViewVC 1.1.26