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 |
* |
* |
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 |
|
|
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 |
|
|
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 |
} |
} |
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 |
} |
} |
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) |
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: */ |
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); |
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 |
|
|
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); |