2 * This file is part of secnet.
3 * See LICENCE and this file CREDITS for full list of copyright holders.
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 * There is NO WARRANTY.
9 test-example/bogus-setup-request 127.0.0.1 19098 test-example/inside/inside 127.0.0.1 16096 test-example/outside/outside
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
24 | 00000 00 00 00 00 00 00 00 01 01 01 01 01 00 1a 74 65 ........ ......te |
25 ~~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~|~~~~~
26 sessionid sender's type sender's
27 zero in index fixed for name
30 | 00010 73 74 2d 65 78 61 6d 70 6c 65 2f 69 6e 73 69 64 st-examp le/insid |
31 | 00020 65 2f 69 6e 73 69 64 65 00 1c 74 65 73 74 2d 65 e/inside ..test-e |
32 ~~~~~|~~~~~~~~~~~~~~~~~
35 | 00030 78 61 6d 70 6c 65 2f 6f 75 74 73 69 64 65 2f 6f xample/o utside/o |
36 | 00040 75 74 73 69 64 65 8d f0 3f 35 d6 c8 1f c0 utside.. ?5.... |
37 ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
45 struct sockaddr_in sin;
49 static void endaddr(Ep *ep, char **argv, int base) {
51 ep->sin.sin_family=AF_INET;
52 r=inet_aton(argv[base],&ep->sin.sin_addr); assert(r);
53 ep->sin.sin_port=htons(atoi(argv[base+1]));
54 ep->name=argv[base+2];
57 static void endname(uint8_t **msgp, const Ep *ep) {
58 int l=strlen(ep->name); assert(l<=65535);
61 memcpy(*msgp, ep->name, l);
67 int main(int argc, char **argv) {
73 endaddr(&them,argv,4);
75 static const uint8_t mprefix[]={
76 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x01,
78 0x01, 0x01, 0x01, 0x01,
80 static const uint8_t msuffix[]={
81 /* our nonce, fixed he he */
82 0x8d, 0xf0, 0x3f, 0x35, 0xd6, 0xc8, 0x1f, 0xc0
84 int msglen= (sizeof(mprefix) +
91 #define PREFIXSUFFIX(prefixsuffix) do { \
92 memcpy(msgp,prefixsuffix,sizeof(prefixsuffix)); \
93 msgp += sizeof(prefixsuffix); \
96 PREFIXSUFFIX(mprefix);
101 PREFIXSUFFIX(msuffix);
103 assert(msgp == msg+msglen);
105 struct protoent *proto=getprotobyname("udp");
106 int fd=socket(AF_INET, SOCK_DGRAM, proto->p_proto);
107 r=bind(fd,&us.sa,sizeof(us.sin)); if (r) { perror("bind us2"); exit(1); }
110 r=sendto(fd,msg,msglen,0,&them.sa,sizeof(them.sin));
111 if (r < 0) perror("sendto");
115 if (ferror(stdin)) { perror("getchar"); exit(1); }