/[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 41 by dpavlin, Mon Oct 8 16:22:11 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: net.c,v 1.9 2007/04/28 00:10:11 debug Exp $   *  $Id: net.c,v 1.10 2007/06/15 17:02:39 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 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 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.41  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26