int main(int argc, char **argv) { int r; assert(argc==7); endaddr(&us,argv,1); endaddr(&them,argv,4); static const uint8_t mprefix[]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, }; static const uint8_t msuffix[]={ /* our nonce, fixed he he */ 0x8d, 0xf0, 0x3f, 0x35, 0xd6, 0xc8, 0x1f, 0xc0 }; int msglen= (sizeof(mprefix) + 2+strlen(us.name) + 2+strlen(them.name) + sizeof(msuffix)); uint8_t msg[msglen]; uint8_t *msgp=msg; #define PREFIXSUFFIX(prefixsuffix) do { \ memcpy(msgp,prefixsuffix,sizeof(prefixsuffix)); \ msgp += sizeof(prefixsuffix); \ }while(0) PREFIXSUFFIX(mprefix); endname(&msgp,&us); endname(&msgp,&them); PREFIXSUFFIX(msuffix); assert(msgp == msg+msglen); struct protoent *proto=getprotobyname("udp"); int fd=socket(AF_INET, SOCK_DGRAM, proto->p_proto); r=bind(fd,&us.sa,sizeof(us.sin)); if (r) { perror("bind us2"); exit(1); } for (;;) { r=sendto(fd,msg,msglen,0,&them.sa,sizeof(them.sin)); if (r < 0) perror("sendto"); r=getchar(); if (r==EOF) { if (ferror(stdin)) { perror("getchar"); exit(1); } break; } if (r!='\n') break; } exit(0); }
init_in() { int p; for (p = endaddr(); p < KERNENTRY; p += sizeof (int)) { if (*(int *)p != ENTRY || *(int *)(p + sizeof (int)) != 0 || *(int *)(p + sizeof (int) * 2) != 0) continue; p += sizeof (int) * 3; if (bcmp((char *)p, magic, MAGICSIZE) == 0) { kern_len = *(int *)(p + MAGICSIZE); bcopy((char *)(p + MAGICSIZE + KERNLENSIZE), (char *)KERNENTRY, kern_len); break; } } }
void init_in() { int p; for (p = endaddr(); p < KERNENTRY; p += sizeof (int)) { if (*(int *)p != BEBOX_ENTRY || *(int *)(p + sizeof (int)) != 0 || *(int *)(p + sizeof (int) * 2) != 0) continue; p += sizeof (int) * 3; if (memcmp((char *)p, bebox_magic, BEBOX_MAGICSIZE) == 0) { kern_len = *(int *)(p + BEBOX_MAGICSIZE); memcpy((char *)KERNENTRY, (char *)(p + BEBOX_MAGICSIZE + KERNLENSIZE), kern_len); break; } } }