mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
If you have trouble updating after this revision you need to follow these instructions. You have probably just seen an error like this: svn: URL 'svn://svn.insecure.org/nping' of existing directory 'nping' does not match expected URL 'svn://svn.insecure.org/nmap/nping' This is caused by the replacement of SVN externals. Here's what you need to do. First, save any local changes you might have in the nping, nsock, nbase, ncat, and zenmap directories. (For example by running "cd nping; svn diff > ../nping.diff".) If you don't have any local changes you can skip this step. Then run these commands: rm -rf nping/ nsock/ nbase/ ncat/ zenmap/ svn update svn cleanup If all else fails, you can just delete your whole working directory and check out anew: svn co --username guest --password "" svn://svn.insecure.org/nmap There may be further discussion in the mailing list thread at http://seclists.org/nmap-dev/2011/q4/303.
130 lines
3.7 KiB
C
130 lines
3.7 KiB
C
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "ncat_core.h"
|
|
#include "http.h"
|
|
|
|
static long test_count = 0;
|
|
static long success_count = 0;
|
|
|
|
/* Check strings or null pointers for equality. */
|
|
int nullstreq(const char *s, const char *t)
|
|
{
|
|
if (s == NULL) {
|
|
if (t == NULL)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
} else {
|
|
if (t == NULL)
|
|
return 0;
|
|
else
|
|
return strcmp(s, t) == 0;
|
|
}
|
|
}
|
|
|
|
int test_uri(const char *uri_s, const char *scheme, const char *host, int port, const char *path)
|
|
{
|
|
struct uri uri;
|
|
int scheme_match, host_match, port_match, path_match;
|
|
|
|
test_count++;
|
|
|
|
if (uri_parse(&uri, uri_s) == NULL) {
|
|
printf("FAIL %s: couldn't parse.\n", uri_s);
|
|
return 0;
|
|
}
|
|
|
|
scheme_match = nullstreq(uri.scheme, scheme);
|
|
host_match = nullstreq(uri.host, host);
|
|
port_match = uri.port == port;
|
|
path_match = nullstreq(uri.path, path);
|
|
|
|
if (scheme_match && host_match && port_match && path_match) {
|
|
printf("PASS %s\n", uri_s);
|
|
uri_free(&uri);
|
|
success_count++;
|
|
return 1;
|
|
} else {
|
|
printf("FAIL %s:", uri_s);
|
|
if (!scheme_match)
|
|
printf(" \"%s\" != \"%s\".", uri.scheme, scheme);
|
|
if (!host_match)
|
|
printf(" \"%s\" != \"%s\".", uri.host, host);
|
|
if (!port_match)
|
|
printf(" %d != %d.", uri.port, port);
|
|
if (!path_match)
|
|
printf(" \"%s\" != \"%s\".", uri.path, path);
|
|
printf("\n");
|
|
uri_free(&uri);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
int test_fail(const char *uri_s)
|
|
{
|
|
struct uri uri;
|
|
|
|
test_count++;
|
|
|
|
if (uri_parse(&uri, uri_s) != NULL) {
|
|
uri_free(&uri);
|
|
printf("FAIL %s: not expected to parse.\n", uri_s);
|
|
return 0;
|
|
} else {
|
|
printf("PASS %s\n", uri_s);
|
|
success_count++;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
test_uri("http://www.example.com", "http", "www.example.com", 80, "");
|
|
|
|
test_uri("HTTP://www.example.com", "http", "www.example.com", 80, "");
|
|
test_uri("http://WWW.EXAMPLE.COM", "http", "WWW.EXAMPLE.COM", 80, "");
|
|
|
|
test_uri("http://www.example.com:100", "http", "www.example.com", 100, "");
|
|
test_uri("http://www.example.com:1", "http", "www.example.com", 1, "");
|
|
test_uri("http://www.example.com:65535", "http", "www.example.com", 65535, "");
|
|
test_uri("http://www.example.com:", "http", "www.example.com", 80, "");
|
|
test_uri("http://www.example.com:/", "http", "www.example.com", 80, "/");
|
|
|
|
test_uri("http://www.example.com/", "http", "www.example.com", 80, "/");
|
|
test_uri("http://www.example.com:100/", "http", "www.example.com", 100, "/");
|
|
|
|
test_uri("http://1.2.3.4", "http", "1.2.3.4", 80, "");
|
|
test_uri("http://1.2.3.4:100", "http", "1.2.3.4", 100, "");
|
|
test_uri("http://[::ffff]", "http", "::ffff", 80, "");
|
|
test_uri("http://[::ffff]:100", "http", "::ffff", 100, "");
|
|
|
|
test_uri("http://www.example.com/path?query#frag", "http", "www.example.com", 80, "/path?query#frag");
|
|
|
|
test_uri("http://www.exampl%65.com", "http", "www.example.com", 80, "");
|
|
test_uri("http://www.exampl%6a.com", "http", "www.examplj.com", 80, "");
|
|
test_uri("http://www.exampl%6A.com", "http", "www.examplj.com", 80, "");
|
|
test_uri("http://www.exampl%2523.com", "http", "www.exampl%23.com", 80, "");
|
|
test_fail("http://www.example.com:%380");
|
|
test_uri("http://www.example.com/a%23b", "http", "www.example.com", 80, "/a%23b");
|
|
|
|
test_uri("unknown://www.example.com", "unknown", "www.example.com", -1, "");
|
|
|
|
test_uri("unknown:", "unknown", NULL, -1, "");
|
|
|
|
test_fail("");
|
|
test_fail("/dir/file");
|
|
test_fail("http://www.example.com:-1");
|
|
test_fail("http://www.example.com:0");
|
|
test_fail("http://www.example.com:65536");
|
|
|
|
/* We explicitly don't support userinfo in the authority. */
|
|
test_fail("http://user@www.example.com");
|
|
test_fail("http://user:pass@www.example.com");
|
|
|
|
printf("%ld / %ld tests passed.\n", success_count, test_count);
|
|
|
|
return success_count == test_count ? 0 : 1;
|
|
}
|