Compare commits
5 commits
ec30d78d3c
...
519f9d415f
Author | SHA1 | Date | |
---|---|---|---|
|
519f9d415f | ||
|
c16666a3f9 | ||
|
0b2c90d5ff | ||
|
581fcd3f0a | ||
|
e03ef4d0e7 |
3 changed files with 29 additions and 16 deletions
|
@ -49,7 +49,7 @@ need it
|
||||||
- `screen` - for process supervision
|
- `screen` - for process supervision
|
||||||
- `source-highlight` - for syntax highlighting when displaying launching
|
- `source-highlight` - for syntax highlighting when displaying launching
|
||||||
scripts
|
scripts
|
||||||
- any text editor - used for builting function to edit launching scripts
|
- any text editor - used for builtin function to edit launching scripts
|
||||||
|
|
||||||
## Installation instructions
|
## Installation instructions
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ public_diskls() {
|
||||||
public_edit() {
|
public_edit() {
|
||||||
local file="${bin}/${1}"
|
local file="${bin}/${1}"
|
||||||
"$EDITOR" "$file"
|
"$EDITOR" "$file"
|
||||||
exec chmod u+x "$file"
|
[ -f "$file" ] && exec chmod u+x "$file"
|
||||||
}
|
}
|
||||||
|
|
||||||
public_rm() {
|
public_rm() {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define MIN_TCP_PORT 1
|
#define MIN_TCP_PORT 1
|
||||||
#define TCP_TABLE "/proc/net/tcp"
|
#define TCP_TABLE "/proc/net/tcp"
|
||||||
|
@ -12,6 +13,13 @@
|
||||||
#define LISTENING_HEX "0A"
|
#define LISTENING_HEX "0A"
|
||||||
#define PORTS_BLOCKS_TO_ALLOW 4
|
#define PORTS_BLOCKS_TO_ALLOW 4
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a nice error message
|
||||||
|
*/
|
||||||
|
static void print_error(char *name, const char *message) {
|
||||||
|
fprintf(stderr, "%s: %s\n", name, message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the listening TCP ports
|
* Get all the listening TCP ports
|
||||||
*/
|
*/
|
||||||
|
@ -81,20 +89,25 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_valid_tcp_port(current_port)) {
|
if (!is_valid_tcp_port(current_port)) {
|
||||||
fprintf(stderr, "Provide a valid TCP port number as first argument.\n");
|
print_error(argv[0], "provide a valid TCP port number as first argument.");
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open TCP table
|
// Open TCP table
|
||||||
FILE *tcp_table_fptr = fopen(TCP_TABLE, "r");
|
FILE *tcp_table_fptr = fopen(TCP_TABLE, "r");
|
||||||
if (tcp_table_fptr == NULL) {
|
if (tcp_table_fptr == NULL) {
|
||||||
fprintf(stderr, "Error opening the TCP table.\n");
|
print_error(argv[0], "error opening the TCP table.");
|
||||||
return EX_OSFILE;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short *listening_ports = malloc(PORTS_BLOCKS_TO_ALLOW * sizeof(unsigned short));
|
unsigned short *listening_ports = malloc(PORTS_BLOCKS_TO_ALLOW * sizeof(unsigned short));
|
||||||
listening_ports = get_listening_ports(listening_ports, tcp_table_fptr);
|
listening_ports = get_listening_ports(listening_ports, tcp_table_fptr);
|
||||||
|
|
||||||
|
if (fclose(tcp_table_fptr) != 0) {
|
||||||
|
print_error(argv[0], "can't close the TCP table.");
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the current port is available, add
|
// Check if the current port is available, add
|
||||||
while (!is_port_available(current_port, listening_ports)) {
|
while (!is_port_available(current_port, listening_ports)) {
|
||||||
current_port++;
|
current_port++;
|
||||||
|
@ -106,7 +119,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("%d\n", current_port);
|
printf("%d\n", current_port);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "No more ports available. How did you fuck up that bad ???\n");
|
print_error(argv[0], "no more ports available; how did you fuck up that bad ???");
|
||||||
return EX_TEMPFAIL;
|
return EX_TEMPFAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue