Jump to content

fugu

Active Members
  • Posts

    197
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by fugu

  1. So i agree, those changes you recommended seem really good.and the //if (written_bytes == 0) ; //*buffer += written_bytes; doesnt seem to do anything. I thought it might look like is was moving the position of the buffer if the write operation had to handle more bytes then where inside the char buffer[] variable, but i tested the program with a very small buffer [20], and I just removed the above 2 lines of extra code, moved much more bytes then coulda fit into the buffer, and it appears to run fine without it. mkfifo(myfdin, 0600); mkfifo(myfdout, 0600); just the user level needs to be able to read and write from each pipe, but the others don't need any permissions. close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); those were all really redundant, replacing them with breaks simplifies this code. programming in C is not an area I know a lot about, so thank you for your help. Ill keep working at it to see if I can make it better
  2. there is a package called ucspi-tcp (apt-get install ucspi-tcp) that i found to be really neat. The tcpserver program works very simillar to netcat -l with the exception that it is multi-threaded. The problem is that it can only execute 1 program for each thread, and that thread is not associated with the stdin/stdout of any terminal, so you can't really use it as a netcat in the ways that you normally do. I managed to find some code which is listed below that does what I couldn't figure out how to do in bash. it basiclly sets up 2 fifo's for each thread that connects to the tcpserver. what would be nice is if it also executed am xterm or somthing also with those pipes connected as well. Cheers #include <errno.h> #include <fcntl.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> int main(int argc, char *argv[]){ struct pollfd poll_file_descriptor[2]; char buffer[2048]; char *myfdin = ""; char *myfdout = ""; int fdin, fdout, index = 0, read_bytes, ret, written_bytes; int quit = 0, file1exists = 0, file2exists = 0; if(argc > 2){ myfdin = argv[1]; myfdout = argv[2]; }else{ index = 0; do{ index++; if(index>=99999){ return -1; } sprintf(buffer, "/tmp/std_in_%05d", index); if(access(buffer , F_OK ) != -1) { file1exists = 1; } else { file1exists = 0; } myfdin = (char *) malloc(sizeof(char)*(strlen(buffer))); memcpy(myfdin, &buffer, strlen(buffer)+1); sprintf(buffer,"/tmp/std_out_%05d", index); if(access(buffer , F_OK ) != -1) { file2exists = 1; } else { file2exists = 0; } myfdout = (char *) malloc(sizeof(char)*(strlen(buffer))); memcpy(myfdout, &buffer, strlen(buffer)+1); }while(file1exists == 1 || file2exists == 1); } mkfifo(myfdin, 0666); mkfifo(myfdout, 0666); fdin = open(myfdin, O_RDONLY); fdout = open(myfdout, O_WRONLY); while (quit == 0) { poll_file_descriptor[0].fd = fdin; poll_file_descriptor[0].events = 1; poll_file_descriptor[0].revents = 0; poll_file_descriptor[1].fd = STDIN_FILENO; poll_file_descriptor[1].events = 1; poll_file_descriptor[1].revents = 0; poll(poll_file_descriptor,2,1200000); //20 minutes if (poll_file_descriptor[0].revents != 0) { read_bytes = read(fdin, buffer, sizeof(buffer)); if(read_bytes < 0){ close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); return -1; } if(read_bytes == 0) quit = 1; while (read_bytes != 0) { written_bytes = write(STDOUT_FILENO,buffer,read_bytes); if (written_bytes == -1) { if (errno == EINTR){ continue; } ret = -1; read_bytes = 0; }else{ if (written_bytes == 0) ; *buffer += written_bytes; read_bytes -= written_bytes; } } if(ret == -1){ close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); return -1; } } if (poll_file_descriptor[1].revents != 0) { read_bytes = read(STDIN_FILENO, buffer, sizeof(buffer)); if(read_bytes < 0){ close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); return -1; } if(read_bytes == 0) quit = 1; while (read_bytes != 0) { written_bytes = write(fdout, buffer, read_bytes); if (written_bytes == -1) { if (errno == EINTR){ continue; } ret = -1; read_bytes = 0; }else{ if (written_bytes == 0) ; *buffer += written_bytes; read_bytes -= written_bytes; } } if(ret == -1){ close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); return -1; } } if (poll_file_descriptor[0].revents == 0 && poll_file_descriptor[1].revents == 0){ close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); return -1; } } close(fdout); close(fdin); unlink(myfdin); unlink(myfdout); return 0; } $ gcc -o juggle juggle.c $ tcpserver 192.168.1.100 4444 ./juggle $ while read cmd; do echo "$cmd"; done > /tmp/std_in_00001 $ cat /tmp/std_out_00001 Edit: formatting
  3. Terminal 1 $ tail -f mystdin | nc -v -l 1025 > mystdout Terminal 2 $ cat mystdout | tail -f Terminal 3 echo 'Hello World' > mystdin This allows remote connection, doesn't output anything in terminal 2 (probabley because cat dumps the entire contents of the fifo (just the EOF) all at once and is done with it at that point) If I try Terminal 1 $ tail -f mystdin | nc -v -l 1025 Terminal 3 echo 'Hello World' > mystdin This allows remote connection, but i don't get mystdout redircted. But it hints at the problem which I think might be the output pipe.
  4. yeah its listeningtcp 0 0 0.0.0.0:1025 0.0.0.0:* LISTEN 31337/nc Im trying to figure out if you can create a simple network service in linux, just using bash, for instances where you don't have direct acces to a real terminal, but you can access fifo pipes that can recreate the inputs and outputs for the service. I'm just using the netcat-openbsd package the command "mkfifo output; nc -l -p 1025" doesn't actually link "output" to anything with netcat, the two commands are independent. I also try an stay away from testing netcat using 'localhost' as on a few rare ocassions it's localhost behavior is different from it's remote host behavior. I've been toying with the idea of something like this $ mkfifo mystdout $ mkfifo mystdin $ tail -f mystdin | nc -l 1025 > mystdout then in another terminal $ tail -f mystdout havn't figured out how to stream into the mystdin stream, I can see that nc is listening, but cannot connect remotely
  5. so thats what I was thinking too, but it doesnt work. a remote nc instance won't connect up to it. it immediately disconnects and you can't use it. I even tried with -q after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever.but it didn't work eitheredit for typo
  6. I need someone with some bashfu. I would like a bash script that can execute a nc -l -p 1025 command, then redirect the stdout to 1 mkfifo and the stdin to a 2nd mkfifo. anyone know how to do that? tyvm
  7. the ip addr "169.xx" smells liek mulicast ick i think the windoze zeroconf like service can reg that address when it has no dhcp. windoze networking is crappy. go into manage wireless networks and remove everything and try again.
  8. <br /> <br /> I'm not sure if this is true or not, but I think the problem comes down to python's twisted libraries. I've played around with twisted a while back and was not impressed with its functionality.
  9. Can the mk5 run nginx? Is it hard to setup? what about php?
  10. I've been playing around with the idea of the possibiliity of one ducky script + batch/bash script to rule them all This is a batch/bash part Filename: autorun.bat #!/bin/bash goto :next # ENTER LINUX CODE HERE!!!!!!! echo 'This is the linux part of the script' if [ -n "$(which lsb_release)" ]; then lsb_release -d | sed 's~^Description:\t\(.*\)~\1~g'; fi # EOF LINUX exit 0 :next @echo off REM wine doesnt understand FINDSTR, REM where as windows does echo "YES" | FINDSTR /L "NO" > NUL IF %ERRORLEVEL% EQU 0 goto :wine SET OSVersion=Unknown VER | FINDSTR /L "5.0" > NUL IF %ERRORLEVEL% EQU 0 SET OSVersion=2000 VER | FINDSTR /L "5.1." > NUL IF %ERRORLEVEL% EQU 0 SET OSVersion=XP VER | FINDSTR /L "5.2." > NUL IF %ERRORLEVEL% EQU 0 SET OSVersion=2003 VER | FINDSTR /L "6.0." > NUL IF %ERRORLEVEL% EQU 0 SET OSVersion=Vista VER | FINDSTR /L "6.1." > NUL IF %ERRORLEVEL% EQU 0 SET OSVersion=7 VER | FINDSTR /L "6.2." > NUL IF %ERRORLEVEL% EQU 0 SET OSVersion=8 REM ENTER WINDOWS CODE HERE!!!!!!! echo This is the windows part of the script IF %OSVersion%==Unknown ( ECHO Unable to determine your version of Windows. ) ELSE ( ECHO You appear to be using Windows %OSVersion% ) ECHO. PAUSE REM EOF WINDOWS exit 0 :wine REM ENTER WINE CODE HERE!!!!!!! echo This is the wine part of the script ECHO You appear to be using Wine REM EOF WINE exit 0
  11. there are a few reasons why a port may not be seen as 'open' from an external machine. The 2 major reasons why it may look closed are that !) the firewall is blocking the port of interest or 2) there is no application currently listening on that port. Try running $ sudo netstat -auntp | grep '443' to see if anything is running on port 443
  12. From http://sdr.osmocom.org/trac/wiki/rtl-sdr (you probably need to apt-get some stuff first, like cmake) $ git clone git://git.osmocom.org/rtl-sdr.git ... $ cd rtl-sdr/ $ mkdir build $ cd build $ cmake ../ -DINSTALL_UDEV_RULES=ON $ make $ sudo make install $ sudo ldconfig $ rtl_fm -f 96.3e6 -W -s 200000 -r 48000 - | aplay -r 48k -f S16_LE where 96.3 will ba a local radio station If you want to install gnuradio and if your using a *nix distro, i've found that the bash script at http://www.sbrac.org/files/build-gnuradio works really well $ wget http://www.sbrac.org/files/build-gnuradio $ chmod +x build-gnuradio $ ./build-gnuradio (that last one might need sudo privs, i can't remember)
×
×
  • Create New...