serverlogslocked = 0;
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--verbose", argv[arg])) {
arg++;
/* nothing yet */
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- port = (unsigned short)atoi(argv[arg]);
+ opt = argv[arg];
+ if(!curlx_str_number(&opt, &num, 0xffff))
+ port = (unsigned short)num;
arg++;
}
}
extern char *data_to_hex(char *data, size_t len);
extern void logmsg(const char *msg, ...);
extern void loghex(unsigned char *buffer, ssize_t len);
-extern unsigned char byteval(char *value);
extern int win32_init(void);
extern FILE *test2fopen(long testno, const char *logdir2);
extern curl_off_t our_getpid(void);
while(fgets(buffer, sizeof(buffer), fp)) {
char key[32];
char value[32];
+ const char *pval;
+ curl_off_t num;
if(sscanf(buffer, "%31s %31s", key, value) == 2) {
if(!strcmp(key, "version")) {
- m_config.version = byteval(value);
- logmsg("version [%d] set", m_config.version);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ m_config.version = (unsigned char)num;
+ logmsg("version [%d] set", m_config.version);
+ }
}
else if(!strcmp(key, "PUBLISH-before-SUBACK")) {
logmsg("PUBLISH-before-SUBACK set");
m_config.short_publish = TRUE;
}
else if(!strcmp(key, "error-CONNACK")) {
- m_config.error_connack = byteval(value);
- logmsg("error-CONNACK = %d", m_config.error_connack);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ m_config.error_connack = (unsigned char)num;
+ logmsg("error-CONNACK = %d", m_config.error_connack);
+ }
}
else if(!strcmp(key, "Testnum")) {
- m_config.testnum = atoi(value);
- logmsg("testnum = %d", m_config.testnum);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, INT_MAX)) {
+ m_config.testnum = (int)num;
+ logmsg("testnum = %d", m_config.testnum);
+ }
}
else if(!strcmp(key, "excessive-remaining")) {
logmsg("excessive-remaining set");
server_port = 1883; /* MQTT default port */
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--version", argv[arg])) {
printf("mqttd IPv4%s\n",
#ifdef USE_IPV6
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- int inum = atoi(argv[arg]);
- if(inum && ((inum < 1025) || (inum > 65535))) {
+ opt = argv[arg];
+ if(curlx_str_number(&opt, &num, 0xffff) || num < 1025) {
fprintf(stderr, "mqttd: invalid --port argument (%s)\n",
argv[arg]);
return 0;
}
- server_port = (unsigned short)inum;
+ server_port = (unsigned short)num;
arg++;
}
}
&prot_major,
&prot_minor) == 5) {
char *ptr;
+ const char *pval;
+ curl_off_t testnum;
if(!strcmp(prot_str, "HTTP")) {
req->protocol = RPROT_HTTP;
while(*ptr && !ISDIGIT(*ptr))
ptr++;
- req->testno = atol(ptr);
+ pval = ptr;
+ if(!curlx_str_number(&pval, &testnum, INT_MAX))
+ req->testno = (long)testnum;
+ else {
+ req->protocol = RPROT_NONE;
+ logmsg("rtspd: failed to read the test number from '%s'", doc);
+ return 1;
+ }
if(req->testno > 10000) {
req->partno = req->testno % 10000;
/* if the host name starts with test, the port number used in the
CONNECT line will be used as test number! */
char *portp = strchr(doc, ':');
- if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1)))
- req->testno = atol(portp + 1);
+ if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1))) {
+ pval = portp + 1;
+ if(!curlx_str_number(&pval, &testnum, INT_MAX))
+ req->testno = (long)testnum;
+ else
+ req->testno = DOCNUMBER_CONNECT;
+ }
else
req->testno = DOCNUMBER_CONNECT;
}
serverlogslocked = 0;
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--version", argv[arg])) {
printf("rtspd IPv4%s"
"\n"
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- port = (unsigned short)atol(argv[arg]);
+ opt = argv[arg];
+ if(!curlx_str_number(&opt, &num, 0xffff))
+ port = (unsigned short)num;
arg++;
}
}
server_port = 8999;
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--version", argv[arg])) {
printf("sockfilt IPv4%s\n",
#ifdef USE_IPV6
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- server_port = (unsigned short)atol(argv[arg]);
+ opt = argv[arg];
+ if(!curlx_str_number(&opt, &num, 0xffff))
+ server_port = (unsigned short)num;
arg++;
}
}
doing a passive server-style listening. */
arg++;
if(argc > arg) {
- int inum = atoi(argv[arg]);
- if(inum && ((inum < 1025) || (inum > 65535))) {
+ opt = argv[arg];
+ if(curlx_str_number(&opt, &num, 0xffff) || num < 1025) {
fprintf(stderr, "sockfilt: invalid --connect argument (%s)\n",
argv[arg]);
return 0;
}
- server_connectport = (unsigned short)inum;
+ server_connectport = (unsigned short)num;
arg++;
}
}
strcpy(s_config.password, "password");
}
-static unsigned short shortval(char *value)
-{
- unsigned long num = (unsigned long)atol(value);
- return num & 0xffff;
-}
-
static void socksd_getconfig(void)
{
FILE *fp = fopen(configfile, FOPEN_READTEXT);
while(fgets(buffer, sizeof(buffer), fp)) {
char key[32];
char value[260];
+ const char *pval;
+ curl_off_t num;
if(sscanf(buffer, "%31s %259s", key, value) == 2) {
if(!strcmp(key, "version")) {
- s_config.version = byteval(value);
- logmsg("version [%d] set", s_config.version);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ s_config.version = (unsigned char)num;
+ logmsg("version [%d] set", s_config.version);
+ }
}
else if(!strcmp(key, "nmethods_min")) {
- s_config.nmethods_min = byteval(value);
- logmsg("nmethods_min [%d] set", s_config.nmethods_min);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ s_config.nmethods_min = (unsigned char)num;
+ logmsg("nmethods_min [%d] set", s_config.nmethods_min);
+ }
}
else if(!strcmp(key, "nmethods_max")) {
- s_config.nmethods_max = byteval(value);
- logmsg("nmethods_max [%d] set", s_config.nmethods_max);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ s_config.nmethods_max = (unsigned char)num;
+ logmsg("nmethods_max [%d] set", s_config.nmethods_max);
+ }
}
else if(!strcmp(key, "backend")) {
strcpy(s_config.addr, value);
logmsg("backend [%s] set", s_config.addr);
}
else if(!strcmp(key, "backendport")) {
- s_config.port = shortval(value);
- logmsg("backendport [%d] set", s_config.port);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xffff)) {
+ s_config.port = (unsigned short)num;
+ logmsg("backendport [%d] set", s_config.port);
+ }
}
else if(!strcmp(key, "user")) {
strcpy(s_config.user, value);
o X'02' USERNAME/PASSWORD
*/
else if(!strcmp(key, "method")) {
- s_config.responsemethod = byteval(value);
- logmsg("method [%d] set", s_config.responsemethod);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ s_config.responsemethod = (unsigned char)num;
+ logmsg("method [%d] set", s_config.responsemethod);
+ }
}
else if(!strcmp(key, "response")) {
- s_config.connectrep = byteval(value);
- logmsg("response [%d] set", s_config.connectrep);
+ pval = value;
+ if(!curlx_str_number(&pval, &num, 0xff)) {
+ s_config.connectrep = (unsigned char)num;
+ logmsg("response [%d] set", s_config.connectrep);
+ }
}
}
}
server_port = 8905;
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--version", argv[arg])) {
printf("socksd IPv4%s\n",
#ifdef USE_IPV6
}
else if(!strcmp("--backendport", argv[arg])) {
arg++;
- if(argc > arg)
- backendport = (unsigned short)atoi(argv[arg++]);
+ if(argc > arg) {
+ opt = argv[arg];
+ if(!curlx_str_number(&opt, &num, 0xffff))
+ backendport = (unsigned short)num;
+ arg++;
+ }
}
else if(!strcmp("--logfile", argv[arg])) {
arg++;
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- server_port = (unsigned short)atol(argv[arg]);
+ opt = argv[arg];
+ if(!curlx_str_number(&opt, &num, 0xffff))
+ server_port = (unsigned short)num;
arg++;
}
}
int prot_major = 0;
int prot_minor = 0;
char *end = strstr(line, end_of_headers);
+ const char *pval;
+ curl_off_t num;
req->callcount++;
ptr++; /* skip the slash */
- req->testno = atol(ptr);
+ pval = ptr;
+ if(!curlx_str_number(&pval, &num, INT_MAX))
+ req->testno = (long)num;
if(req->testno > 10000) {
req->partno = req->testno % 10000;
portp = strchr(doc, ':');
if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1))) {
- int inum = atoi(portp + 1);
- if((inum <= 0) || (inum > 65535))
+ pval = portp + 1;
+ if(curlx_str_number(&pval, &num, 0xffff) ||
+ (num <= 0) || (num > 65535))
logmsg("Invalid CONNECT port received");
else
- req->connect_port = (unsigned short)inum;
-
+ req->connect_port = (unsigned short)num;
}
logmsg("Port number: %d, test case number: %ld",
req->connect_port, req->testno);
/* check for a Testno: header with the test case number */
char *testno = strstr(line, "\nTestno: ");
if(testno) {
- req->testno = atol(&testno[9]);
- logmsg("Found test number %ld in Testno: header!", req->testno);
+ pval = &testno[9];
+ if(!curlx_str_number(&pval, &num, INT_MAX)) {
+ req->testno = (long)num;
+ logmsg("Found test number %ld in Testno: header!", req->testno);
+ }
+ else
+ logmsg("No Testno: number");
}
else {
logmsg("No Testno: header");
while(*ptr && !ISDIGIT(*ptr))
ptr++;
- req->testno = atol(ptr);
+ pval = ptr;
+ if(!curlx_str_number(&pval, &num, INT_MAX))
+ req->testno = (long)num;
if(req->testno > 10000) {
req->partno = req->testno % 10000;
serverlogslocked = 0;
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--version", argv[arg])) {
puts("sws IPv4"
#ifdef USE_IPV6
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- int inum = atoi(argv[arg]);
- if(inum && ((inum < 1025) || (inum > 65535))) {
+ opt = argv[arg];
+ if(curlx_str_number(&opt, &num, 0xffff) || num < 1025) {
fprintf(stderr, "sws: invalid --port argument (%s)\n",
argv[arg]);
return 0;
}
- port = (unsigned short)inum;
+ port = (unsigned short)num;
arg++;
}
}
else if(!strcmp("--keepalive", argv[arg])) {
arg++;
if(argc > arg) {
- int inum = atoi(argv[arg]);
- if(inum && (inum > 65535)) {
+ opt = argv[arg];
+ if(curlx_str_number(&opt, &num, 0xffff)) {
fprintf(stderr, "sws: invalid --keepalive argument (%s), must "
"be number of seconds\n", argv[arg]);
return 0;
}
- keepalive_secs = (unsigned short)inum;
+ keepalive_secs = (unsigned short)num;
arg++;
}
}
serverlogslocked = 0;
while(argc > arg) {
+ const char *opt;
+ curl_off_t num;
if(!strcmp("--version", argv[arg])) {
printf("tftpd IPv4%s\n",
#ifdef USE_IPV6
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
- port = (unsigned short)atol(argv[arg]);
+ opt = argv[arg];
+ if(!curlx_str_number(&opt, &num, 0xffff))
+ port = (unsigned short)num;
arg++;
}
}
char partbuf[80]="data";
long partno;
long testno;
+ const char *pval;
+ curl_off_t num;
FILE *stream;
ptr++; /* skip the slash */
ptr++;
/* get the number */
- testno = atol(ptr);
+ pval = ptr;
+ if(!curlx_str_number(&pval, &num, INT_MAX))
+ testno = (long)num;
+ else {
+ logmsg("tftpd: failed to read the test number from '%s'", filename);
+ return TFTP_EACCESS;
+ }
if(testno > 10000) {
partno = testno % 10000;
}
}
-unsigned char byteval(char *value)
-{
- unsigned int num = (unsigned int)atoi(value);
- return num & 0xff;
-}
-
#ifdef _WIN32
/* use instead of perror() on generic Windows */
static void win32_perror(const char *msg)