cast_type cast_new_type(cast_type_kind kind) { cast_type type = mustcalloc(sizeof(*type)); memset(type, 0, sizeof(*type)); type->kind = kind; return type; }
/* Generate the mappings from FLICK_ERROR codes into presentation preferred codes */ void gen_error_mappings( pres_c_1 *out_pres ) { cast_expr *error_map; out_pres->error_mappings.error_mappings_len = FLICK_ERROR_MAX; out_pres->error_mappings.error_mappings_val = (cast_expr *)mustcalloc( out_pres->error_mappings.error_mappings_len * sizeof( cast_expr ) ); error_map = out_pres->error_mappings.error_mappings_val; error_map[FLICK_ERROR_NONE] = cast_new_expr_name( "err_none" ); error_map[FLICK_ERROR_CONSTANT] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_VIRTUAL_UNION] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_STRUCT_UNION] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_DECODE_SWITCH] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_COLLAPSED_UNION] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_VOID_UNION] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_COMMUNICATION] = cast_new_expr_name( "MIG_SERVER_DIED" ); error_map[FLICK_ERROR_OUT_OF_BOUNDS] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_INVALID_TARGET] = cast_new_expr_name( "MIG_BAD_ARGUMENTS" ); error_map[FLICK_ERROR_NO_MEMORY] = cast_new_expr_name( "MIG_ARRAY_TOO_LARGE" ); }
cast_stmt cast_new_block(int defs, int stmts) { cast_stmt stmt; stmt = cast_new_stmt(CAST_STMT_BLOCK); stmt->cast_stmt_u_u.block.scope = cast_new_scope(defs); if (stmts > 0) { stmt->cast_stmt_u_u.block.stmts.stmts_len = stmts; stmt->cast_stmt_u_u.block.stmts.stmts_val = mustcalloc(stmts*sizeof(cast_stmt)); } return stmt; }
pres_c_inline pres_c_new_inline_struct(int slots) { pres_c_inline inl = pres_c_new_inline(PRES_C_INLINE_STRUCT); inl->pres_c_inline_u_u.struct_i.slots.slots_len = slots; if (slots > 0) inl->pres_c_inline_u_u.struct_i.slots.slots_val = mustcalloc(slots * sizeof(pres_c_inline_struct_slot)); else inl->pres_c_inline_u_u.struct_i.slots.slots_val = 0; return inl; }
pres_c_inline pres_c_new_inline_void_union(int cases) { pres_c_inline inl = pres_c_new_inline(PRES_C_INLINE_VOID_UNION); inl->pres_c_inline_u_u.void_union.cases.cases_len = cases; if (cases > 0) inl->pres_c_inline_u_u.void_union.cases.cases_val = mustcalloc(cases * sizeof(pres_c_inline_void_union_case)); else inl->pres_c_inline_u_u.void_union.cases.cases_val = 0; inl->pres_c_inline_u_u.void_union.dfault = 0; return inl; }
cast_scope cast_new_scope(int defs) { cast_scope retval; if (defs) { int i; retval.cast_scope_len = defs; retval.cast_scope_val = mustcalloc(defs * sizeof(cast_def)); memset(retval.cast_scope_val, 0, defs * sizeof(cast_def)); for (i = 0; i < defs; i++ ) { retval.cast_scope_val[i].name = empty_scope_name; retval.cast_scope_val[i].channel = -1; } } else { retval.cast_scope_len = 0; retval.cast_scope_val = 0; } return retval; }
cast_template_arg cast_new_template_arg(cast_template_arg_kind kind) { cast_template_arg template_arg = mustcalloc(sizeof(*template_arg)); template_arg->kind = kind; return template_arg; }
/* * Initialize networkiness. * * Empty comments in column 1 indicate things that need to be undone upon * failure or in net_shutdown. * * Returns zero on success, an error code from <oskit/error.h> otherwise. */ oskit_error_t net_init(void) { #define BUFSIZE 128 struct bootp_net_info bpi; struct in_addr gw, ns; char hn[64], dn[64]; static char buf[BUFSIZE]; oskit_etherdev_t **alldevs; int ndev; int i, ix; unsigned required_flags; int interactive = 0; oskit_socket_factory_t *fsc; #ifdef FREEBSD_NET oskit_error_t err; #endif /* * Find all the Ethernet device nodes. */ retry: ndev = osenv_device_lookup(&oskit_etherdev_iid, (void***)&alldevs); #ifdef BOOTP_IF if (ndev < BOOTP_IF) panic("BOOTP Ethernet adaptor %d not found!", BOOTP_IF); #else if (ndev <= 0) panic("no Ethernet adaptors found!"); #endif dev = NULL; memset(&bpi, 0, sizeof bpi); /* * Prompt user for info */ if (interactive) { char *cp; do { printf("Enter ethernet IF to use [%d-%d]: ", 0, ndev-1); fgets(buf, BUFSIZE, stdin); ix = atoi(buf); if (ix < 0) goto gotinfo; } while (ix >= ndev); do { printf("Enter IP address: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &bpi.ip) == 0); do { printf("Enter netmask: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &bpi.netmask) == 0); do { printf("Enter gateway IP address: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &gw) == 0); bpi.gateway.addr = &gw; bpi.gateway.len = 1; printf("Enter hostname: "); fgets(buf, BUFSIZE, stdin); if ((cp = strchr(buf, '\n')) != 0) *cp = '\0'; memcpy(hn, buf, sizeof hn); bpi.hostname = hn; printf("Enter domainname: "); fgets(buf, BUFSIZE, stdin); if ((cp = strchr(buf, '\n')) != 0) *cp = '\0'; memcpy(dn, buf, sizeof dn); bpi.domainname = dn; do { printf("Enter nameserver IP address: "); fgets(buf, BUFSIZE, stdin); } while (inet_aton(buf, &ns) == 0); bpi.dns_server.addr = &ns; bpi.dns_server.len = 1; dev = alldevs[ix]; goto gotinfo; } /* * Try bootp on each dev and use the first one that succeeds. */ ix = ndev; for (i = 0; i < ndev; i++) { #ifdef BOOTP_IF if (i != BOOTP_IF) { oskit_etherdev_release(alldevs[i]); continue; } #else if (dev) { /* Have choice, but must release the others anyway. */ oskit_etherdev_release(alldevs[i]); continue; } #endif if (bootp(alldevs[i], &bpi) != 0) { oskit_etherdev_release(alldevs[i]); continue; } required_flags = (BOOTP_NET_IP | BOOTP_NET_NETMASK | BOOTP_NET_GATEWAY | BOOTP_NET_DNS_SERVER | BOOTP_NET_DOMAINNAME | BOOTP_NET_HOSTNAME); if ((bpi.flags & required_flags) != required_flags) { #define MISSING(flag, name) if ((bpi.flags & flag) == 0) \ printf("bootp did not supply %s\n", name) MISSING(BOOTP_NET_IP, "my IP address"); MISSING(BOOTP_NET_NETMASK, "my netmask"); MISSING(BOOTP_NET_GATEWAY, "gateway address"); MISSING(BOOTP_NET_DNS_SERVER, "DNS servers"); MISSING(BOOTP_NET_DOMAINNAME, "domainname"); MISSING(BOOTP_NET_HOSTNAME, "my hostname"); #undef MISSING oskit_etherdev_release(alldevs[i]); continue; } /**/ dev = alldevs[i]; ix = i; } gotinfo: if (dev == NULL) { #ifdef UTAHTESTBED /* * XXX fer now hack */ static int tried; if (tried++ < 5) goto retry; #endif #ifdef BOOTP_IF printf("No bootp server found for eth%d!", BOOTP_IF); #else printf("No bootp server found for any interface!"); #endif printf(" Try again? [n] "); fgets(buf, BUFSIZE, stdin); if (buf[0] == 'y' || buf[0] == 'Y') goto retry; printf("Enter bootp information manually? [y] "); fgets(buf, BUFSIZE, stdin); if (buf[0] != 'n' && buf[0] != 'N') { interactive = 1; goto retry; } return OSKIT_E_FAIL; } /* * Now we know our bootp struct has all we need, * so we copy the info out. */ ipaddr = strdup(inet_ntoa(bpi.ip)); netmask = strdup(inet_ntoa(bpi.netmask)); gateway = strdup(inet_ntoa(bpi.gateway.addr[0])); domain = strdup(bpi.domainname); { struct bootp_addr_array ns; int x; ns = bpi.dns_server; nameservers = mustcalloc(1, (sizeof(char*) * ns.len) + 1); for (x = 0; x < ns.len; x++) nameservers[x] = strdup(inet_ntoa(ns.addr[x])); nameservers[ns.len] = NULL; } /* Hostnamelen needs to be word aligned for RPC code. */ hostname = (char *)mustcalloc(strlen(bpi.hostname) + 3, 1); strcpy(hostname, bpi.hostname); hostnamelen = (strlen(hostname) + 3) & ~3; #ifdef DEBUG bootp_dump(&bpi); #endif printf("I am %s.%s (IP: %s, GW: %s, mask: %s)\n", hostname, domain, ipaddr, gateway, netmask); #ifdef FREEBSD_NET err = start_conf_network_init(start_osenv(), &fsc); assert(!err); err = start_conf_network_eifstart(i, ipaddr, netmask); assert(!err); start_conf_network_host(hostname, gateway, domain, nameservers); #else /* Now init the fudp module. It will open the device */ udplib_init(dev, hostname, ipaddr, netmask, gateway, &fsc); /* * This writes out the DNS files. We need the freebsd stub * function below since it thinks its dealing with the freebsd * network stack. */ start_conf_network_host(hostname, gateway, domain, nameservers); #endif /* * Register to socket factory so that UDP might be useful for others. * Its a long shot! */ #ifdef PTHREADS pthread_init_socketfactory(fsc); #else oskit_register(&oskit_socket_factory_iid, (void *) fsc); #endif return 0; }