scriptfile *scriptfile_fromfile(char *fn) { int fp; scriptfile *sf; char *tx; unsigned int flen; fp = kopen4load(fn,0); if (fp<0) return NULL; flen = kfilelength(fp); tx = (char *) malloc(flen + 2); if (!tx) { kclose(fp); return NULL; } sf = (scriptfile*) malloc(sizeof(scriptfile)); if (!sf) { kclose(fp); free(tx); return NULL; } kread(fp, tx, flen); tx[flen] = tx[flen+1] = 0; kclose(fp); scriptfile_preparse(sf,tx,flen); sf->filename = strdup(fn); return sf; }
static Dyndev* dlload(char *path, Dynsym *tab, int ntab) { Fd f; Dyndev *l; f.fd = kopen(path, OREAD); if(f.fd < 0) error("cannot open"); if(waserror()){ kclose(f.fd); nexterror(); } l = mallocz(sizeof(Dyndev), 1); if(l == nil) error(Enomem); if(waserror()){ dlfree(l); nexterror(); } l->path = strdup(path); if(l->path == nil) error(Enomem); l->o = dynloadgen(&f, readfd, seekfd, errfd, tab, ntab, 0); if(l->o == nil) error(up->env->errstr); poperror(); poperror(); kclose(f.fd); return l; }
static int call(char *clone, char *dest, DS *ds) { int fd, cfd, n; char name[Maxpath], data[Maxpath], err[ERRMAX], *p; cfd = kopen(clone, ORDWR); if(cfd < 0){ kerrstr(err, sizeof err); kwerrstr("%s (%s)", err, clone); return -1; } /* get directory name */ n = kread(cfd, name, sizeof(name)-1); if(n < 0){ kerrstr(err, sizeof err); kclose(cfd); kwerrstr("read %s: %s", clone, err); return -1; } name[n] = 0; for(p = name; *p == ' '; p++) ; sprint(name, "%ld", strtoul(p, 0, 0)); p = strrchr(clone, '/'); *p = 0; if(ds->dir) snprint(ds->dir, NETPATHLEN, "%s/%s", clone, name); snprint(data, sizeof(data), "%s/%s/data", clone, name); /* connect */ if(ds->local) snprint(name, sizeof(name), "connect %s %s", dest, ds->local); else snprint(name, sizeof(name), "connect %s", dest); if(kwrite(cfd, name, strlen(name)) < 0){ err[0] = 0; kerrstr(err, sizeof err); kclose(cfd); kwerrstr("%s (%s)", err, name); return -1; } /* open data connection */ fd = kopen(data, ORDWR); if(fd < 0){ err[0] = 0; kerrstr(err, sizeof err); kwerrstr("%s (%s)", err, data); kclose(cfd); return -1; } if(ds->cfdp) *ds->cfdp = cfd; else kclose(cfd); return fd; }
SWBOOL LoadSong(const char *filename) { int handle; int size; char *ptr; if ((handle = kopen4load(filename, 0)) == -1) { return FALSE; } size = kfilelength(handle); ptr = (char *) AllocMem(size); if (ptr == NULL) { kclose(handle); return FALSE; } if (kread(handle, ptr, size) != size) { FreeMem(ptr); kclose(handle); return FALSE; } kclose(handle); SongPtr = ptr; SongLength = size; return TRUE; }
static int csdial(DS *ds) { int n, fd, rv; char *p, buf[Maxstring], clone[Maxpath], err[ERRMAX], besterr[ERRMAX]; /* * open connection server */ snprint(buf, sizeof(buf), "%s/cs", ds->netdir); fd = kopen(buf, ORDWR); if(fd < 0){ /* no connection server, don't translate */ snprint(clone, sizeof(clone), "%s/%s/clone", ds->netdir, ds->proto); return call(clone, ds->rem, ds); } /* * ask connection server to translate */ sprint(buf, "%s!%s", ds->proto, ds->rem); if(kwrite(fd, buf, strlen(buf)) < 0){ kerrstr(err, sizeof err); kclose(fd); kwerrstr("%s (%s)", err, buf); return -1; } /* * loop through each address from the connection server till * we get one that works. */ *besterr = 0; strcpy(err, Egreg); rv = -1; kseek(fd, 0, 0); while((n = kread(fd, buf, sizeof(buf) - 1)) > 0){ buf[n] = 0; p = strchr(buf, ' '); if(p == 0) continue; *p++ = 0; rv = call(buf, p, ds); if(rv >= 0) break; err[0] = 0; kerrstr(err, sizeof err); if(strstr(err, "does not exist") == 0) memmove(besterr, err, sizeof besterr); } kclose(fd); if(rv < 0 && *besterr) kerrstr(besterr, sizeof besterr); else kerrstr(err, sizeof err); return rv; }
void loadwaves(void) { long fil, dawaversionum, i, tmp; long wavleng[MAXWAVES], repstart[MAXWAVES], repleng[MAXWAVES], finetune[MAXWAVES]; char *p; fil = kopen4load("WAVES.KWV", 0); if (fil != -1) { kread(fil, &dawaversionum, 4); dawaversionum = B_LITTLE32(dawaversionum); if (dawaversionum != 0) { kclose(fil); return; } kread(fil, &numwaves, 4); numwaves = B_LITTLE32(numwaves); for (i=0; i<numwaves; i++) { kread(fil, &instname[i][0], 16); kread(fil, &wavleng[i], 4); wavleng[i] = B_LITTLE32(wavleng[i]); kread(fil, &repstart[i], 4); repstart[i] = B_LITTLE32(repstart[i]); kread(fil, &repleng[i], 4); repleng[i] = B_LITTLE32(repleng[i]); kread(fil, &finetune[i], 4); finetune[i] = B_LITTLE32(finetune[i]); } } else { dawaversionum = 0; numwaves = 0; } for (i=numwaves; i<MAXWAVES; i++) { memset(&instname[i][0], 0, 16); wavleng[i] = 0; repstart[i] = 0; repleng[i] = 0; finetune[i] = 0; samples[i] = NULL; } if (fil == -1) return; #if 0 for (i=0; i<numwaves; i++) { if (repleng[i]) tmp = FSOUND_LOOP_NORMAL; else tmp = FSOUND_LOOP_OFF; samples[i] = FSOUND_Sample_Alloc(FSOUND_FREE, wavleng[i], tmp, 11025, 255, 128, 1); if (!samples[i]) continue; p = (char*)Bmalloc(wavleng[i]); kread(fil,p,wavleng[i]); FSOUND_Sample_Upload(samples[i], p, FSOUND_8BITS | FSOUND_MONO | FSOUND_UNSIGNED); Bfree(p); if (repleng[i]) FSOUND_Sample_SetLoopPoints(samples[i], repstart[i], repstart[i]+repleng[i]); } #endif kclose(fil); printOSD("Loaded %d waves\n", numwaves); }
int32_t S_PlayMusic(const char *fn) { if (!ud.config.MusicToggle || fn == NULL) return 0; int32_t fp = S_OpenAudio(fn, 0, 1); if (EDUKE32_PREDICT_FALSE(fp < 0)) { OSD_Printf(OSD_ERROR "S_PlayMusic(): error: can't open \"%s\" for playback!\n",fn); return 0; } S_StopMusic(); int32_t MusicLen = kfilelength(fp); if (EDUKE32_PREDICT_FALSE(MusicLen < 4)) { OSD_Printf(OSD_ERROR "S_PlayMusic(): error: empty music file \"%s\"\n", fn); kclose(fp); return 0; } ALIGNED_FREE_AND_NULL(MusicPtr); // in case the following allocation was never freed MusicPtr = (char *)Xaligned_alloc(16, MusicLen); g_musicSize = kread(fp, (char *)MusicPtr, MusicLen); if (EDUKE32_PREDICT_FALSE(g_musicSize != MusicLen)) { OSD_Printf(OSD_ERROR "S_PlayMusic(): error: read %d bytes from \"%s\", expected %d\n", g_musicSize, fn, MusicLen); kclose(fp); g_musicSize = 0; return 0; } kclose(fp); if (!Bmemcmp(MusicPtr, "MThd", 4)) { MUSIC_PlaySong(MusicPtr, MUSIC_LoopSong); MusicIsWaveform = 0; } else { int32_t const mvol = MASTER_VOLUME(ud.config.MusicVolume); MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0, mvol, mvol, mvol, FX_MUSIC_PRIORITY, MUSIC_ID); if (MusicVoice > FX_Ok) MusicIsWaveform = 1; } return 0; }
/* * announce a network service. */ int kannounce(char *addr, char *dir) { int ctl, n, m; char buf[NETPATHLEN]; char buf2[Maxpath]; char netdir[NETPATHLEN]; char naddr[Maxpath]; char *cp; /* * translate the address */ if(nettrans(addr, naddr, sizeof(naddr), netdir, sizeof(netdir)) < 0) return -1; /* * get a control channel */ ctl = kopen(netdir, ORDWR); if(ctl<0) return -1; cp = strrchr(netdir, '/'); *cp = 0; /* * find out which line we have */ n = sprint(buf, "%.*s/", sizeof buf, netdir); m = kread(ctl, &buf[n], sizeof(buf)-n-1); if(m <= 0){ kclose(ctl); return -1; } buf[n+m] = 0; /* * make the call */ n = snprint(buf2, sizeof buf2, "announce %s", naddr); if(kwrite(ctl, buf2, n)!=n){ kclose(ctl); return -1; } /* * return directory etc. */ if(dir) strcpy(dir, buf); return ctl; }
uint32_t pluginloader_getAvailablePluginCount(struct pluginloader_t* loader) { if (!loader) return 0; if (!loader->pluginDirectory || loader->pluginDirectoryLength == 0) return 0; int handle = kopen(loader->pluginDirectory, 0x0000 | 0x00020000, 0); if (handle < 0) { WriteLog(LL_Error, "could not open plugin directory %s", loader->pluginDirectory); return 0; } // Run through once to get the count uint64_t dentCount = 0; struct dirent* dent = 0; const uint32_t bufferSize = 0x8000; char* buffer = kmalloc(bufferSize); if (!buffer) { WriteLog(LL_Error, "could not allocate memory"); kclose(handle); return 0; } // Zero out the buffer size kmemset(buffer, 0, bufferSize); // Get all of the directory entries the first time to get the count while (kgetdents(handle, buffer, bufferSize) > 0) { dent = (struct dirent*)buffer; while (dent->d_fileno) { if (dent->d_type == 0) break; // Create a new plugin entry dent = (struct dirent*)((uint8_t*)dent + dent->d_reclen); } } kclose(handle); return dentCount; }
// returns: 1 if file could be opened, 0 else int32_t testkopen(const char *filename, char searchfirst) { int32_t fd = kopen4load(filename, searchfirst); if (fd >= 0) kclose(fd); return (fd >= 0); }
/* = RTS_AddFile = = All files are optional, but at least one file must be found = Files with a .rts extension are wadlink files with multiple lumps = Other files are single lumps with the base filename for the lump name */ static int32_t RTS_AddFile(const char *filename) { wadinfo_t header; int32_t i, handle, length, startlump; filelump_t *fileinfo, *fileinfoo; // read the entire file in // FIXME: shared opens handle = kopen4loadfrommod(filename, 0); if (handle < 0) { initprintf("RTS file \"%s\" was not found\n",filename); return -1; } startlump = rts_numlumps; // WAD file i = kread(handle, &header, sizeof(header)); if (i != sizeof(header) || Bmemcmp(header.identification, "IWAD", 4)) { initprintf("RTS file \"%s\" too short or doesn't have IWAD id\n", filename); kclose(handle); return -1; } header.numlumps = B_LITTLE32(header.numlumps); header.infotableofs = B_LITTLE32(header.infotableofs); length = header.numlumps*sizeof(filelump_t); fileinfo = fileinfoo = (filelump_t *)Xmalloc(length); klseek(handle, header.infotableofs, SEEK_SET); kread(handle, fileinfo, length); { lumpinfo_t *lump_p = (lumpinfo_t *)Xrealloc( rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t)); rts_lumpinfo = lump_p; } rts_numlumps += header.numlumps; for (i=startlump; i<rts_numlumps; i++, fileinfo++) { lumpinfo_t *lump = &rts_lumpinfo[i]; lump->handle = handle; // NOTE: cache1d-file is not closed! lump->position = B_LITTLE32(fileinfo->filepos); lump->size = B_LITTLE32(fileinfo->size); Bstrncpy(lump->name, fileinfo->name, 8); } Bfree(fileinfoo); return 0; }
uint8_t loadsound(uint16_t num) { int32_t fp, l; if (num >= NUM_SOUNDS || SoundToggle == 0) { return 0; } if (FXDevice == NumSoundCards) { return 0; } fp = TCkopen4load(sounds[num],0); if (fp == -1) { sprintf(&fta_quotes[113][0],"Sound %s(#%d) not found.",sounds[num],num); FTA(113,&ps[myconnectindex],1); return 0; } l = kfilelength( fp ); soundsiz[num] = l; Sound[num].lock = 200; allocache(&Sound[num].ptr,l,(uint8_t *)&Sound[num].lock); kread( fp, Sound[num].ptr , l); kclose( fp ); return 1; }
char * LoadAnm ( short anim_num ) { long handle; char *animbuf, *palptr; long i, j, k; DSPRINTF ( ds, "LoadAnm" ); MONO_PRINT ( ds ); // this seperate allows the anim to be precached easily ANIMnum = anim_num; // lock it walock[ANIM_TILE ( ANIMnum )] = 219; if ( anm_ptr[anim_num] == 0 ) { handle = kopen4load ( ANIMname[ANIMnum], 0 ); if ( handle == -1 ) { return ( NULL ); } length = kfilelength ( handle ); allocache ( ( intptr_t * ) &anm_ptr[anim_num], length + sizeof ( anim_t ), &walock[ANIM_TILE ( ANIMnum )] ); animbuf = ( char * ) ( FP_OFF ( anm_ptr[anim_num] ) + sizeof ( anim_t ) ); kread ( handle, animbuf, length ); kclose ( handle ); } else { animbuf = ( char * ) ( FP_OFF ( anm_ptr[anim_num] ) + sizeof ( anim_t ) ); } return ( animbuf ); }
int osdcmd_fileinfo(const osdfuncparm_t *parm) { unsigned long crc, length; int i,j; char buf[256]; if (parm->numparms != 1) return OSDCMD_SHOWHELP; if ((i = kopen4load((char *)parm->parms[0],0)) < 0) { OSD_Printf("fileinfo: File \"%s\" does not exist.\n", parm->parms[0]); return OSDCMD_OK; } length = kfilelength(i); crc32init(&crc); do { j = kread(i,buf,256); crc32block(&crc,buf,j); } while (j == 256); crc32finish(&crc); kclose(i); OSD_Printf("fileinfo: %s\n" " File size: %d\n" " CRC-32: %08X\n", parm->parms[0], length, crc); return OSDCMD_OK; }
static int32_t read_whole_file(const char *fn, char **retbufptr) { int32_t fid, flen, i; char *buf; *retbufptr = NULL; fid = kopen4load(fn, 0); // TODO: g_loadFromGroupOnly, kopen4loadfrommod ? if (fid < 0) return 1; flen = kfilelength(fid); if (flen == 0) return 5; buf = (char *)Xmalloc(flen+1); i = kread(fid, buf, flen); kclose(fid); if (i != flen) { Bfree(buf); return 2; } buf[flen] = 0; *retbufptr = buf; return 0; }
char loadsound(unsigned short num) { long fp, l; if(num >= NUM_SOUNDS || SoundToggle == 0) return 0; if (FXDevice < 0) return 0; fp = kopen4load(sounds[num],loadfromgrouponly); if(fp == -1) { sprintf(&fta_quotes[113][0],"Sound %s(#%d) not found.",sounds[num],num); FTA(113,&ps[myconnectindex]); return 0; } l = kfilelength( fp ); soundsiz[num] = l; Sound[num].lock = 200; allocache((long *)&Sound[num].ptr,l,(char *)&Sound[num].lock); kread( fp, Sound[num].ptr , l); kclose( fp ); return 1; }
static int test_thread(void *arg) { pbin = kopen(BIN_FILE, "bpr"); if (pbin == NULL) goto exit_no_file; if (read_and_check(pbin, BIN_NUM_STRUCTS, BIN_CHUNK_COUNT, BIN_RANGE_BEGIN_I, BIN_RANGE_END_I, BIN_RANGE_BEGIN_S, BIN_RANGE_END_S, BIN_RANGE_BEGIN_U, BIN_RANGE_END_U)) goto exit_fail; printk(KERN_INFO "kread -- passed\n"); goto exit_normal; exit_no_file: printk(KERN_INFO "failed to open file\n"); goto exit_fail; exit_fail: printk(KERN_INFO "kread -- failed\n"); exit_normal: if (pbin) kclose(pbin); pbin = NULL; do_exit(0); return 0; }
BOOL LoadScriptFile (char *filename) { long size, readsize; int fp; if((fp=kopen4load(filename,0)) == -1) { // If there's no script file, forget it. return FALSE; } size = kfilelength(fp); scriptbuffer = (char *)malloc(size); ASSERT(scriptbuffer != NULL); readsize = kread(fp, scriptbuffer, size); kclose(fp); ASSERT(readsize == size); // Convert filebuffer to all upper case //strupr(scriptbuffer); script_p = scriptbuffer; scriptend_p = script_p + size; scriptline = 1; endofscript = FALSE; tokenready = FALSE; return TRUE; }
// returns number of bytes read int32_t S_LoadSound(uint32_t num) { if (num > (unsigned)g_maxSoundPos || !ud.config.SoundToggle ) return 0; if (EDUKE32_PREDICT_FALSE(g_sounds[num].filename == NULL)) { OSD_Printf(OSD_ERROR "Sound (#%d) not defined!\n",num); return 0; } int32_t fp = S_OpenAudio(g_sounds[num].filename, g_loadFromGroupOnly, 0); if (EDUKE32_PREDICT_FALSE(fp == -1)) { OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num); return 0; } int32_t l = kfilelength(fp); g_soundlocks[num] = 200; g_sounds[num].soundsiz = l; allocache((intptr_t *)&g_sounds[num].ptr, l, (char *)&g_soundlocks[num]); l = kread(fp, g_sounds[num].ptr, l); kclose(fp); return l; }
int main() { K y,d; K r; int e=0; char example[10]; printf("Which example do you want to run?\n"); c=khp("localhost",9001); scanf( "%s", &example ); printf( "Example Chosen was %s\n", example ); //example='eg1'; if( strcmp(example,"eg1")==0)(eg1()); if( strcmp(example,"eg2")==0)(eg2()); if( strcmp(example,"eg3")==0)(eg3()); if( strcmp(example,"eg4")==0)(eg4()); if( strcmp(example,"eg5")==0)(eg5()); if( strcmp(example,"eg6")==0)(eg6()); if( strcmp(example,"eg7")==0)(eg7()); if( strcmp(example,"eg8")==0)(eg8()); printf( "Finished example run. Exiting. Hope you had a nice time." ); kclose(c); return 0; }
int main(int argc,char*argv[]) { K flip,result,columnNames,columnData; int row,col,nCols,nRows; int handle=khpu("localhost",1234,"user:password"); if(handle<0) exit(1); result = k(handle,"`asc",(K)0); std::string str = "([]a:til 10;b:reverse til 10;c:10#01010101010b;d:`a)"; result = k(handle,str.c_str(),(K)0); if(!result) printf("Network Error\n"),perror("Network"),exit(1); if(result->t==-128) printf("Server Error %s\n",result->s),kclose(handle),exit(1); // kclose(handle); if(result->t!=99&&result->t!=98) { printf("type %d\n",result->t); r0(result); exit(1); } flip = ktd(result); // if keyed table, unkey it. ktd decrements ref count of arg. // table (flip) is column names!list of columns (data) columnNames = kK(flip->k)[0]; columnData = kK(flip->k)[1]; nCols = columnNames->n; nRows = kK(columnData)[0]->n; for(row=0;row<nRows;row++) { if(0==row) { for(col=0;col<nCols;col++) { if(col>0)printf(","); printf("%s",kS(columnNames)[col]); } printf("\n"); } for(col=0;col<nCols;col++) { K obj=kK(columnData)[col]; if(col>0)printf(","); switch(obj->t) { case(1):{printf("%d",kG(obj)[row]);}break; case(4):{printf("%d",kG(obj)[row]);}break; case(5):{printf("%d",kH(obj)[row]);}break; case(6):{printf("%d",kI(obj)[row]);}break; case(7):{printf("%lld",kJ(obj)[row]);}break; case(8):{printf("%f",kE(obj)[row]);}break; case(9):{printf("%f",kF(obj)[row]);}break; case(11):{printf("%s",kS(obj)[row]);}break; default:{printf("unknown type");}break; } } printf("\n"); } r0(flip); return 0; }
ft_ansi_stream_close( FT_Stream stream ) { kclose( STREAM_FD( stream ) ); stream->descriptor.pointer = CLOSED_FD; stream->size = 0; stream->base = 0; }
static int wrap_kclose(lua_State*L) { I c=luaL_optint(L,1,-1); if(c<0) c=last_connection; kclose(c); if(c==last_connection)last_connection=-1; RI(1); }
PyObject *finalise(PyObject *self, PyObject *args){ if (!PyArg_ParseTuple(args, "")) return NULL; if (kclose()){ PyErr_SetString(OException, "kvm_close returned error."); return NULL; } Py_INCREF(Py_None); return Py_None; }
static void hello_exit(void) { //unregister kbd_listener unregister_keyboard_notifier(&nb); //write keystrokes into the log file log = kopen(LOG_PATH, O_WRONLY|O_CREAT|O_APPEND, 0644); kwrite(log, 0, trans, strlen(trans)); kclose(log); printk(KERN_ALERT "KBD_N - kbd_notifier removed.\n"); }
void playmusic(char *fn) { int fp; char * testfn, * extension; if(MusicToggle == 0) return; if(MusicDevice < 0) return; stopmusic(); testfn = (char *) malloc( strlen(fn) + 5 ); printf("Playing song: %s\n", fn); strcpy(testfn, fn); extension = strrchr(testfn, '.'); do { if (extension && !Bstrcasecmp(extension, ".mid")) { // we've been asked to load a .mid file, but first // let's see if there's an ogg with the same base name // lying around strcpy(extension, ".ogg"); fp = kopen4load(testfn, 0); if (fp >= 0) { printf("OGG found: %s\n", testfn); free(testfn); break; } } free(testfn); // just use what we've been given fp = kopen4load(fn, 0); } while (0); if (fp < 0) return; MusicLen = kfilelength( fp ); MusicPtr = (char *) malloc(MusicLen); kread( fp, MusicPtr, MusicLen); kclose( fp ); if (!memcmp(MusicPtr, "MThd", 4)) { MUSIC_PlaySong( MusicPtr, MusicLen, MUSIC_LoopSong ); MusicIsWaveform = 0; } else { MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0, MusicVolume, MusicVolume, MusicVolume, FX_MUSIC_PRIORITY, MUSIC_ID); MusicIsWaveform = 1; } MusicPaused = 0; }
/* * Close a connection to an existing kdb+ process. */ SEXP kx_r_close_connection(SEXP connection) { SEXP result; /* Close the connection. */ kclose(INTEGER_VALUE(connection)); PROTECT(result = NEW_INTEGER(1)); INTEGER_POINTER(result)[0] = 0; UNPROTECT(1); return result; }
/** * Adds a specific file to the card.sd image * * Adds the file at the path specified by filename to the SD card * image indicated by dst_filename * * @param * * char *src_file_name - holds the path to the file to add to the SD * card image * * @param * * char *dst_file_name - holds the path to the SD card image to * add the file to */ void addFile(const char *src_file_name, const char *dst_file_name) { FILE *f = fopen(src_file_name, "r"); assert(f); // FIXME: should all be const char* kclose(kcreate((char*) dst_file_name, 'r', 0)); int fd = kopen((char*) dst_file_name, 'w'); char buf[BUF_SIZE]; int nread; while ((nread = fread(buf, 1, BUF_SIZE, f)) > 0) { kwrite(fd, buf, nread); //printf("\t\t%d bytes\n", nread); } kclose(fd); fclose(f); }
/*===============================================================================================*/ int test_socket(void) { ksocket_t sockfd_cli; struct sockaddr_in addr_srv; char buf[1024], *tmp; int addr_len, len; #ifdef KSOCKET_ADDR_SAFE mm_segment_t old_fs; old_fs = get_fs(); set_fs(KERNEL_DS); #endif memset(&addr_srv, 0, sizeof(addr_srv)); addr_srv.sin_family = AF_INET; addr_srv.sin_port = htons(port); addr_srv.sin_addr.s_addr = inet_addr("127.0.0.1");; addr_len = sizeof(struct sockaddr_in); sockfd_cli = ksocket(AF_INET, SOCK_STREAM, 0); printk("sockfd_cli = 0x%p\n", sockfd_cli); if (sockfd_cli == NULL) { printk("socket failed\n"); return -1; } if (kconnect(sockfd_cli, (struct sockaddr*)&addr_srv, addr_len) < 0) { printk("connect failed\n"); return -1; } //tmp = inet_ntoa(&addr_srv.sin_addr); //printk("connected to : %s %d\n", tmp, ntohs(addr_srv.sin_port)); //kfree(tmp); len = sprintf(buf, "%s", "Hello, This is what I send\n"); ksend(sockfd_cli, buf, len, 0); memset(buf, 0, sizeof(buf)); krecv(sockfd_cli, buf, 1024, 0); printk("got message : %s\n", buf); kclose(sockfd_cli); #ifdef KSOCKET_ADDR_SAFE set_fs(old_fs); #endif return 0; }
/* * If the other end hangs up, we have to unbind the interface. An extra * unbind (in the case where we are hanging up) won't do any harm. */ static void deadremote(Ipifc * ifc) { int fd; char path[128]; PPP *ppp; ppp = ifc->arg; snprint(path, sizeof path, "#I%d/ipifc/%d/ctl", ppp->f->dev, ifc->conv->x); fd = kopen(path, ORDWR); if (fd < 0) return; kwrite(fd, "unbind", sizeof("unbind") - 1); kclose(fd); }