/* Initialize user socket array */ void sockinit(void) { if(Usock != (struct usock **)NULL) return; /* Already initialized */ Usock = (struct usock **)callocw(Nsock,sizeof(struct usock *)); }
/* Create a TCB, return pointer. Return pointer if TCB already exists. */ struct tcb * create_tcb( struct connection *conn) { struct tcb *tcb; struct tcp_rtt *tp; if((tcb = lookup_tcb(conn)) != NULL) return tcb; tcb = (struct tcb *)callocw(1,sizeof (struct tcb)); tcb->conn = *conn; tcb->state = TCP_CLOSED; tcb->cwind = tcb->mss = Tcp_mss; tcb->ssthresh = 65535; if((tp = rtt_get(tcb->conn.remote.address)) != NULL){ tcb->srtt = tp->srtt; tcb->mdev = tp->mdev; } else { tcb->srtt = Tcp_irtt; /* mdev = 0 */ } /* Initialize timer intervals */ set_timer(&tcb->timer,tcb->srtt); tcb->timer.func = tcp_timeout; tcb->timer.arg = tcb; tcb->next = Tcbs; Tcbs = tcb; return tcb; }
/* Call a subcommand based on the first token in an already-parsed line */ int subcmd( struct cmds tab[], int argc, char *argv[], void *p) { struct cmds *cmdp; char **pargv; int found = 0; int i; /* Strip off first token and pass rest of line to subcommand */ if (argc < 2) { if (argc < 1) printf("SUBCMD - Don't know what to do?\n"); else { printf("\"%s\" subcommands:\n", argv[0]); print_help(tab); } return -1; } argc--; argv++; for(cmdp = tab;cmdp->name != NULL;cmdp++){ if(strncmp(argv[0],cmdp->name,strlen(argv[0])) == 0){ found = 1; break; } } if(!found){ printf("\"%s\" subcommands:\n", argv[-1]); print_help(tab); return -1; } if(argc < cmdp->argcmin){ if(cmdp->argc_errmsg != NULL) printf("Usage: %s\n",cmdp->argc_errmsg); return -1; } if(cmdp->stksize == 0){ return (*cmdp->func)(argc,argv,p); } else { #ifndef SINGLE_THREADED /* Make private copy of argv and args */ pargv = (char **)callocw(argc,sizeof(char *)); for(i=0;i<argc;i++) pargv[i] = strdup(argv[i]); newproc(cmdp->name,cmdp->stksize, (void (*)(int,void *,void *))cmdp->func,argc,pargv,p,1); #endif return(0); } }
/* Arrange for receipt of raw IP datagrams */ struct raw_ip * raw_ip( int protocol, void (*r_upcall)() ){ register struct raw_ip *rp; rp = (struct raw_ip *)callocw(1,sizeof(struct raw_ip)); rp->protocol = protocol; rp->r_upcall = r_upcall; rp->next = Raw_ip; Raw_ip = rp; return rp; }
int ethertap_attach(int argc, char *argv[], void *p) { char *ifname; char devname[1024]; int fd; struct edv_t *edv; struct iface *ifp; ifname = argv[1]; if (if_lookup(ifname)) { printf("Interface %s already exists\n", ifname); return -1; } strcpy(devname, "/dev/"); strcat(devname, ifname); fd = open(devname, O_RDWR); if (fd < 0) { printf("%s: %s\n", devname, strerror(errno)); return -1; } ifp = (struct iface *) callocw(1, sizeof(struct iface)); ifp->name = strdup(ifname); ifp->addr = Ip_addr; ifp->broadcast = 0xffffffffUL; ifp->netmask = 0xffffffffUL; ifp->mtu = 0xffff; setencap(ifp, "None"); edv = (struct edv_t *) malloc(sizeof(struct edv_t)); edv->fd = fd; ifp->edv = edv; ifp->send = ethertap_send; on_read(fd, ethertap_recv, (void *) ifp); ifp->next = Ifaces; Ifaces = ifp; return 0; }
int ipip_attach(int argc, char *argv[], void *p) { char *ifname = "ipip"; int fd; int port = IP4_PTCL; int type = USE_IP; struct edv_t *edv; struct iface *ifp; struct sockaddr_in addr; if (argc >= 2) ifname = argv[1]; if (if_lookup(ifname) != NULL) { printf("Interface %s already exists\n", ifname); return -1; } if (argc >= 3) switch (*argv[2]) { case 'I': case 'i': type = USE_IP; break; case 'U': case 'u': type = USE_UDP; break; default: printf("Type must be IP or UDP\n"); return -1; } if (argc >= 4) port = atoi(argv[3]); if (type == USE_IP) fd = socket(AF_INET, SOCK_RAW, port); else fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { printf("cannot create socket: %s\n", strerror(errno)); return -1; } if (type == USE_UDP) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(port); if (bind(fd, (struct sockaddr *) &addr, sizeof(addr))) { printf("cannot bind address: %s\n", strerror(errno)); close(fd); return -1; } } ifp = (struct iface *) callocw(1, sizeof(struct iface)); ifp->name = strdup(ifname); ifp->addr = Ip_addr; ifp->broadcast = 0xffffffffUL; ifp->netmask = 0xffffffffUL; ifp->mtu = MAX_FRAME; ifp->flags = NO_RT_ADD; setencap(ifp, "None"); edv = (struct edv_t *) malloc(sizeof(struct edv_t)); edv->type = type; edv->port = port; edv->fd = fd; ifp->edv = edv; ifp->send = ipip_send; on_read(fd, ipip_receive, (void * ) ifp); ifp->next = Ifaces; Ifaces = ifp; return 0; }
int hfdd_connect (char *cc) { char cbuf[20], *cptr, *ccptr, **pargv; int cnt; pargv = (char **)callocw(3,sizeof(char *)); /* just to get this working, it needs better structure */ for (ccptr = cc, cnt = 0; cnt < 3; cnt++) { cptr = cbuf; while (*ccptr && *ccptr != ' ') *cptr++ = *ccptr++; *cptr = 0; /* 20Mar2006, Maiko, Remove any EOL (end of line) chars */ if (cnt == 2) rip (cbuf); if (hfdd_debug) log (-1, "cbuf [%s]", cbuf); pargv[cnt] = j2strdup (cbuf); if (*ccptr == ' ') ccptr++; } hfdd_conn_flag = 0; /* 03Feb2005, MAKE SURE this is set !!! */ /* * 16Apr2007, Maiko (VE4KLM), Identify which device interface is, now * that I have the KAM connect working nicely, I need to add the other * devices, PTC now, the DXP will be later. */ /* 17Feb2007, Maiko, New way to conn */ if (hfdd_is_kam (pargv[1])) kam_make_call (pargv[2]); else if (hfdd_is_ptc (pargv[1])) ptc_make_call (pargv[2]); /* 23Apr2008, Maiko, Now support AEA PK232 modem */ /* 10Sep2008, Maiko, New queue system for PK232, different function */ else if (hfdd_is_pk232 (pargv[1])) pk232_connect (pargv[1], pargv[2]); else if (hfdd_is_dxp (pargv[1])) log (-1, "dxp not supported YET ..."); #ifdef WINMOR /* 07Apr2010, Maiko, Support the WINMOR Sound Card modem */ else if (hfdd_is_winmor (pargv[1])) winmor_make_call (pargv[2]); #endif /* * 16Feb2007, Maiko, Need a function to request connect from hfddsrv * used to be hfdd_console here - no more, since hfddsrv fulltime now */ if (hfdd_debug) log (-1, "trying [%s]", pargv[2]); /* 04Mar2006, Maiko, Fix up this wait for connection ... */ while (!hfdd_conn_flag) j2pause (100); if (hfdd_conn_flag == -1) { if (hfdd_debug) log (-1, "[%s] no connection", pargv[2]); return -1; } if (hfdd_debug) log (-1, "[%s] connected - assign socket pair", pargv[2]); /* use socket pair like bbs side, 08Jan2005 */ if (j2socketpair (AF_LOCAL, SOCK_STREAM, 0, fwds) == -1) { log (-1, "socketpair failed, errno %d", errno); return -1; } seteol (fwds[0], "\r"); seteol (fwds[1], "\r"); /* seteol (fwds[0], "\r\n"); seteol (fwds[1], "\r\n"); */ hfdd_fwdsock = fwds[0]; /* this is for our local access */ sockmode (fwds[1], SOCK_ASCII); return (fwds[1]); /* this one becomes m->user in forward.c */ }
static int dohfddsrv (int argc, char *argv[], void *p) { static struct proc *hfsrvp = (struct proc*)0; if (argc == 3) { if (!stricmp (argv[2], "start")) { char **pargv = (char**)callocw (3, sizeof(char*)); log (-1, "start hfdd server on port [%s]", argv[1]); pargv[0] = "c"; pargv[1] = j2strdup (argv[1]); pargv[2] = "bbs"; hfsrvp = newproc ("hfddsrv", 2048, hfddsrv2, 3, pargv, (void*)0, 1); } /* 09Mar2005, Maiko, Kick option incase server goes into limbo */ else if (!stricmp (argv[2], "kick")) { log (-1, "kick hfdd server on port [%s]", argv[1]); alert (hfsrvp, EABORT); } /* 23Sep2006, Maiko, Unproto option for sysop to FEC at will, * note this is a bit of a kludge in that we have to pass the * name of the interface (will fix that later) ... */ else if (!stricmp (argv[2], "unproto")) { struct iface *ifp; log (-1, "sending unproto (FEC) beacon"); /* 20Mar2007, Maiko, Added KAM hostmode */ if ((ifp = if_lookup (argv[1])) != NULLIF) { if (hfdd_is_dxp (ifp->name)) dxp_FEC (ifp->dev, 1); else if (hfdd_is_kam (ifp->name)) kam_FEC (); /* 16Apr2007, Maiko, Added FEC code for SCS modem */ else if (hfdd_is_ptc (ifp->name)) ptc_FEC (); /* 20Sepr2008, Maiko, Added FEC code for PK232 modem */ else if (hfdd_is_pk232 (ifp->name)) pk232_FEC (ifp->dev); } } /* * 14Mar2007, Maiko, Utility to EXIT hostmode incase the * TNC seems to get into the occasional I AM IN HOSTMODE * but I AM NOT RESPONDING type of situation. Doing this * kick will force the code to recognize NOT IN HOSTMODE * status, and reinitialize the TNC (KAM). */ else if (!stricmp (argv[2], "exit")) { struct iface *ifp; if ((ifp = if_lookup (argv[1])) != NULLIF) { /* 15May07, Now have hostmode exit for PTC-IIusb modem */ if (hfdd_is_ptc (ifp->name)) ptc_exit_hostmode (ifp->dev); /* 23Apr08, Maiko, Supporting PK232 now */ else if (hfdd_is_pk232 (ifp->name)) pk232_exit_hostmode (ifp->dev); else kam_exit_hostmode (ifp->dev); } } } else tprintf ("use: hfdd server [iface] [start|stop]\n"); return 0; }
int cmdparse( struct cmds cmds[], char *line, void *p ){ struct cmds *cmdp; char *argv[NARG]; char **pargv; int argc,i; /* Remove cr/lf */ rip(line); for(argc = 0;argc < NARG;argc++) argv[argc] = NULL; for(argc = 0;argc < NARG;){ int qflag = FALSE; /* Skip leading white space */ while(isspace(*line & 0xff)) line++; if(*line == '\0') break; /* '#' is start of comment */ if(*line == '#') break; /* Check for quoted token */ if(*line == '"'){ line++; /* Suppress quote */ qflag = TRUE; } argv[argc++] = line; /* Beginning of token */ if(qflag){ /* Find terminating delimiter */ if((line = stringparse(line)) == NULL){ return -1; } } else { /* Find space or tab. If not present, * then we've already found the last * token. */ while(*line && !isspace(*line & 0xff)) line++; } if(*line) *line++ = 0; } if (argc < 1) { /* empty command line */ argc = 1; argv[0] = ""; } if (argv[0][0] == '?') return print_help(cmds); /* Look up command in table; prefix matches are OK */ for(cmdp = cmds;cmdp->name != NULL;cmdp++){ if(strncmp(argv[0],cmdp->name,strlen(argv[0])) == 0) break; } if(cmdp->name == NULL) { if(cmdp->argc_errmsg != NULL) printf("%s\n",cmdp->argc_errmsg); return -1; } argv[0] = cmdp->name; if(argc < cmdp->argcmin) { /* Insufficient arguments */ printf("Usage: %s\n",cmdp->argc_errmsg); return -1; } if(cmdp->func == NULL) return 0; if(cmdp->stksize == 0){ return (*cmdp->func)(argc,argv,p); } else { #ifndef SINGLE_THREADED /* Make private copy of argv and args, * spawn off subprocess and return. */ pargv = (char **)callocw(argc,sizeof(char *)); for(i=0;i<argc;i++) pargv[i] = strdup(argv[i]); newproc(cmdp->name,cmdp->stksize, (void (*)(int,void *,void *))cmdp->func,argc,pargv,p,1); #endif return 0; } }