Browse Source

Add very, very quick and dirty hello world test

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
010288577f
2 changed files with 31 additions and 6 deletions
  1. 26
    3
      src/tests/dhcptest.c
  2. 5
    3
      src/tests/hellotest.c

+ 26
- 3
src/tests/dhcptest.c View File

@@ -13,8 +13,7 @@ static int test_dhcp_aoe_boot ( struct net_device *netdev,
13 13
 	return test_aoeboot ( netdev, aoename, drivenum );
14 14
 }
15 15
 
16
-static int test_dhcp_iscsi_boot ( struct net_device *netdev __unused,
17
-				  char *iscsiname ) {
16
+static int test_dhcp_iscsi_boot ( char *iscsiname ) {
18 17
 	char *initiator_iqn = "iqn.1900-01.localdomain.localhost:initiator";
19 18
 	char *target_iqn;
20 19
 	union {
@@ -36,11 +35,35 @@ static int test_dhcp_iscsi_boot ( struct net_device *netdev __unused,
36 35
 	return test_iscsiboot ( initiator_iqn, &target.st, target_iqn );
37 36
 }
38 37
 
38
+static int test_dhcp_hello ( char *helloname ) {
39
+	char *message;
40
+	union {
41
+		struct sockaddr_in sin;
42
+		struct sockaddr_tcpip st;
43
+	} target;
44
+
45
+	memset ( &target, 0, sizeof ( target ) );
46
+	target.sin.sin_family = AF_INET;
47
+	target.sin.sin_port = htons ( 80 );
48
+	message = strchr ( helloname, ':' );
49
+	*message++ = '\0';
50
+	if ( ! message ) {
51
+		printf ( "Invalid hello path\n" );
52
+		return -EINVAL;
53
+	}
54
+	inet_aton ( helloname, &target.sin.sin_addr );	
55
+
56
+	test_hello ( &target.st, message );
57
+	return 0;
58
+}
59
+
39 60
 static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
40 61
 	if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
41 62
 		return test_dhcp_aoe_boot ( netdev, &filename[4] );
42 63
 	} else if ( strncmp ( filename, "iscsi:", 6 ) == 0 ) {
43
-		return test_dhcp_iscsi_boot ( netdev, &filename[6] );
64
+		return test_dhcp_iscsi_boot ( &filename[6] );
65
+	} else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
66
+		return test_dhcp_hello ( &filename[6] );
44 67
 	} else {
45 68
 		printf ( "Don't know how to boot %s\n", filename );
46 69
 		return -EPROTONOSUPPORT;

+ 5
- 3
src/tests/hellotest.c View File

@@ -22,15 +22,17 @@ static void test_hello_callback ( char *data, size_t len ) {
22 22
 	}
23 23
 }
24 24
 
25
-void test_hello ( struct sockaddr_in *server, const char *message ) {
25
+void test_hello ( struct sockaddr_tcpip *server, const char *message ) {
26
+	/* Quick and dirty hack */
27
+	struct sockaddr_in *sin = ( struct sockaddr_in * ) server;
26 28
 	struct hello_request hello;
27 29
 	int rc;
28 30
 
29 31
 	printf ( "Saying \"%s\" to %s:%d\n", message,
30
-		 inet_ntoa ( server->sin_addr ), ntohs ( server->sin_port ) );
32
+		 inet_ntoa ( sin->sin_addr ), ntohs ( sin->sin_port ) );
31 33
 	
32 34
 	memset ( &hello, 0, sizeof ( hello ) );
33
-	hello.tcp.sin = *server;
35
+	memcpy ( &hello.tcp.peer, server, sizeof ( hello.tcp.peer ) );
34 36
 	hello.message = message;
35 37
 	hello.callback = test_hello_callback;
36 38
 

Loading…
Cancel
Save