static int UDPSendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, u_char *data, int dataLen) { struct sockaddr_in toaddr,*dest; int i=dataLen; int bcast; char *buf; #ifdef UDPDEBUG msg("SendPacket enter, dataLen=%d",dataLen); #endif if (dataLen<0 || dataLen>MAX_PACKETSIZE) return -1; chk(buf=alloca(8+dataLen)); if (compatibility) { memcpy(buf+0,D1Xudp,6); buf+=6; } else { memcpy(buf+0,D1Xid ,2); buf+=2; } memcpy(buf+0,IPXHeader->Destination.Socket,2); memcpy(buf+2,data,dataLen); toaddr.sin_family=AF_INET; memcpy(&toaddr.sin_addr,IPXHeader->Destination.Node+0,4); toaddr.sin_port= htons(((short)ntohs(*(unsigned short *)(IPXHeader->Destination.Node+4)))+UDP_BASEPORT); for (bcast=(toaddr.sin_addr.s_addr==htonl(INADDR_BROADCAST)?0:-1);bcast<broadnum;bcast++) { if (bcast>=0) dest=broads+bcast; else dest=&toaddr; #ifndef _WIN32 # ifdef UDPDEBUG /* printf(MSGHDR "sendto((%d),Node=[4] %02X %02X,Socket=%02X %02X,s_port=%u,", dataLen, IPXHeader->Destination.Node [4], IPXHeader->Destination.Node [5], IPXHeader->Destination.Socket[0], IPXHeader->Destination.Socket[1], ntohs(dest->sin_port); */ dumpaddr(dest); //puts(")."); # endif #endif i=sendto(mysock->fd,buf-(compatibility?6:2),(compatibility?8:4)+dataLen, 0,(struct sockaddr *)dest,sizeof(*dest)); if (bcast==-1) { int h; if (i == SOCKET_ERROR) h = WSAGetLastError (); return (i<8?-1:i-8); } } return(dataLen); }
void k_debugger(regs *r,uint32 eip, uint32 cs, uint32 eflags) { char *line; uint32 n; kprintf("OpenBLT Kernel Debugger"); for(;;){ krefresh(); line = kgetline(linebuf,80); if(!strncmp(line,"pgroup ",7)) { dumppgroup(readnum(line+7)); continue; } if(!strncmp(line,"resource ", 9)) { dumponersrc(line+9); continue; } if(!strcmp(line,"resources")) { dumprsrc(&resource_list); continue; } if(!strncmp(line,"queue ",6)) { dumpqueue(readnum(line+6)); continue; } if(!strcmp(line,"tasks")) { dumptasks(); continue; } if(!strcmp(line,"ports")) { dumpports(); continue; } if(!strcmp(line,"memory")) { memory_status(); continue; } if(!strcmp(line,"trace")) { trace(r->ebp,eip); continue; } if(!strcmp(line,"regs")) { print_regs(r,eip,cs,eflags); continue; } if(!strncmp(line,"dump ",5)) { dump(readnum(line+5),16); continue; } if(!strncmp(line,"aspace ",7)) { dumpaddr(readnum(line+7)); continue; } if(!strcmp(line,"reboot")) { reboot(); } if(!strncmp(line,"checksum ",9)) { checksum(line+9); continue; } if(!strncmp(line,"team ",5)) { dumpteam(readnum(line+5)); continue; } if(!strncmp(line,"find ",5)) { findpage(readnum(line+5)); continue; } if(!strcmp(line,"teams")) { dumpteams(); continue; } if(!strcmp(line,"exit")) break; if(!strcmp(line,"x")) break; if(!strcmp(line,"c")) break; } }
/* Handle the netgame aux data * Byte 0 is the protocol version number. * Bytes 1-4 are the IPv4 multicast session to join, in network byte order. */ static int ipx_mcast4_HandleNetgameAuxData(ipx_socket_t *sk, const u_char buf[NETGAME_AUX_SIZE]) { // Extract the multicast session and subscribe to it. We should // now be getting packets intended for the players of this game. // Note that we stay subscribed to the game announcement session, // so we can reply to game info requests struct ip_mreq mreq; int ttl = 128; // Check the protocol version if(buf[0] != IPX_MCAST4_VERSION) { #ifdef _GNUC FAIL("mcast4 protocol\nversion mismatch!\nGame version is %02x,\nour version is %02x", buf[0], IPX_MCAST4_VERSION); #else FAIL("mcast4 protocol version mismatch!"); #endif } // Get the multicast session memcpy(&game_addr, buf + 1, sizeof(game_addr)); #ifdef IPX_MCAST4_DEBUG { struct sockaddr_in tmpaddr; tmpaddr.sin_addr = game_addr; tmpaddr.sin_port = 0; //printf("Handling netgame aux data: Subscribing to "); dumpaddr(&tmpaddr); ////puts(""); } #endif // Set the TTL so the packets can get out of the local network. if(setsockopt(sk->fd, IPPROTO_IP, IP_MULTICAST_TTL, (const void*)&ttl, sizeof(ttl)) < 0) FAIL("setsockopt() failed to set TTL to 128"); memset(&mreq, 0, sizeof(mreq)); mreq.imr_multiaddr = game_addr; mreq.imr_interface.s_addr = INADDR_ANY; if(setsockopt(sk->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void*)&mreq, sizeof(mreq)) < 0) FAIL("setsockopt() failed to subscribe to the game group"); return 0; }
static int ipx_mcast4_ReceivePacket(ipx_socket_t *sk, ubyte *outbuf, int outbufsize, struct ipx_recv_data *rd) { int size; struct sockaddr_in fromaddr; int fromaddrsize = sizeof(fromaddr); if((size = recvfrom(sk->fd, outbuf, outbufsize, 0, (struct sockaddr*)&fromaddr, &fromaddrsize)) < 0) return -1; #ifdef IPX_MCAST4_DEBUG //printf(MSGHDR "Got packet from "); dumpaddr(&fromaddr); //puts(""); #endif // We have the packet, now fill out the receive data. memset(rd, 0, sizeof(*rd)); memcpy(rd->src_node, &fromaddr.sin_addr, 4); // TODO: Include the port like in ipx_udp.c rd->pktType = 0; return size; }
static int ipx_mcast4_SendPacket(ipx_socket_t *sk, IPXPacket_t *IPXHeader, u_char *data, int dataLen) { struct sockaddr_in toaddr; int i; //msg("SendPacket enter, dataLen=%d", dataLen); if(dataLen < 0 || dataLen > MAX_PACKETSIZE) return -1; toaddr.sin_family = AF_INET; memcpy(&toaddr.sin_addr, IPXHeader->Destination.Node + 0, 4); //toaddr.sin_port = htons(((short)ntohs(*(unsigned short *)(IPXHeader->Destination.Node + 4))) + UDP_BASEPORT); // For now, just use the same port for everything toaddr.sin_port = htons(UDP_BASEPORT); // If it's the broadcast address, then we want to send it to the // GAME ANNOUNCEMENT address. // Data to be sent to the GAME has the destination already set by // ipx_mcast4_SendGamePacket if(toaddr.sin_addr.s_addr == INADDR_BROADCAST) toaddr.sin_addr.s_addr = DESCENT2_ANNOUNCE_ADDR; #ifdef IPX_MCAST4_DEBUG /*printf(MSGHDR "sendto((%d),Node=[4] %02X %02X,Socket=%02X %02X,s_port=%u,", dataLen, IPXHeader->Destination.Node[4], IPXHeader->Destination.Node[5], IPXHeader->Destination.Socket[0], IPXHeader->Destination.Socket[1], ntohs(toaddr.sin_port); */ dumpaddr(&toaddr); //puts(")."); #endif i = sendto(sk->fd, data, dataLen, 0, (struct sockaddr *)&toaddr, sizeof(toaddr)); return i; }
static int UDPReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize, struct ipx_recv_data *rd) { int size; struct sockaddr_in fromaddr; int fromaddrsize=sizeof(fromaddr); unsigned short ports; size_t offs; int i; if ((size=recvfrom(s->fd,outbuf,outbufsize,0,(struct sockaddr *)&fromaddr,&fromaddrsize))<0) return -1; #ifndef _WIN32 # ifdef UDPDEBUG ////printf(MSGHDR "recvfrom((%d-8=%d),",size,size-8); dumpaddr(&fromaddr); //puts(")."); # endif #endif if (fromaddr.sin_family!=AF_INET) return -1; if (size<4) return -1; if (memcmp(outbuf+0,D1Xid,2)) { if (size<8 || memcmp(outbuf+0,D1Xudp,6)) return -1; if (!compatibility) { compatibility=1; fputs(MSGHDR "Received obsolete packet from ",stdout); dumpaddr(&fromaddr); //puts(", upgrade that machine.\n" MSGHDR "Turning on compatibility mode..."); } offs=6; } else offs=2; /* Lace: (dst_socket & src_socket) should be network-byte-order by comment in include/ipx_drv.h */ /* This behaviour presented here is broken. It is not used anywhere, so why bother? */ rd->src_socket = ntohs(*(unsigned short *)(outbuf+offs)); if (rd->src_socket != s->socket) { #ifdef UDPDEBUG msg(" - pkt was dropped (dst=%d,my=%d)",rd->src_socket,s->socket); #endif return -1; } rd->dst_socket = s->socket; // check if we already have sender of this packet in broadcast list for (i=0;i<broadnum;i++) { if (i>=masksnum) { if (addreq(fromaddr,broads[i])) break; } else { if (fromaddr.sin_port==broads[i].sin_port &&( fromaddr.sin_addr.s_addr & broadmasks[i].sin_addr.s_addr) ==(broads[i].sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)) break; } } if (i>=broadnum) { // we don't have sender of this packet in our broadcast list chkbroadsize(); broads[broadnum++]=fromaddr; fputs(MSGHDR "Adding host ",stdout); dumpaddr(&fromaddr); //puts(" to broadcasting address list"); } memmove(outbuf,outbuf+offs+2,size-(offs+2)); size-=offs+2; memcpy(rd->src_node+0,&fromaddr.sin_addr,4); ports=htons(ntohs(fromaddr.sin_port)-UDP_BASEPORT); memcpy(rd->src_node+4,&ports,2); memset(rd->src_network, 0, 4); rd->pktType = 0; #ifndef _WIN32 # ifdef UDPDEBUG ////printf(MSGHDR "ReceivePacket: size=%d,from=",size); dumpraddr(rd->src_node); ////putchar('\n'); # endif #endif return size; }
int UDPGetMyAddress(void) { char buf[256]; int i; char *s,*s2,*ns; if (!have_empty_address()) return 0; if (!((i=FindArg("-udp")) && (s=Args[i+1]) && (*s=='=' || *s=='+' || *s=='@'))) s=NULL; if (gethostname(buf,sizeof(buf))) FAIL("Error getting my hostname"); if (!queryhost(buf)) FAIL("Querying my own hostname \"%s\"",buf); if (s) while (*s=='@') { portshift(++s); while (isdigit(*s)) s++; } memset(ipx_MyAddress+0,0,4); memcpy(ipx_MyAddress+4,qhbuf,6); baseport+=(short)ntohs(*(unsigned short *)(qhbuf+4)); #if 0 ipx_MyAddress [4] = 127; ipx_MyAddress [5] = 0; ipx_MyAddress [6] = 0; ipx_MyAddress [7] = 1; #endif if (!(s && *s)) addiflist(); else { if (*s=='+') addiflist(); s++; for (;;) { struct sockaddr_in *sin; while (isspace(*s)) s++; if (!*s) break; for (s2=s;*s2 && *s2!=',';s2++) ; chk(ns=D2_ALLOC(s2-s+1)); memcpy(ns,s,s2-s); ns[s2-s]='\0'; if (!queryhost(ns)) msg("Ignored broadcast-destination \"%s\" as being invalid",ns); D2_FREE(ns); chkbroadsize(); sin=broads+(broadnum++); sin->sin_family=AF_INET; memcpy(&sin->sin_addr,qhbuf+0,4); sin->sin_port=htons(((short)ntohs(*(unsigned short *)(qhbuf+4)))+UDP_BASEPORT); s=s2+(*s2==','); } } unifyiflist(); #ifndef _WIN32 //printf(MSGHDR "Using TCP/IP address "); dumpraddr(ipx_MyAddress+4); //putchar('\n'); if (broadnum) { //printf(MSGHDR "Using %u broadcast-dest%s:",broadnum,(broadnum==1?"":"s")); for (i=0;i<broadnum;i++) { //putchar(' '); dumpaddr(broads+i); } //putchar('\n'); } #endif return 0; }