static int accepter(void *x) { struct gdbcontext *ctx; struct sockaddr_storage sa; socklen_t salen; int remotefd; (void)x; /* not used */ salen = sizeof(sa); remotefd = accept(g_listenfd, (struct sockaddr *)&sa, &salen); if (remotefd < 0) { /* :-? */ return 0; } if (g_ctx_inuse) { /* * Hardcode the checksum; the code for sending these things * is file-static in gdb_be.c. :-| * * It doesn't appear to make much difference if we * send anything anyway. */ const char *errmsg = "$E99#b7"; write(remotefd, errmsg, strlen(errmsg)); close(remotefd); return 0; } g_ctx_inuse = 1; ctx = &g_ctx; msg("New debugger connection"); ctx->myfd = remotefd; ctx->bufptr = 0; onselect(remotefd, ctx, gdb_receive, gdb_cleanup); main_stop(); return 0; }
static void common_init(int sfd) { if (sfd == -1) { msg("Could not bind debug socket; debugging disabled"); return; } if (listen(sfd, 1) < 0) { msg("listen: %s", strerror(errno)); msg("Could not set up debug socket; debugging disabled"); close(sfd); return; } g_listenfd = sfd; onselect(sfd, NULL, accepter, NULL); }
void GUICONTROL::OnSelect() const { onselect(); }
static void * net_init(int slot, int argc, char *argv[]) { struct net_data *nd = domalloc(sizeof(struct net_data)); const char *hubname = ".sockets/hub"; u_int16_t hwaddr = HUB_ADDR; char cwd[PATH_MAX]; int len; struct sockaddr_un mysun; socklen_t mylen; int i, one=1; for (i=1; i<argc; i++) { if (!strncmp(argv[i], "hub=", 4)) { hubname = argv[i]+4; } else if (!strncmp(argv[i], "hwaddr=", 7)) { hwaddr = atoi(argv[i]+7); } else { msg("nic: slot %d: invalid option %s", slot, argv[i]); die(); } } if (hwaddr == BROADCAST_ADDR || hwaddr == HUB_ADDR) { msg("nic: slot %d: invalid hwaddr or hwaddr not set", slot); die(); } if (getcwd(cwd, sizeof(cwd))==NULL) { msg("nic: slot %d: getcwd: %s", slot, strerror(errno)); die(); } nd->nd_slot = slot; nd->nd_status = ND_STATUS(hwaddr, 0); nd->nd_socket = socket(AF_UNIX, SOCK_DGRAM, 0); if (nd->nd_socket < 0) { msg("nic: slot %d: socket: %s", slot, strerror(errno)); die(); } nd->nd_lostcarrier = 1; nd->nd_rbuf = domalloc(NET_BUFSIZE); nd->nd_wbuf = domalloc(NET_BUFSIZE); memset(&mysun, 0, sizeof(mysun)); mysun.sun_family = AF_UNIX; len = snprintf(mysun.sun_path, sizeof(mysun.sun_path), "%s/.sockets/net-%04x", cwd, hwaddr); if (len < 0 || len >= (int) sizeof(mysun.sun_path)) { msg("nic: slot %d: current directory %s too long", slot, cwd); die(); } mylen = SUN_LEN(&mysun); #ifdef HAS_SUN_LEN mysun.sun_len = mylen; #endif unlink(mysun.sun_path); setsockopt(nd->nd_socket, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); if (bind(nd->nd_socket, (struct sockaddr *)&mysun, mylen)<0) { msg("nic: slot %d: bind: %s", slot, strerror(errno)); die(); } memset(&nd->nd_hubaddr, 0, sizeof(nd->nd_hubaddr)); nd->nd_hubaddr.sun_family = AF_UNIX; strcpy(nd->nd_hubaddr.sun_path, hubname); nd->nd_hubaddrlen = SUN_LEN(&nd->nd_hubaddr); #ifdef HAS_SUN_LEN nd->nd_hubaddr.sun_len = nd->nd_hubaddrlen; #endif onselect(nd->nd_socket, nd, dorecv, NULL); keepalive(nd, 0); return nd; }